# Scripts

This directory contains maintenance scripts for generating and enriching config files.

## Quick Start

Run all generators in one command:

```bash
make generate-configs
```

This runs `generate-regions` → `generate-vm` → `generate-loki` in order.

## `generate_regions.py`

Scans the app-delivery repo directory structure to discover all regions (dedicated, nextgen, serverless). Outputs `config/regions.json` which serves as the single source of truth for region IDs.

The scanning logic aligns with the TypeScript scanner (`src/lib/scanner.ts`).

Run:

```bash
make generate-regions
```

Dependencies: Python 3.9+, `APP_DELIVERY_REPO_PATH` environment variable

## `generate_vm_config.py`

Uses `config/regions.json` as the region list and `deployments/globalserver/manifests/prod/meta.json` as the authoritative routing table to resolve VM datasource URLs. Preserves existing cluster UUIDs from the current `victoriametrics.json`. Queries `acs_build_info` to verify each URL and extract cluster labels. With Auth0 credentials (`AUTH0_CLIENT_ID`, `AUTH0_CLIENT_SECRET`), enriches new entries via the Clusters API.

Run:

```bash
make generate-vm
```

Dependencies: Python 3.9+ (no external dependencies), Auth0 credentials for UUID enrichment

## `generate_loki_config.py`

Uses `config/regions.json` as the region list and `deployments/globalserver/manifests/prod/meta.json` as the authoritative routing table to resolve Loki datasource URLs. Queries Loki APIs to enrich entries with cluster labels.

Run:

```bash
make generate-loki
```

Dependencies: Python 3.9+ (no external dependencies), network access for Loki API queries

## Data Flow

```
app-delivery directories → generate_regions.py → config/regions.json
                                                      ├─► generate_vm_config.py → config/victoriametrics.json
                                                      └─► generate_loki_config.py → config/loki.json
```

## Shared Code

`routing.py` contains the common meta.json routing logic (region ID parsing, biz string construction, route pattern matching, candidate resolution) used by both `generate_vm_config.py` and `generate_loki_config.py`.
