Initial project setup

May 2, 2021 ยท View on GitHub

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcsList of prometheus configuration targetsList of labelsrequired

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcsList of Prometheus rules file targetsList of labelsrequired

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
rulesList of Rules-under-Test file targetsList of labelsrequired
srcsList of Prometheus Unit Test file targetsList of labelsrequired

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

NameDescriptionDefault Value
nameA unique name for this target.none
kwargsAttributes to be passed alongnone

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

NameDescriptionDefault Value
nameA unique name for this target.none
kwargsAttributes to be passed alongnone

Examples

Here