{
  "repo": "tidbcloud/billing",
  "binary": "stress",
  "binary_path": "cmd/stress/main.go",
  "dependencies": {
    "BillingStressLifecycle.LoadConfig": {
      "infrastructure": {
        "filesystem": {
          "conditions": [
            "Always at startup"
          ],
          "operations": [
            {
              "operation": "READ FILE",
              "trigger": "Load billing config before stress-mode overrides and DB initialization",
              "conditions": [
                "main() reached config.Init()"
              ],
              "implementation": "config.Init()"
            }
          ]
        }
      },
      "services": []
    },
    "BillingStressLifecycle.EnableStressMode": {
      "infrastructure": {},
      "services": []
    },
    "BillingStressLifecycle.InitializeStressDatabase": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Always after config initialization succeeds"
          ],
          "operations": [
            {
              "operation": "CONNECT",
              "trigger": "Create stress-mode primary and read-only database handles",
              "conditions": [
                "config.Init() succeeded"
              ],
              "implementation": "db.InitializeStressDB() -> config overrides stress DB fields -> db.Initialize()"
            }
          ]
        }
      },
      "services": []
    },
    "BillingStressLifecycle.InitializeCache": {
      "infrastructure": {
        "redis": {
          "conditions": [
            "Always at startup even if later cache use is feature-gated"
          ],
          "operations": [
            {
              "operation": "CONNECT",
              "trigger": "Build the shared Redis-backed cache client used by measure helpers",
              "conditions": [
                "main() reached cachehandler.Init()"
              ],
              "implementation": "cachehandler.Init() -> redis.NewClient(...)"
            }
          ]
        }
      },
      "services": []
    },
    "BillingStressLifecycle.InitializeRateLimiter": {
      "infrastructure": {},
      "services": []
    },
    "BillingStressLifecycle.InitializeWebIdentity": {
      "infrastructure": {},
      "services": []
    },
    "BillingStressLifecycle.InitializeLoggerAndSentry": {
      "infrastructure": {},
      "services": []
    },
    "BillingStressLifecycle.BuildHTTPServer": {
      "infrastructure": {},
      "services": []
    },
    "BillingStressLifecycle.RegisterMetrics": {
      "infrastructure": {},
      "services": []
    },
    "BillingStressLifecycle.RegisterStressRoutes": {
      "infrastructure": {},
      "services": []
    },
    "BillingStressLifecycle.RegisterPprof": {
      "infrastructure": {},
      "services": []
    },
    "BillingStressLifecycle.InitializeAuditLog": {
      "infrastructure": {},
      "services": [
        {
          "name": "auditlog-sdk",
          "target_repo": "tidbcloud/tiinf",
          "target_interface": "auditlog.InitAuditLogSDK",
          "operation_type": "client_init",
          "conditions": [
            "Always at startup"
          ],
          "operations": [
            {
              "operation": "INITIALIZE SDK",
              "trigger": "Bring up the audit-log SDK used by stress-mode billing paths",
              "conditions": [
                "main() reached auditlog.InitAuditLogSDK(context.Background(), time.Second)"
              ],
              "implementation": "auditlog.InitAuditLogSDK(context.Background(), time.Second)"
            }
          ]
        }
      ]
    },
    "BillingStressLifecycle.InitializeMeasureSender": {
      "infrastructure": {},
      "services": [
        {
          "name": "measure-sqs",
          "target_repo": "tidbcloud/tiinf",
          "target_interface": "measure.MeasureSQSImpl.InitMeasureSqsHandler",
          "operation_type": "client_init",
          "conditions": [
            "Always at startup"
          ],
          "operations": [
            {
              "operation": "INITIALIZE SENDER",
              "trigger": "Set the default SQS measure sender used when stress mode queues measures instead of writing them inline",
              "conditions": [
                "main() reached sqsmeasurehandler.SetDefaultMeasureSender()"
              ],
              "implementation": "sqsmeasurehandler.SetDefaultMeasureSender()"
            }
          ]
        }
      ]
    },
    "BillingStressLifecycle.StartHTTPServer": {
      "infrastructure": {
        "tcp": {
          "conditions": [
            "Always after startup succeeds"
          ],
          "operations": [
            {
              "operation": "LISTEN",
              "trigger": "Serve metrics, pprof, and stress business routes on the fixed port 16688",
              "conditions": [
                "engine.Run(\":16688\") is reached"
              ],
              "implementation": "engine.Run(fmt.Sprintf(\":%d\", 16688))"
            }
          ]
        }
      },
      "services": []
    },
    "HTTP GET /metrics": {
      "infrastructure": {},
      "services": []
    },
    "HTTP GET /stress/billing/test": {
      "infrastructure": {},
      "services": []
    },
    "HTTP POST /stress/billing/tenants/:tenant_id/measures": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Only when HTTPMeasuresToQueue is false"
          ],
          "operations": [
            {
              "operation": "SELECT / INSERT / UPDATE",
              "trigger": "Directly compute and persist billing measure effects instead of queueing them",
              "conditions": [
                "c.ShouldBindJSON(costForm) succeeded",
                "config.Get().GetBool(config.HTTPMeasuresToQueue) == false"
              ],
              "implementation": "measureAPI.CostUnits -> billing.MeasureModel.CostUnits(tenantID, costForm)"
            }
          ]
        }
      },
      "services": [
        {
          "name": "measure-sqs",
          "target_repo": "tidbcloud/tiinf",
          "target_interface": "MeasureSender.SendMeasure",
          "operation_type": "sqs_send",
          "conditions": [
            "Only when HTTPMeasuresToQueue is true and costForm.Cost > 0"
          ],
          "operations": [
            {
              "operation": "SEND MEASURE",
              "trigger": "Queue the stress-mode measure instead of executing MeasureModel.CostUnits inline",
              "conditions": [
                "c.ShouldBindJSON(costForm) succeeded",
                "config.Get().GetBool(config.HTTPMeasuresToQueue)",
                "costForm.Cost > 0"
              ],
              "implementation": "measureAPI.CostUnits -> sqsmeasurehandler.GetMeasureSender().SendMeasure(tenantID, costForm)"
            }
          ]
        }
      ]
    },
    "HTTP GET /debug/pprof/*": {
      "infrastructure": {},
      "services": []
    },
    "HTTP POST /debug/pprof/symbol": {
      "infrastructure": {},
      "services": []
    }
  }
}
