# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This file is used to show how to write configuration files and can be used to test.

setup:
  env: compose
  file: docker-compose.yml
  timeout: 20m
  init-system-environment: ../../script/env
  steps:
    - name: set PATH
      command: export PATH=/tmp/skywalking-infra-e2e/bin:$PATH
    - name: install yq
      command: bash test/e2e-v2/script/prepare/setup-e2e-shell/install.sh yq
    - name: install swctl
      command: bash test/e2e-v2/script/prepare/setup-e2e-shell/install.sh swctl

trigger:
  action: http
  interval: 3s
  times: 10
  url: http://${consumer_host}:${consumer_9092}/users
  method: POST
  body: '{"id":"123","name":"skywalking"}'
  headers:
    "Content-Type": "application/json"

verify:
  # verify with retry strategy
  retry:
    # max retry count
    count: 20
    # the interval between two retries, in millisecond.
    interval: 3s
  cases:
    # service list
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql service ls
      expected: expected/service.yml
    # service instance list
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql instance list --service-name=e2e-service-provider
      expected: expected/service-instance-provider.yml
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql instance list --service-name=e2e-service-consumer
      expected: expected/service-instance-consumer.yml
    # service endpoint
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql endpoint list --keyword=users --service-name=e2e-service-provider
      expected: expected/service-endpoint-provider.yml
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql endpoint list --keyword=users --service-name=e2e-service-consumer
      expected: expected/service-endpoint-consumer.yml
    # trace segment list
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql trace ls
      expected: expected/traces-list.yml
    # dependency service
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql dependency service --service-name=e2e-service-consumer
      expected: expected/dependency-services-consumer.yml
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql dependency service --service-name=e2e-service-provider
      expected: expected/dependency-services-provider.yml
    # dependency instance gateway:80 is not real then use service-id
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql dependency instance --service-id=Z2F0ZXdheTo4MA==.0 --dest-service-name=e2e-service-provider
      expected: expected/dependency-instance.yml
    # service metrics linear
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql metrics exec --expression=service_sla --service-name=e2e-service-provider
      expected: expected/metrics-has-value.yml
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql metrics exec --expression=service_cpm --service-name=e2e-service-provider
      expected: expected/metrics-has-value.yml
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql metrics exec --expression=service_resp_time --service-name=e2e-service-provider
      expected: expected/metrics-has-value.yml
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql metrics exec --expression=service_apdex --service-name=e2e-service-provider
      expected: expected/metrics-has-value.yml
    # service metrics percentile
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql metrics exec --expression=service_percentile --service-name=e2e-service-provider
      expected: expected/metrics-has-value-percentile.yml
    # service instance metrics
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql metrics exec --expression=service_instance_resp_time --instance-name=provider1 --service-name=e2e-service-provider
      expected: expected/metrics-has-value.yml
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql metrics exec --expression=service_instance_cpm --instance-name=provider1 --service-name=e2e-service-provider
      expected: expected/metrics-has-value.yml
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql metrics exec --expression=service_instance_sla --instance-name=provider1 --service-name=e2e-service-provider
      expected: expected/metrics-has-value.yml
    # service endpoint metrics
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql metrics exec --expression=endpoint_cpm --endpoint-name=POST:/users --service-name=e2e-service-provider
      expected: expected/metrics-has-value.yml
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql metrics exec --expression=endpoint_resp_time --endpoint-name=POST:/users --service-name=e2e-service-provider
      expected: expected/metrics-has-value.yml
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql metrics exec --expression=endpoint_sla --endpoint-name=POST:/users --service-name=e2e-service-provider
      expected: expected/metrics-has-value.yml
    # service endpoint metrics percentile
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql metrics exec --expression=endpoint_percentile --endpoint-name=POST:/users --service-name=e2e-service-provider
      expected: expected/metrics-has-value-percentile.yml
    # service relation metrics
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql metrics exec --expression=service_relation_client_cpm --service-name=e2e-service-consumer --dest-service-id=Z2F0ZXdheTo4MA==.0
      expected: expected/metrics-has-value.yml
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql metrics exec --expression=service_relation_server_cpm --service-id=VXNlcg==.0 --dest-service-name=e2e-service-consumer
      expected: expected/metrics-has-value.yml
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql metrics exec --expression=service_relation_client_cpm --service-name=e2e-service-provider --dest-service-id=bG9jYWxob3N0Oi0x.0
      expected: expected/metrics-has-value.yml
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql metrics exec --expression=service_relation_server_cpm --service-id=Z2F0ZXdheTo4MA==.0 --dest-service-name=e2e-service-provider
      expected: expected/metrics-has-value.yml
    # service instance relation metrics gateway:80 is not real then use service-id
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql metrics exec --expression=service_instance_relation_server_cpm --instance-id=Z2F0ZXdheTo4MA==.0_Z2F0ZXdheTo4MA== --service-id=Z2F0ZXdheTo4MA==.0 --dest-instance-name=provider1 --dest-service-name=e2e-service-provider
      expected: expected/metrics-has-value.yml
    - query: swctl --display yaml --base-url=http://${ui_host}:${ui_8080}/graphql metrics exec --expression=service_instance_relation_server_cpm --instance-id=Z2F0ZXdheTo4MA==.0_Z2F0ZXdheTo4MA== --service-id=Z2F0ZXdheTo4MA==.0 --dest-instance-name=provider2 --dest-service-name=e2e-service-provider
      expected: expected/metrics-has-value.yml
