Git Product home page Git Product logo

prometheusruleloader's Introduction

New version contains breaking changes, see Changes below

Handy Kubernetes sidecar for Prometheus 2.x. It watches for configmaps in all namespaces that have the annotation specified with the -annotation flag. When it finds one it pulls each value out and assumes it's a prometheus rule. It then validates them and adds them to a the rules file specified with -rulespath. If that file changes it hits the reload endpoint specified by the -endpoint flag.

Changes

  • New 5.0 version, no breaking changes. Some work to reduce churn, added an event recorder, configmaps will get events if keys are successfully loaded or not. Brought up to spec with the current kubernetes sample controller. If it finds two RuleGroup(s) with the same name it will automatically salt the name of the duplicate in the final configmap.
  • New 3.0 version, breaking changes! This works with the new prometheus 2 rules only, if you want to use the rule loader with prometheus 1.x please use the prom1.x-stable tag.

Parameters

  • -annotation - Used to customize the annotation label you'd like the rule loader to look like on your configmaps.
  • -rulespath - The location you would like your rules to be written to. Should correspond to a rule_files path in your prometheus config.
  • -endpoint - Endpoint to make a bodyless POST request to (Prometheus uses /-/reload)
  • -batchtime - Configure how long you want it to sleep between reload attempts in seconds, if your configmaps churn a lot it can cause excessive reloads on prometheus.
  • -kubeconfig - Use a kubeconfig to configure the connection to the api server, off cluster use only.
  • master - Address of the master server, overrides server in kubeconfig. For off cluster use only.

for example:

./PrometheusRuleLoader -rulespath ./rules.rules -annotation 'prometheus.io/v2/rules' -endpoint http://127.0.0.1:9090/-/reload

Configmap Annotation

Assuming a launch with the above commandline here is an example of a configmap.

kind: ConfigMap
apiVersion: v1
metadata:
  name: 'test-rules'
  namespace: "kube-system"
  labels:
    app: "prometheus"
  annotations: {
    "prometheus.io/v2/rules": "true"
  }
data:
  mygroupname: |
    - record: job:http_inprogress_requests:sum
      expr: sum(http_inprogress_requests) by (job)
    - alert: HighErrorRate
      expr: job:request_latency_seconds:mean5m{job="myjob"} > 0.5
      for: 10m
      labels:
        severity: page
      annotations:
        summary: High request latency

The value of the configmap that contains rules can either be in the format of []Rules, RuleGroup, or RuleGroups as detailed in github.com/prometheus/prometheus/pkg/rulefmt. If the values are in the []Rules format a group will be created around them and named configmapnamespace-configmapname-key.

Once all the appropriate configmaps are processed all the groups will be assembled into a single rule file named -rulespath.

Deployment

The PrometheusRuleLoaders docker container should be deployed in the same pod as prometheus. They should both share a volume mount (and emptydir works fine here). PrometheusRuleLoader will use this shared space to write it's rule file to, meanwhile Prometheus should be configured to look for it's rule file at this path.

prometheusruleloader's People

Contributors

bregor avatar dhawal55 avatar jperville avatar sleepybrett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

prometheusruleloader's Issues

Duplicate rules when configMap value is RuleGroups or RuleGroup

A configMap like:

kind: ConfigMap
apiVersion: v1
metadata:
  name: prometheus-rules
  namespace: default
  annotations:
    prometheus.io/rules: "true"
data:
  myrulegroups: |
    groups:
    - name: my.rules
      rules:
      - alert: Watchdog
        expr: vector(1)
        labels:
        severity: none
        annotations:
          message: |
            This is an alert meant to ensure that the entire alerting pipeline is functional.
            This alert is always firing, therefore it should always be firing in Alertmanager
            and always fire against a receiver. There are integrations with various notification
            mechanisms that send a notification when this alert is not firing. For example the
            "DeadMansSnitch" integration in PagerDuty.

results in two duplicate rules in the generated rules file:

$ cat /etc/prometheus/dynamic-rules/rules.yml
groups:
- name: my.rules
  rules:
  - alert: Watchdog
    expr: vector(1)
    annotations:
      message: |
        This is an alert meant to ensure that the entire alerting pipeline is functional.
        This alert is always firing, therefore it should always be firing in Alertmanager
        and always fire against a receiver. There are integrations with various notification
        mechanisms that send a notification when this alert is not firing. For example the
        "DeadMansSnitch" integration in PagerDuty
- name: my.rules
  rules:
  - alert: Watchdog
    expr: vector(1)
    annotations:
      message: |
        This is an alert meant to ensure that the entire alerting pipeline is functional.
        This alert is always firing, therefore it should always be firing in Alertmanager
        and always fire against a receiver. There are integrations with various notification
        mechanisms that send a notification when this alert is not firing. For example the
        "DeadMansSnitch" integration in PagerDuty

As a result, prometheusRuleLoader reload of prometheus fails with prometheus throwing an error:

2019/07/25 01:47:59 Unable to reload the Prometheus config. Endpoint: http://127.0.0.1:9090/-/reload, Reponse StatusCode: 500, Response Body: failed to reload config: one or more errors occurred while applying the new configuration (--config.file="/etc/prometheus/prometheus.yml")

Metrics for rule-loader

It would be great to have some metrics for the rule-loader itself.

Like for example a counter for rejected rules that can be alerted on.

[Feature] Add parameter to control log verbosity (esp. to omit events about irrelevant ConfigMaps)

On v5.0, if the cluster is getting a lot of changes to ConfigMaps, prometheusruleloader spits out a lot of logs:

I1104 22:16:40.220118       1 controller.go:199] Successfully synced 'namespace1/myconfigmap'
I1104 22:16:40.220118       1 controller.go:199] Successfully synced 'namespace1/myconfigmap'
I1104 22:16:40.220118       1 controller.go:199] Successfully synced 'namespace1/myconfigmap'
I1104 22:16:44.962284       1 controller.go:199] Successfully synced 'namespace2/myconfigmap'
I1104 22:16:46.982016       1 controller.go:199] Successfully synced 'namespace2/myconfigmap'
I1104 22:16:48.997786       1 controller.go:199] Successfully synced 'namespace2/myconfigmap'
I1104 22:16:40.220118       1 controller.go:199] Successfully synced 'namespace3/myconfigmap'
I1104 22:16:40.911943       1 controller.go:199] Successfully synced 'namespace3/myconfigmap'
I1104 22:16:42.943651       1 controller.go:199] Successfully synced 'namespace3/myconfigmap'
...

It would be great to have some -log-level parameter to control the logging verbosity so that only ConfigMaps with an annotation matching that specified in -annotation get logged about their sync status in INFO log level, and those that don't match get logged only on the DEBUG log level etc.

License?

Thanks for the repo, decoupling prometheus rules and dynamically reloading them is the only really useful thing around prometheus-operator. With this sidecar one may be able to eliminate the prometheus-operator entirely.

May i ask, what's the license for this repo?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.