Mercurial > code > home > repos > victoriametrics
annotate tasks.py @ 22:cd115f1ca2a8
use configmaps and a special pod refresh trick
author | drewp@bigasterisk.com |
---|---|
date | Sat, 24 Jun 2023 23:02:04 -0700 |
parents | f5777b65f035 |
children | eec015e90818 |
rev | line source |
---|---|
10 | 1 import json |
2 | |
20 | 3 import yaml |
4
1eb6e6a2b9b6
version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff
changeset
|
4 from invoke import task |
20 | 5 from kubernetes import config |
4
1eb6e6a2b9b6
version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff
changeset
|
6 |
20 | 7 from k8s_ops import firstPodName, replaceCmap, refreshPodCmaps |
22
cd115f1ca2a8
use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents:
20
diff
changeset
|
8 import alert_rules |
4
1eb6e6a2b9b6
version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff
changeset
|
9 |
20 | 10 config.load_kube_config() |
12 | 11 |
12 | |
22
cd115f1ca2a8
use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents:
20
diff
changeset
|
13 @task |
cd115f1ca2a8
use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents:
20
diff
changeset
|
14 def push_config(ctx): |
cd115f1ca2a8
use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents:
20
diff
changeset
|
15 configObj = scrapeConfig(ctx) |
cd115f1ca2a8
use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents:
20
diff
changeset
|
16 rulesObj = alert_rules.allRules() |
cd115f1ca2a8
use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents:
20
diff
changeset
|
17 rulesObj["groups"] += alert_rules.expectedK8sNodes(ctx)["groups"] |
cd115f1ca2a8
use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents:
20
diff
changeset
|
18 rulesObj["groups"] += alert_rules.hostsExpectedOnline(ctx)["groups"] |
10 | 19 |
22
cd115f1ca2a8
use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents:
20
diff
changeset
|
20 replaceCmap("victoriametrics-config", {"scrape_main": configObj, "rules": rulesObj}) |
4
1eb6e6a2b9b6
version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff
changeset
|
21 |
22
cd115f1ca2a8
use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents:
20
diff
changeset
|
22 refreshPodCmaps(firstPodName("app=victoriametrics")) |
cd115f1ca2a8
use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents:
20
diff
changeset
|
23 refreshPodCmaps(firstPodName("app=vmalert")) |
4
1eb6e6a2b9b6
version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff
changeset
|
24 |
22
cd115f1ca2a8
use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents:
20
diff
changeset
|
25 # If the VM reloader isn't fast enough, we could do this too: |
cd115f1ca2a8
use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents:
20
diff
changeset
|
26 # hup(ctx, 'deploy/victoriametrics', 'victoria-metrics-prod') |
20 | 27 |
28 | |
29 def scrapeConfig(ctx): | |
22
cd115f1ca2a8
use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents:
20
diff
changeset
|
30 return yaml.load(open("config/scrape_main.yaml"), yaml.FullLoader) |