69 lines
2.0 KiB
Python
69 lines
2.0 KiB
Python
import os
|
|
import yaml
|
|
from pathlib import Path
|
|
|
|
REPOS = {
|
|
"dev-tools": "https://git.dvirlabs.com/dvirlabs/dev-tools.git",
|
|
"infra": "https://git.dvirlabs.com/dvirlabs/infra.git",
|
|
"observability-stack": "https://git.dvirlabs.com/dvirlabs/observability-stack.git"
|
|
}
|
|
|
|
TMP_DIR = ".tmp-repos"
|
|
OUTPUT_FILE = os.path.join(TMP_DIR, "observability-stack/manifests/prometheus-scrape-secret/additional-scrape-configs.yaml")
|
|
|
|
os.makedirs(TMP_DIR, exist_ok=True)
|
|
|
|
def collect_targets():
|
|
jobs = {}
|
|
|
|
for name, url in REPOS.items():
|
|
repo_path = os.path.join(TMP_DIR, name)
|
|
if not os.path.exists(repo_path):
|
|
os.system(f"git clone --depth 1 {url} {repo_path}")
|
|
|
|
for path in Path(repo_path, "manifests").glob("*/monitoring.yaml"):
|
|
with open(path) as f:
|
|
data = yaml.safe_load(f)
|
|
|
|
if data.get("enabled") and "targets" in data:
|
|
if name not in jobs:
|
|
jobs[name] = []
|
|
jobs[name].extend(data["targets"])
|
|
|
|
return jobs
|
|
|
|
def write_scrape_config(jobs):
|
|
result = []
|
|
for repo, targets in jobs.items():
|
|
result.append({
|
|
"job_name": repo,
|
|
"static_configs": [{"targets": targets}]
|
|
})
|
|
|
|
scrape_yaml = "# This content will be auto-updated by the pipeline\n" + yaml.dump(result, sort_keys=False)
|
|
|
|
secret = {
|
|
"apiVersion": "v1",
|
|
"kind": "Secret",
|
|
"metadata": {
|
|
"name": "prometheus-additional-scrape-configs",
|
|
"namespace": "monitoring",
|
|
"labels": {
|
|
"app.kubernetes.io/name": "prometheus"
|
|
}
|
|
},
|
|
"type": "Opaque",
|
|
"stringData": {
|
|
"additional-scrape-configs.yaml": scrape_yaml
|
|
}
|
|
}
|
|
|
|
os.makedirs(os.path.dirname(OUTPUT_FILE), exist_ok=True)
|
|
with open(OUTPUT_FILE, "w") as f:
|
|
yaml.dump(secret, f, sort_keys=False)
|
|
|
|
if __name__ == "__main__":
|
|
jobs = collect_targets()
|
|
write_scrape_config(jobs)
|
|
print(f"✅ Generated: {OUTPUT_FILE}")
|