{
  "repo": "tidbcloud/escalation-base",
  "binary": "prometheus-aggregation",
  "binary_path": "prometheus_aggregation/main.go",
  "notes": [
    "Fresh codex rescan rebuilt prometheus_aggregation as a background worker instead of a skipped CLI. The main loop reads persisted state, discovers clinic clusters, queries metrics, and remote-writes each batch."
  ],
  "dependencies": {
    "PromAggregationLifecycle.LoadConfig": {
      "infrastructure": {
        "filesystem": {
          "conditions": [
            "Always"
          ],
          "operations": [
            {
              "operation": "READ CONFIG",
              "paths": [
                "./config/conf.yaml"
              ],
              "conditions": [
                "Always"
              ],
              "implementation": "setUpConfig"
            }
          ]
        }
      },
      "services": []
    },
    "PromAggregationLifecycle.InitLog": {
      "infrastructure": {
        "filesystem": {
          "conditions": [
            "Always"
          ],
          "operations": [
            {
              "operation": "OPEN APPEND",
              "paths": [
                "./log/increase.log"
              ],
              "conditions": [
                "Always"
              ],
              "implementation": "initLog"
            }
          ]
        }
      },
      "services": []
    },
    "PromAggregationLifecycle.StartLoop": {
      "infrastructure": {
        "time": {
          "conditions": [
            "Always"
          ],
          "operations": [
            {
              "operation": "SLEEP",
              "duration": "3m",
              "conditions": [
                "After each fetch round"
              ],
              "implementation": "time.Sleep(3 * time.Minute)"
            }
          ]
        }
      },
      "services": [
        {
          "name": "local:PromAggregationPipeline",
          "target_interface": "PromAggregationPipeline.GetToken",
          "operation_type": "local_call",
          "conditions": [
            "Every loop iteration"
          ],
          "implementation": "main.main"
        },
        {
          "name": "local:PromAggregationPipeline",
          "target_interface": "PromAggregationPipeline.DiscoverClusters",
          "operation_type": "local_call",
          "conditions": [
            "Every loop iteration after token acquisition"
          ],
          "implementation": "main.main"
        },
        {
          "name": "local:PromAggregationPipeline",
          "target_interface": "PromAggregationPipeline.FetchAndWriteMetrics",
          "operation_type": "local_call",
          "conditions": [
            "Every loop iteration after cluster discovery"
          ],
          "implementation": "main.main"
        },
        {
          "name": "local:PromAggregationPipeline",
          "target_interface": "PromAggregationPipeline.PersistProgress",
          "operation_type": "local_call",
          "conditions": [
            "Cluster cache and window progress are updated within discovery and fetch/write paths"
          ],
          "implementation": "fetch.GetAllClusterInf + write.FetchAndWrite"
        }
      ]
    },
    "PromAggregationPipeline.GetToken": {
      "infrastructure": {},
      "services": [
        {
          "name": "auth0",
          "target_interface": "POST /oauth/token",
          "operation_type": "http_post",
          "conditions": [
            "Always"
          ],
          "implementation": "fetch.GetToken"
        }
      ]
    },
    "PromAggregationPipeline.DiscoverClusters": {
      "infrastructure": {
        "filesystem": {
          "conditions": [
            "Always"
          ],
          "operations": [
            {
              "operation": "READ",
              "paths": [
                "./persist/cluster_url.json"
              ],
              "conditions": [
                "Always"
              ],
              "implementation": "fetch.GetAllClusterInf"
            },
            {
              "operation": "WRITE",
              "paths": [
                "./persist/cluster_url.json"
              ],
              "conditions": [
                "After cluster discovery updates the cache"
              ],
              "implementation": "fetch.GetAllClusterInf"
            }
          ]
        }
      },
      "services": [
        {
          "name": "clinic",
          "target_interface": "GET /clinic/api/v1/dashboard/clusters2",
          "operation_type": "http_get",
          "conditions": [
            "Always"
          ],
          "implementation": "fetch.GetNeededClinicClusters"
        },
        {
          "name": "clinic",
          "target_interface": "GET /clinic/api/v1/orgs/external/{tenant}",
          "operation_type": "http_get",
          "conditions": [
            "Only for clusters missing from the persisted cache"
          ],
          "implementation": "fetch.GetOrgIdByTenant"
        },
        {
          "name": "clinic",
          "target_interface": "GET /clinic/api/v1/orgs/{org}/clusters/{cluster}",
          "operation_type": "http_get",
          "conditions": [
            "Only for clusters missing from the persisted cache"
          ],
          "implementation": "fetch.GetRegionInfo"
        },
        {
          "name": "observability-global-service",
          "target_interface": "GET /api/v1/clusters",
          "operation_type": "http_get",
          "conditions": [
            "Only for clusters missing from the persisted cache",
            "Clusters with empty returned ID are treated as dev tier and skipped"
          ],
          "implementation": "fetch.GetClusterId"
        }
      ]
    },
    "PromAggregationPipeline.FetchAndWriteMetrics": {
      "infrastructure": {},
      "services": [
        {
          "name": "cluster-prometheus",
          "target_interface": "GET /api/v1/query_range",
          "operation_type": "http_get",
          "conditions": [
            "For each cluster and each metric in GetAllNeededMetrics()",
            "Time windows are processed in 15-minute slices"
          ],
          "implementation": "write.GetOneMetricRequest"
        },
        {
          "name": "remote-prometheus",
          "target_interface": "POST /api/v1/write",
          "operation_type": "http_post",
          "conditions": [
            "For each generated write request"
          ],
          "implementation": "write.SendWriteRequest"
        }
      ]
    },
    "PromAggregationPipeline.PersistProgress": {
      "infrastructure": {
        "filesystem": {
          "conditions": [
            "Always"
          ],
          "operations": [
            {
              "operation": "READ",
              "paths": [
                "./persist/start_time.json"
              ],
              "conditions": [
                "At the start of each main-loop round"
              ],
              "implementation": "main.main"
            },
            {
              "operation": "WRITE",
              "paths": [
                "./persist/start_time.json"
              ],
              "conditions": [
                "After each 15-minute batch is written"
              ],
              "implementation": "write.FetchAndWrite"
            }
          ]
        }
      },
      "services": []
    }
  }
}
