# 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.

cases:
  # layer list
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql layer ls
    expected: expected/layer.yml
  # service list
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql service layer GENERAL
    expected: expected/service.yml
  # service instance list
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql instance list --service-name=e2e-service-provider
    expected: expected/service-instance-provider.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql instance list --service-name=e2e-service-consumer
    expected: expected/service-instance-consumer.yml
  # service endpoint
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql endpoint list --keyword=users --service-name=e2e-service-provider
    expected: expected/service-endpoint-provider.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql endpoint list --keyword=users --service-name=e2e-service-consumer
    expected: expected/service-endpoint-consumer.yml
  # dependency service
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql dependency service --service-name=e2e-service-provider
    expected: expected/dependency-services-provider.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql dependency service --service-name=e2e-service-consumer
    expected: expected/dependency-services-consumer.yml
  # dependency instance
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql dependency instance --service-name=e2e-service-consumer --dest-service-name=e2e-service-provider
    expected: expected/dependency-instance.yml
  # dependency endpoint
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql dependency endpoint --service-name=e2e-service-provider --endpoint-name=POST:/users
    expected: expected/dependency-endpoint-provider.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql dependency endpoint --service-name=e2e-service-consumer --endpoint-name=POST:/users
    expected: expected/dependency-endpoint-consumer.yml
  # service metrics
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics single --name=service_sla --service-name=e2e-service-provider
    expected: expected/metrics-single-sla.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics nullable --name=service_sla --service-name=e2e-service-provider
    expected: expected/metrics-nullable-single-sla.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics nullable --name=service_sla --service-name=e2e-service-provider --start "2023-01-08" --end "2023-01-09"
    expected: expected/metrics-nullable-single-sla-empty.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics sorted --name service_apdex 5
    expected: expected/metrics-top-service.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics top --name service_sla 5
    expected: expected/metrics-top-service.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_sla --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_cpm --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/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://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_apdex --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_sla --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_cpm --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_resp_time --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_apdex --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  # service instance metrics
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_instance_resp_time --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_instance_cpm --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=service_instance_sla --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  # service instance JVM metrics
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_memory_heap --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_memory_heap_max --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_memory_noheap --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_thread_live_count --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_thread_daemon_count --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_thread_peak_count --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_thread_runnable_state_thread_count --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_class_loaded_class_count --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_class_total_loaded_class_count --instance-name=consumer1 --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_memory_heap --instance-name=provider1 --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_memory_heap_max --instance-name=provider1 --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_memory_noheap --instance-name=provider1 --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_thread_live_count --instance-name=provider1 --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_thread_daemon_count --instance-name=provider1 --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_thread_peak_count --instance-name=provider1 --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_thread_runnable_state_thread_count --instance-name=provider1 --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_class_loaded_class_count --instance-name=provider1 --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=instance_jvm_class_total_loaded_class_count --instance-name=provider1 --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  # service endpoint metrics
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/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://${oap_host}:${oap_12800}/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://${oap_host}:${oap_12800}/graphql metrics exec --expression=endpoint_sla --endpoint-name=POST:/users --service-name=e2e-service-provider
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=endpoint_cpm --endpoint-name=POST:/users --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=endpoint_resp_time --endpoint-name=POST:/users --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=endpoint_sla --endpoint-name=POST:/users --service-name=e2e-service-consumer
    expected: expected/metrics-has-value.yml
  # service endpoint metrics percentile
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=endpoint_percentile --endpoint-name=POST:/users --service-name=e2e-service-consumer
    expected: expected/metrics-has-value-percentile.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=endpoint_percentile --endpoint-name=POST:/users --service-name=e2e-service-consumer
    expected: expected/metrics-has-value-percentile.yml
  # endpoint TopN with service_id
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics top --name endpoint_cpm --service-name e2e-service-provider 5
    expected: expected/metrics-top-endpoint.yml
  # native event: event list
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql event list
    expected: expected/event-list.yml
  # topN-OP-service Global
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression="top_n(service_resp_time,3,des)"
    expected: expected/topN-OP-service.yml
  # topN-OP-service Global with attrs
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression="top_n(service_resp_time,3,des,attr0='GENERAL')"
    expected: expected/topN-OP-service.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression="top_n(service_resp_time,3,des,attr0!='Not_GENERAL')"
    expected: expected/topN-OP-service.yml
  # topN-OP-endpoint Global
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression="top_n(endpoint_resp_time,3,des)"
    expected: expected/topN-OP-endpoint.yml
  # topN-OP-endpoint Global with attrs
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression="top_n(endpoint_resp_time,3,des,attr0='GENERAL')"
    expected: expected/topN-OP-endpoint.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression="top_n(endpoint_resp_time,3,des,attr0!='Not_GENERAL')"
    expected: expected/topN-OP-endpoint.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression="top_n(service_resp_time,3,des,attr0='GENERAL',attr1!='Not_exist')/100"
    expected: expected/topN-OP-service.yml
  # trace
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql tv2 ls
    expected: expected/traces-v2-list.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql tv2 ls --service-name=e2e-service-provider
    expected: expected/traces-v2-list.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql tv2 ls --service-name=e2e-service-consumer
    expected: expected/traces-v2-list.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql tv2 ls --service-name=e2e-service-consumer --endpoint-name=POST:/users
    expected: expected/traces-v2-list.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql tv2 ls --tags http.method=POST
    expected: expected/traces-v2-list.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql tv2 ls --tags http.method=POST,http.status_code=201
    expected: expected/empty-traces-v2-list.yml