{
  "repo": "tidbcloud/metrics-server",
  "binary": "scrape_gateway",
  "binary_path": "cmd/scrape_gateway/main.go",
  "dependencies": {
    "HTTP GET /ping": {
      "infrastructure": {},
      "services": []
    },
    "HTTP GET /healthz": {
      "infrastructure": {},
      "services": []
    },
    "HTTP GET /metrics": {
      "infrastructure": {},
      "services": []
    },
    "HTTP GET /public_api/v1/clusters/:cluster_id/monitoring/measurements": {
      "infrastructure": {
        "mysql": {
          "conditions": ["Always"],
          "operations": [
            {
              "operation": "SELECT",
              "trigger": "Authenticate API key",
              "conditions": ["Always"],
              "implementation": "apikey.AuthenticateAPIKey(token) -> dbutil.GetMetricsKeyByKey(tx, token, projectID)"
            }
          ]
        },
        "thanos": {
          "conditions": ["Always"],
          "operations": [
            {
              "operation": "GET /api/v1/query",
              "trigger": "Query cluster metrics from Thanos",
              "conditions": ["Always"],
              "implementation": "client.DoInstantQuery(ctx, promql, metricName) via central_thanos.QuerierFuncs"
            }
          ]
        }
      },
      "services": [
        {
          "name": "core-svc",
          "target_interface": "CoreService.ListClusters",
          "operation_type": "grpc_unary",
          "conditions": ["Always"],
          "operations": [
            {
              "operation": "gRPC ListClusters",
              "trigger": "Get cluster info for authentication",
              "conditions": ["Always"],
              "implementation": "grpcli.ListClusters(ctx, &core.ListClustersReq{Filter: {ClusterIds: [clusterID], TenantIds: [tenantID]}})"
            }
          ]
        }
      ]
    },
    "HTTP GET /public_api/v1/projects/:project_id/metrics": {
      "infrastructure": {
        "mysql": {
          "conditions": ["Always"],
          "operations": [
            {
              "operation": "SELECT",
              "trigger": "Get metrics key by project",
              "conditions": ["Always"],
              "implementation": "db.Transaction -> dbutil.GetMetricsKeyByKey(tx, token, projectID)"
            }
          ]
        },
        "thanos": {
          "conditions": ["Always"],
          "operations": [
            {
              "operation": "GET /api/v1/query",
              "trigger": "Query cluster metrics from Thanos for each cluster",
              "conditions": ["Always"],
              "implementation": "client.DoInstantQuery(ctx, promql, metricName) via central_thanos.QuerierFuncs"
            }
          ]
        }
      },
      "services": [
        {
          "name": "core-svc",
          "target_interface": "CoreService.ListClusters",
          "operation_type": "grpc_unary",
          "conditions": ["Always"],
          "operations": [
            {
              "operation": "gRPC ListClusters",
              "trigger": "List all clusters under project",
              "conditions": ["Always"],
              "implementation": "grpcli.ListClusters(ctx, &core.ListClustersReq{Filter: {ProjectIds: [projectID]}})"
            }
          ]
        }
      ]
    },
    "Runtime ScrapeGatewayLifecycle.Startup": {
      "infrastructure": {
        "mysql": {
          "conditions": ["Always"],
          "operations": [
            {
              "operation": "CONNECT",
              "trigger": "Initialize database connection pool",
              "conditions": ["Always"],
              "implementation": "cmd.InitMetadbDriver() -> dbinit.InitializeV2(mysqlConfig, false)"
            }
          ]
        }
      },
      "services": []
    }
  }
}
