{
  "repo": "tidbcloud/dbaas",
  "binary": "scrape_gateway",
  "binary_path": "metrics/cmd/scrape_gateway/main.go",
  "dependencies": {
    "HTTP GET /ping": {"infrastructure": {}, "services": [], "description": "Simple health check, no external dependencies"},
    "HTTP GET /healthz": {"infrastructure": {}, "services": [], "description": "Simple health check, no external dependencies"},
    "HTTP GET /metrics": {"infrastructure": {}, "services": [], "description": "Built-in gin-prometheus metrics, no external dependencies"},
    "HTTP GET /public_api/v1/clusters/:cluster_id/monitoring/measurements": {
      "infrastructure": {
        "mysql": {
          "conditions": ["Always"],
          "operations": [
            {"operation": "SELECT", "trigger": "apikey.AuthenticateAPIKey", "implementation": "Query api_keys table by key_hash to validate bearer token", "tables": ["api_keys"]},
            {"operation": "SELECT", "trigger": "getClusterAndRegion -> dbutil.GetCluster", "implementation": "Query clusters table by cluster_id", "tables": ["clusters"]},
            {"operation": "SELECT", "trigger": "getClusterAndRegion -> dbutil.GetClusterRegion", "implementation": "Query regions table to get cluster region info", "tables": ["regions"]},
            {"operation": "SELECT", "trigger": "metadb.BuildNodeMemoryCapacityQuerier -> clustermodel.GetClusterComponentsV2", "implementation": "Query machine_profiles and component resources for capacity info", "tables": ["clusters", "machine_profiles"]}
          ]
        },
        "kubernetes": {
          "conditions": ["Always"],
          "operations": [{"operation": "GET", "trigger": "infraapi.API.GetCluster", "implementation": "Query Gardener K8s cluster CRD to get cluster metadata including metrics endpoint", "resource": "cloudv1.Cluster CRD"}]
        },
        "prometheus_thanos": {
          "conditions": ["Always"],
          "operations": [{"operation": "HTTP GET /api/v1/query", "trigger": "central_thanos.doInstantQuery", "implementation": "Query central Thanos for node memory, CPU, storage, DB queries, connections, query duration metrics", "endpoint": "config.Global().ServerConfig.ThanosAddr"}]
        },
        "prometheus_shoot": {
          "conditions": ["Always"],
          "operations": [{"operation": "HTTP GET /api/v1/query", "trigger": "prom.BasePromClient.Query", "implementation": "Query cluster-internal Prometheus for query rate, failed query rate, query duration, CPU usage, connections, storage metrics", "endpoint": "cluster.Status.Metrics.BaseURL (via proxy)"}]
        }
      },
      "services": [
        {"name": "auth0", "target_interface": "POST /oauth/token", "operation_type": "http_post", "conditions": ["When querying Shoot Prometheus"], "operations": [{"operation": "POST /oauth/token", "trigger": "auth0.GetClientToken", "implementation": "Get bearer token for authenticating requests to cluster Prometheus proxy", "endpoint": "proxyCfg.Auth0Domain"}]}
      ]
    },
    "HTTP GET /public_api/v1/projects/:project_id/metrics": {
      "infrastructure": {
        "mysql": {
          "conditions": ["Always"],
          "operations": [
            {"operation": "SELECT", "trigger": "dbutil.GetMetricsKeyByKey", "implementation": "Query metrics_keys table by key to validate bearer token", "tables": ["metrics_keys"]},
            {"operation": "SELECT", "trigger": "dbutil.FindClusters", "implementation": "Query all clusters in the project with filters (not deleted, not cleared, not creating)", "tables": ["clusters"]}
          ]
        },
        "kubernetes": {"conditions": ["Always (per cluster)"], "operations": [{"operation": "GET", "trigger": "infraapi.API.GetCluster", "implementation": "Query Gardener K8s cluster CRD for each cluster to get metrics endpoint", "resource": "cloudv1.Cluster CRD"}]},
        "prometheus_thanos": {"conditions": ["Always (per cluster)"], "operations": [{"operation": "HTTP GET /api/v1/query", "trigger": "central_thanos.doInstantQuery", "implementation": "Query central Thanos for cluster metrics (CPU, memory, storage, DB queries, connections)", "endpoint": "config.Global().ServerConfig.ThanosAddr"}]},
        "prometheus_shoot": {"conditions": ["Always (per cluster)"], "operations": [{"operation": "HTTP GET /api/v1/query", "trigger": "prom.BasePromClient.Query", "implementation": "Query cluster-internal Prometheus for cluster-level metrics", "endpoint": "cluster.Status.Metrics.BaseURL (via proxy)"}]}
      },
      "services": [
        {"name": "auth0", "target_interface": "POST /oauth/token", "operation_type": "http_post", "conditions": ["When querying Shoot Prometheus"], "operations": [{"operation": "POST /oauth/token", "trigger": "auth0.GetClientToken", "implementation": "Get bearer token for authenticating requests to cluster Prometheus proxy", "endpoint": "proxyCfg.Auth0Domain"}]}
      ]
    }
  }
}
