comparison tasks.py @ 70:68164135ae66

refactor tasks.py to smaller steps
author drewp@bigasterisk.com
date Fri, 03 May 2024 11:56:59 -0700
parents c5e98d891638
children
comparison
equal deleted inserted replaced
69:6a021aa7b4be 70:68164135ae66
13 def scrapeConfig(fn): 13 def scrapeConfig(fn):
14 return yaml.load(open(fn), yaml.FullLoader) 14 return yaml.load(open(fn), yaml.FullLoader)
15 15
16 16
17 @task 17 @task
18 def build_k8s_config(ctx):
19 ctx.run('pdm run python create_k8s.py')
20
21
22 @task
23 def build_scrape_config(ctx):
24 ctx.run('pdm run python create_scrape_configs.py')
25
26
27 @task(pre=[build_k8s_config, build_scrape_config])
18 def push_config(ctx): 28 def push_config(ctx):
19 # plan: 29 cmap: dict[str, object] = {
20 # every discovered service may:
21 # - be described here as a forever retention - ignore the discovery
22 # - be blocked here as a no-metrics service - ignore the discovery
23 # - be scraped as 'recent', with possible overrides of port/path
24 # all per-node metrics shall be 'recent' (oops, not smartctl!)
25 map: dict[str, object] = {
26 'rules': alert_rules.allRules(ctx), 30 'rules': alert_rules.allRules(ctx),
27 } 31 }
28 top = Path('build/scrape_config') 32 top = Path('build/scrape_config')
29 for p in top.glob('*.yaml'): 33 for p in top.glob('*.yaml'):
30 map[str(p.relative_to(top))] = scrapeConfig(p) 34 cmap[str(p.relative_to(top))] = scrapeConfig(p)
31 replaceCmap("victoriametrics-config", map) 35 replaceCmap("victoriametrics-config", cmap)
36
37 # note: these will fail on first run, since you have to make config before
38 # you can launch the service for the first time. Also, these won't error if
39 # there are problems with the config. Watch the vmagent (etc) logs.
32 refreshPodCmaps(firstPodName("app=victoriametrics-forever-vmagent")) 40 refreshPodCmaps(firstPodName("app=victoriametrics-forever-vmagent"))
33 refreshPodCmaps(firstPodName("app=victoriametrics-recent-vmagent")) 41 refreshPodCmaps(firstPodName("app=victoriametrics-recent-vmagent"))