Skip to content

Latest commit

 

History

History
221 lines (143 loc) · 5.82 KB

README.md

File metadata and controls

221 lines (143 loc) · 5.82 KB

Prometheus bazel rules

Prometheus/Alertmanager rules for Bazel

TODO

  • integrate alertmanager and amtool into rules and workspace binaries (todo with sergey)
  • implement local backfiller (todo with alexander)
  • start alertmanager with input configs
  • unit test rules and toolchains
  • add linux toolchain
  • run some binary tests macros against prometheus server and alertmanager for smoke/integration/load testing
  • make toolchains work in containers

Initial project setup

You will need recent Bazel release, otherwise rules will download and discover dependent required tools

otherwise, refer to release page

Rules

promtool_config_test

promtool_config_test(name, srcs)

Run "promtool check config" against config targets

Example:

//examples:test_config_yml

load("//prometheus:defs.bzl", "promtool_config_test")
promtool_config_test(
    name = "test_config_yml",
    srcs = ["prometheus.yml"],
)
bazel test //examples:test_config_yml

//examples:test_config_yml                                      PASSED in 0.1s

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
srcs List of prometheus configuration targets List of labels required

promtool_rules_test

promtool_rules_test(name, srcs)

Run "promtool check rules" against rules targets

Example:

//examples:test_rules_yml
promtool_rules_test(
    name = "test_rules_yml",
    srcs = ["rules.yml"],
)
bazel test //examples:test_rules_yml

//examples:unit_test_rules_yml                                           PASSED in 0.3s

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
srcs List of Prometheus rules file targets List of labels required

promtool_unit_test

promtool_unit_test(name, rules, srcs)

Run "promtool test rules" against test targets and rules files

Example:

//examples:unit_test_rules_yml

load("//prometheus:defs.bzl", "promtool_unit_test")
promtool_unit_test(
name = "unit_test_rules_yml",
srcs = [
"tests.yml",
],
rules = ["rules.yml"],
)
bazel test //examples:unit_test_rules_yml

//examples:unit_test_rules_yml                                                PASSED in 0.1s

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
rules List of Rules-under-Test file targets List of labels required
srcs List of Prometheus Unit Test file targets List of labels required

prometheus

prometheus(name, kwargs)

Prometheus runner which will launch prometheus server

This will emit runnable sh_binary target which will invoke prometheus server with all arguments passed along. Tool will have access to workspace. It is intended for convenient in-workspace usage by human and not to be invoked programmatically.

Example:

load("//prometheus:defs.bzl", "prometheus")

package(default_visibility = ["//visibility:public"])

prometheus(
    name = "prometheus",
)

PARAMETERS

Name Description Default Value
name A unique name for this target. none
kwargs Attributes to be passed along none

promtool

promtool(name, kwargs)

Promtool runner which will launch promtool

This rule will emit runnable sh_binary target which will invoke promtool binary and all passed arguments along. Tool will have access to workspace. It is intended for convenient in-workspace usage by human and not to be invoked programmatically.

Example:

//:promtool
load("//prometheus:defs.bzl", "promtool")

package(default_visibility = ["//visibility:public"])

promtool(
    name = "promtool",
)

PARAMETERS

Name Description Default Value
name A unique name for this target. none
kwargs Attributes to be passed along none

Examples

Here