# 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=meter_clickhouse_tcp_connections --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_mysql_connections --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_http_connections --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_postgresql_connections --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_network_receive_bytes --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_network_send_bytes --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_query --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_query_select --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_query_insert --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_query_select_rate --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_query_insert_rate --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_querytime_microseconds --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_querytime_select_microseconds --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_querytime_insert_microseconds --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_querytime_other_microseconds --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_query_slow --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_inserted_rows --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_inserted_bytes --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_delayed_inserts --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_replicated_checks --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_replicated_fetch --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_background_merge --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_merge_rows --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_parts_active --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_mutations --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_kafka_messages_read --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_kafka_writes --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_kafka_consumers --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_kafka_producers --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_zookeeper_session --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_zookeeper_watch --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_zookeeper_bytes_sent --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_zookeeper_bytes_received --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_keeper_connections_alive --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_keeper_outstanding_requests --service-name=clickhouse::clickhouse:8123
    expected: expected/metrics-has-value-label.yml

  # instance metrics
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_version --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_cpu_usage --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_memory_usage --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_memory_available --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_uptime --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_file_open --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml

  # Network
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_tcp_connections --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_mysql_connections --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_http_connections --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_interserver_connections --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_postgresql_connections --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_network_receive_bytes  --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_network_send_bytes  --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml

  # Query
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_query --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_query_select --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_query_insert --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_query_select_rate --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_query_insert_rate --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_querytime_microseconds --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_querytime_select_microseconds --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_querytime_insert_microseconds --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_querytime_other_microseconds --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_query_slow --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml

  # Insertion
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_inserted_rows --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_inserted_bytes --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_delayed_inserts --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363

  # Replicas
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_replicated_checks  --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_replicated_fetch  --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_replicated_send --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml

  # MergeTree
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_background_merge --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_merge_rows --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_merge_uncompressed_bytes --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_move --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_parts_active --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_mutations --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml

  # Kafka Table Engine
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_kafka_messages_read --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_kafka_writes --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_kafka_consumers --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_kafka_producers --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected:  expected/metrics-has-value.yml

  # Zookeeper
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_zookeeper_session --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_zookeeper_watch --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_zookeeper_bytes_sent --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_zookeeper_bytes_received --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml

  # ClickHouse Keeper
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_keeper_connections_alive --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml
  - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression=meter_clickhouse_instance_keeper_outstanding_requests --service-name=clickhouse::clickhouse:8123 --instance-name=clickhouse1:9363
    expected: expected/metrics-has-value.yml
