view tasks.py @ 34:3b91d52b007d

rules tuning
author drewp@bigasterisk.com
date Mon, 09 Oct 2023 18:50:36 -0700
parents eb1de82c93aa
children 21185db8a52e
line wrap: on
line source

import yaml
from invoke import task
from kubernetes import config

import alert_rules
from k8s_ops import firstPodName, refreshPodCmaps, replaceCmap

config.load_kube_config()


@task
def push_config(ctx):
    configObj = scrapeConfig(ctx)
    rulesObj = alert_rules.allRules(ctx)

    replaceCmap("victoriametrics-config", {"scrape_main": configObj, "rules": rulesObj})

    # these don't give errors on rules format! they just quietly keep the old
    # rules! use `skaffold run` to get errs.
    #
    # or run
    #  validateTemplates   = flag.Bool("rule.validateTemplates", true, "Whether to validate annotation and label templates")
	#  validateExpressions = flag.Bool("rule.validateExpressions", true, "Whether to validate rules expressions via MetricsQL engine")

    refreshPodCmaps(firstPodName("app=victoriametrics"))
    refreshPodCmaps(firstPodName("app=vmalert"))

    # If the VM reloader isn't fast enough, we could do this too:
    # hup(ctx, 'deploy/victoriametrics', 'victoria-metrics-prod')


def scrapeConfig(ctx):
    return yaml.load(open("config/scrape_main.yaml"), yaml.FullLoader)