{
  "repo": "tidbcloud/auditservice",
  "binary": "worker",
  "binary_path": "cmd/worker/main.go",
  "dependencies": {
    "AuditWorkerLifecycle.Startup": {
      "infrastructure": {},
      "services": []
    },
    "AuditWorkerLifecycle.LoadRemoteConfig": {
      "infrastructure": {},
      "services": [
        {
          "name": "config-service-oneconfig",
          "target_interface": "oneconfig-account/config.yaml",
          "operation_type": "remote_config",
          "target_repo": "tidbcloud/config-service",
          "conditions": [
            "Always"
          ],
          "operations": [
            {
              "operation": "READ REMOTE CONFIG",
              "trigger": "Load dynamic config before DB initialization and cleanup scheduling",
              "conditions": [
                "Always"
              ],
              "implementation": "configs.LoadRemoteConfig -> viper.AddRemoteProvider(...); viper.ReadRemoteConfig(); go watchViperConfig(ctx)"
            }
          ]
        }
      ]
    },
    "AuditWorkerLifecycle.InitializeDB": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Only when DB_DSN environment variable is set"
          ],
          "operations": [
            {
              "operation": "OPEN DB HANDLE",
              "trigger": "Create the shared auditlog database handle used by the retention task",
              "conditions": [
                "os.Getenv(\"DB_DSN\") != \"\""
              ],
              "implementation": "entity.InitDB(cfg, true) -> gorm.Open(mysql.Open(dsn), &gorm.Config{})"
            },
            {
              "operation": "AUTO MIGRATE",
              "trigger": "Ensure the event and settings tables exist before the retention task runs",
              "conditions": [
                "os.Getenv(\"DB_DSN\") != \"\""
              ],
              "implementation": "entity.InitDB(cfg, true) -> db.AutoMigrate(&Event{}, &InternalEvent{}, &OrgAuditLogSettings{})"
            }
          ]
        }
      },
      "services": []
    },
    "AuditWorkerLifecycle.ScheduleDeleteOldEvents": {
      "infrastructure": {},
      "services": []
    },
    "AuditWorkerLifecycle.StartScheduler": {
      "infrastructure": {},
      "services": []
    },
    "AuditWorkerLifecycle.StartHTTPServer": {
      "infrastructure": {},
      "services": []
    },
    "HTTP GET /healthz": {
      "infrastructure": {},
      "services": []
    },
    "HTTP GET /ping": {
      "infrastructure": {},
      "services": []
    },
    "AuditWorkerTasks.DeleteOldEvents": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Only when server.clearAuditLogWhitelist has at least one org id"
          ],
          "operations": [
            {
              "operation": "DELETE",
              "trigger": "Hard delete old events that are older than 90 days and not in the remote-config whitelist",
              "conditions": [
                "len(viper.GetStringSlice(\"server.clearAuditLogWhitelist\")) > 0"
              ],
              "implementation": "dao.NewAuditDao().DeleteEventsOlderThanAndNotInOrgIds(ctx, db, orgIds, createdAt)"
            }
          ]
        }
      },
      "services": []
    }
  },
  "notes": [
    "The else branch calling DeleteEventsOlderThan is currently unreachable because the function returns early when the whitelist is empty. Effective deletion therefore requires a non-empty whitelist."
  ]
}
