Mercurial > code > home > repos > victoriametrics
comparison tasks.py @ 20:f5777b65f035
fast update of scrape_main.yaml
author | drewp@bigasterisk.com |
---|---|
date | Sat, 24 Jun 2023 01:44:57 -0700 |
parents | 2c37fab420da |
children | cd115f1ca2a8 |
comparison
equal
deleted
inserted
replaced
19:10017def57ce | 20:f5777b65f035 |
---|---|
4 import time | 4 import time |
5 import urllib.request | 5 import urllib.request |
6 from pathlib import Path | 6 from pathlib import Path |
7 from typing import Dict | 7 from typing import Dict |
8 | 8 |
9 import yaml | |
9 from invoke import task | 10 from invoke import task |
11 from kubernetes import config | |
10 | 12 |
11 sys.path.append('/usr/lib/python3/dist-packages/') | 13 from k8s_ops import firstPodName, replaceCmap, refreshPodCmaps |
12 import yaml | |
13 | 14 |
14 _tfs = [] | 15 _tfs = [] |
16 config.load_kube_config() | |
15 | 17 |
16 | 18 |
17 def saveTmp(text): | 19 def saveTmp(text): |
18 tf = tempfile.NamedTemporaryFile(mode='wt') | 20 tf = tempfile.NamedTemporaryFile(mode='wt') |
19 _tfs.append(tf) | 21 _tfs.append(tf) |
36 print(f'reload with POST {reload_url}') | 38 print(f'reload with POST {reload_url}') |
37 for workaround in [1]: | 39 for workaround in [1]: |
38 print(' -> status', | 40 print(' -> status', |
39 urllib.request.urlopen(reload_url, data=b'unused').status) | 41 urllib.request.urlopen(reload_url, data=b'unused').status) |
40 time.sleep(0) | 42 time.sleep(0) |
41 | |
42 | 43 |
43 | 44 |
44 def hostsExpectedOnline(ctx): | 45 def hostsExpectedOnline(ctx): |
45 return ctx.run( | 46 return ctx.run( |
46 'cd /my/serv/lanscape; pdm run python hosts_expected_online.py').stdout | 47 'cd /my/serv/lanscape; pdm run python hosts_expected_online.py').stdout |
83 | 84 |
84 # this reload doesn't get the new config- not sure if it's vmalert bug or k8s cm propogation problem | 85 # this reload doesn't get the new config- not sure if it's vmalert bug or k8s cm propogation problem |
85 # reload(ctx, 'vmalert') | 86 # reload(ctx, 'vmalert') |
86 ctx.run('kubectl rollout restart deploy/vmalert') | 87 ctx.run('kubectl rollout restart deploy/vmalert') |
87 | 88 |
89 | |
88 @task | 90 @task |
89 def build_config(ctx): | 91 def build_config(ctx): |
90 with open('rules/build/expected_hosts.yaml', 'w') as out: | 92 with open('rules/build/expected_hosts.yaml', 'w') as out: |
91 out.write(hostsExpectedOnline(ctx)) | 93 out.write(hostsExpectedOnline(ctx)) |
94 | |
95 | |
96 # -------------------------- | |
97 | |
98 | |
99 def scrapeConfig(ctx): | |
100 return yaml.load(open('config/scrape_main.yaml'), yaml.FullLoader) | |
101 | |
102 | |
103 @task | |
104 def updateScrapes(ctx): | |
105 configObj = scrapeConfig(ctx) | |
106 | |
107 replaceCmap('victoriametrics-config', configObj) | |
108 | |
109 refreshPodCmaps(firstPodName('app=victoriametrics')) | |
110 | |
111 # If the VM reloader isn't fast enough, we could do this too: | |
112 # hup(ctx, 'deploy/victoriametrics', 'victoria-metrics-prod') |