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

cases:
  # service list
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql service ls
    expected: expected/service.yml
  # service metrics
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression='latest(aggregate_labels(meter_kong_service_nginx_metric_errors_total,sum))' --service-name=kong::kong-cluster
    expected: expected/metrics-single-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression='latest(aggregate_labels(meter_kong_service_datastore_reachable,sum(service_instance_id)))' --service-name=kong::kong-cluster
    expected: expected/metrics-single-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression='aggregate_labels(meter_kong_service_http_bandwidth,sum(direction))' --service-name=kong::kong-cluster
    expected: expected/metrics-has-value-label-bandwidth-service.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression='aggregate_labels(meter_kong_service_http_status,sum(code))' --service-name=kong::kong-cluster
    expected: expected/metrics-has-value-label-status.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression='aggregate_labels(meter_kong_service_http_requests,sum)' --service-name=kong::kong-cluster
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression='aggregate_labels(meter_kong_service_nginx_connections_total,sum(state))' --service-name=kong::kong-cluster
    expected: expected/metrics-has-value-label-state.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression='aggregate_labels(meter_kong_service_nginx_timers,sum(state))' --service-name=kong::kong-cluster
    expected: expected/metrics-has-value-label-state.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression='aggregate_labels(meter_kong_service_kong_latency,avg(p))' --service-name=kong::kong-cluster
    expected: expected/metrics-has-value-label-percentile.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression='aggregate_labels(meter_kong_service_request_latency,avg(p))' --service-name=kong::kong-cluster
    expected: expected/metrics-has-value-label-percentile.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression='aggregate_labels(meter_kong_service_upstream_latency,avg(p))' --service-name=kong::kong-cluster
    expected: expected/metrics-has-value-label-percentile.yml

  # instance metrics
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_kong_instance_http_bandwidth --service-name=kong::kong-cluster --instance-name=kong-1:8001
    expected: expected/metrics-has-value-label-bandwidth.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_kong_instance_http_status --service-name=kong::kong-cluster --instance-name=kong-1:8001
    expected: expected/metrics-has-value-label-status.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_kong_instance_datastore_reachable --service-name=kong::kong-cluster --instance-name=kong-1:8001
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_kong_instance_http_requests --service-name=kong::kong-cluster --instance-name=kong-1:8001
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_kong_instance_shared_dict_bytes --service-name=kong::kong-cluster --instance-name=kong-1:8001
    expected: expected/metrics-has-value-label-shared-dict.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_kong_instance_shared_dict_total_bytes --service-name=kong::kong-cluster --instance-name=kong-1:8001
    expected: expected/metrics-has-value-label-shared-dict.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_kong_instance_memory_workers_lua_vms_bytes --service-name=kong::kong-cluster --instance-name=kong-1:8001
    expected: expected/metrics-has-value-label-pid.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_kong_instance_nginx_connections_total --service-name=kong::kong-cluster --instance-name=kong-1:8001
    expected: expected/metrics-has-value-label-state.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_kong_instance_nginx_timers --service-name=kong::kong-cluster --instance-name=kong-1:8001
    expected: expected/metrics-has-value-label-state.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_kong_instance_kong_latency --service-name=kong::kong-cluster --instance-name=kong-1:8001
    expected: expected/metrics-has-value-label-percentile.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_kong_instance_request_latency --service-name=kong::kong-cluster --instance-name=kong-1:8001
    expected: expected/metrics-has-value-label-percentile.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_kong_instance_upstream_latency --service-name=kong::kong-cluster --instance-name=kong-1:8001
    expected: expected/metrics-has-value-label-percentile.yml

  # Endpoint metrics
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_kong_endpoint_http_bandwidth --service-name=kong::kong-cluster --instance-name=kong-1:8001 --endpoint-name=sw_route
    expected: expected/metrics-has-value-label-bandwidth-endpoint.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_kong_endpoint_http_status --service-name=kong::kong-cluster --instance-name=kong-1:8001 --endpoint-name=sw_route
    expected: expected/metrics-has-value-label-status.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_kong_endpoint_kong_latency --service-name=kong::kong-cluster --instance-name=kong-1:8001 --endpoint-name=sw_route
    expected: expected/metrics-has-value-label-percentile.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_kong_endpoint_request_latency --service-name=kong::kong-cluster --instance-name=kong-1:8001 --endpoint-name=sw_route
    expected: expected/metrics-has-value-label-percentile.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_kong_endpoint_upstream_latency --service-name=kong::kong-cluster --instance-name=kong-1:8001 --endpoint-name=sw_route
    expected: expected/metrics-has-value-label-percentile.yml