view tasks.py @ 58:0064c490c33d

some tiny scrape configs for testing multi-node vmstorage/vmselect
author drewp@bigasterisk.com
date Fri, 26 Apr 2024 15:48:22 -0700
parents 21185db8a52e
children 6a357b483c04
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):
    rulesObj = alert_rules.allRules(ctx)

    replaceCmap("victoriametrics-config", {
        "scrape_main": scrapeConfig("config/scrape_main.yaml"),
        "scrape_recent": scrapeConfig("config/scrape_recent.yaml"),
        "scrape_forever": scrapeConfig("config/scrape_forever.yaml"),
        "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(fn):
    return yaml.load(open(fn), yaml.FullLoader)