-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
486 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bazel* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
workspace(name = "io_bazel_rules_prometheus") | ||
|
||
load(":deps.bzl", "prometheus_repositories") | ||
|
||
prometheus_repositories() | ||
|
||
register_toolchains( | ||
"//prometheus/toolchain:all", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
PROMETHEUS_VERSION = "2.23.0" | ||
PROMETHEUS_DARWIN_ARCH = "darwin-amd64" | ||
PROMETHEUS_DARWIN = "{PROMETHEUS_VERSION}.{PROMETHEUS_DARWIN_ARCH}" | ||
PROMETHEUS_DARWIN_URL = "https://github.com/prometheus/prometheus/releases/download/v{PROMETHEUS_VERSION}/prometheus-{PROMETHEUS_VERSION}.{PROMETHEUS_DARWIN_ARCH}.tar.gz" | ||
|
||
def prometheus_repositories(): | ||
http_archive( | ||
name = "prometheus_darwin", | ||
sha256 = "d589a45495cea1aa74bff82335d2145f2d93b8b357c3398739b9139c74dc0cfe", | ||
urls = [PROMETHEUS_DARWIN_URL], | ||
strip_prefix = "prometheus-%s.%s" % (PROMETHEUS_VERSION, PROMETHEUS_DARWIN_ARCH), | ||
build_file = "@//:prometheus.BUILD", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
load("//prometheus:prometheus.bzl", "promtool_config_test", "promtool_unit_test") | ||
|
||
promtool_unit_test( | ||
name = "test_rules_yml", | ||
srcs = [ | ||
"tests.yml", | ||
], | ||
rules = ["rules.yml"], | ||
) | ||
|
||
promtool_unit_test( | ||
name = "test_rules_json", | ||
srcs = [ | ||
"tests.json", | ||
], | ||
rules = ["rules.json"], | ||
) | ||
|
||
promtool_unit_test( | ||
name = "test_rules_multiple", | ||
srcs = [ | ||
"tests.json", | ||
"tests.yml", | ||
], | ||
rules = [ | ||
"rules.json", | ||
"rules.yml", | ||
], | ||
) | ||
|
||
promtool_config_test( | ||
name = "test_config_yml", | ||
srcs = ["prometheus.yml"], | ||
) | ||
|
||
promtool_config_test( | ||
name = "test_config_json", | ||
srcs = ["prometheus.json"], | ||
) | ||
|
||
promtool_config_test( | ||
name = "test_config_multiple", | ||
srcs = [ | ||
"prometheus.json", | ||
"prometheus.yml", | ||
], | ||
) | ||
|
||
test_suite( | ||
name = "all_tests", | ||
tests = [ | ||
":test_config_json", | ||
":test_config_multiple", | ||
":test_config_yml", | ||
":test_rules_json", | ||
":test_rules_multiple", | ||
":test_rules_yml", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"global": { | ||
"scrape_interval": "15s", | ||
"evaluation_interval": "15s" | ||
}, | ||
"alerting": { | ||
"alertmanagers": [ | ||
{ | ||
"static_configs": [ | ||
{ | ||
"targets": null | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"rule_files": null, | ||
"scrape_configs": [ | ||
{ | ||
"job_name": "prometheus", | ||
"static_configs": [ | ||
{ | ||
"targets": ["localhost:9090"] | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# my global config | ||
global: | ||
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. | ||
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. | ||
# scrape_timeout is set to the global default (10s). | ||
|
||
# Alertmanager configuration | ||
alerting: | ||
alertmanagers: | ||
- static_configs: | ||
- targets: | ||
# - alertmanager:9093 | ||
|
||
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'. | ||
rule_files: | ||
# - "first_rules.yml" | ||
# - "second_rules.yml" | ||
|
||
# A scrape configuration containing exactly one endpoint to scrape: | ||
# Here it's Prometheus itself. | ||
scrape_configs: | ||
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. | ||
- job_name: "prometheus" | ||
|
||
# metrics_path defaults to '/metrics' | ||
# scheme defaults to 'http'. | ||
|
||
static_configs: | ||
- targets: ["localhost:9090"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"groups": [ | ||
{ | ||
"name": "example", | ||
"rules": [ | ||
{ | ||
"alert": "InstanceDown", | ||
"expr": "up == 0", | ||
"for": "5m", | ||
"labels": { | ||
"severity": "page" | ||
}, | ||
"annotations": { | ||
"summary": "Instance {{ $labels.instance }} down", | ||
"description": "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes." | ||
} | ||
}, | ||
{ | ||
"alert": "AnotherInstanceDown", | ||
"expr": "up == 0", | ||
"for": "10m", | ||
"labels": { | ||
"severity": "page" | ||
}, | ||
"annotations": { | ||
"summary": "Instance {{ $labels.instance }} down", | ||
"description": "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes." | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# This is the rules file. | ||
|
||
groups: | ||
- name: example | ||
rules: | ||
- alert: InstanceDown | ||
expr: up == 0 | ||
for: 5m | ||
labels: | ||
severity: page | ||
annotations: | ||
summary: "Instance {{ $labels.instance }} down" | ||
description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes." | ||
|
||
- alert: AnotherInstanceDown | ||
expr: up == 0 | ||
for: 10m | ||
labels: | ||
severity: page | ||
annotations: | ||
summary: "Instance {{ $labels.instance }} down" | ||
description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"rule_files": ["rules.json"], | ||
"evaluation_interval": "1m", | ||
"tests": [ | ||
{ | ||
"interval": "1m", | ||
"input_series": [ | ||
{ | ||
"series": "up{job=\"prometheus\", instance=\"localhost:9090\"}", | ||
"values": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" | ||
}, | ||
{ | ||
"series": "up{job=\"node_exporter\", instance=\"localhost:9100\"}", | ||
"values": "1+0x6 0 0 0 0 0 0 0 0" | ||
}, | ||
{ | ||
"series": "go_goroutines{job=\"prometheus\", instance=\"localhost:9090\"}", | ||
"values": "10+10x2 30+20x5" | ||
}, | ||
{ | ||
"series": "go_goroutines{job=\"node_exporter\", instance=\"localhost:9100\"}", | ||
"values": "10+10x7 10+30x4" | ||
} | ||
], | ||
"alert_rule_test": [ | ||
{ | ||
"eval_time": "10m", | ||
"alertname": "InstanceDown", | ||
"exp_alerts": [ | ||
{ | ||
"exp_labels": { | ||
"severity": "page", | ||
"instance": "localhost:9090", | ||
"job": "prometheus" | ||
}, | ||
"exp_annotations": { | ||
"summary": "Instance localhost:9090 down", | ||
"description": "localhost:9090 of job prometheus has been down for more than 5 minutes." | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"promql_expr_test": [ | ||
{ | ||
"expr": "go_goroutines > 5", | ||
"eval_time": "4m", | ||
"exp_samples": [ | ||
{ | ||
"labels": "go_goroutines{job=\"prometheus\",instance=\"localhost:9090\"}", | ||
"value": 50 | ||
}, | ||
{ | ||
"labels": "go_goroutines{job=\"node_exporter\",instance=\"localhost:9100\"}", | ||
"value": 50 | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# This is the main input for unit testing. | ||
# Only this file is passed as command line argument. | ||
|
||
rule_files: | ||
- rules.yml | ||
|
||
evaluation_interval: 1m | ||
|
||
tests: | ||
# Test 1. | ||
- interval: 1m | ||
# Series data. | ||
input_series: | ||
- series: 'up{job="prometheus", instance="localhost:9090"}' | ||
values: "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" | ||
- series: 'up{job="node_exporter", instance="localhost:9100"}' | ||
values: "1+0x6 0 0 0 0 0 0 0 0" # 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 | ||
- series: 'go_goroutines{job="prometheus", instance="localhost:9090"}' | ||
values: "10+10x2 30+20x5" # 10 20 30 30 50 70 90 110 130 | ||
- series: 'go_goroutines{job="node_exporter", instance="localhost:9100"}' | ||
values: "10+10x7 10+30x4" # 10 20 30 40 50 60 70 80 10 40 70 100 130 | ||
|
||
# Unit test for alerting rules. | ||
alert_rule_test: | ||
# Unit test 1. | ||
- eval_time: 10m | ||
alertname: InstanceDown | ||
exp_alerts: | ||
# Alert 1. | ||
- exp_labels: | ||
severity: page | ||
instance: localhost:9090 | ||
job: prometheus | ||
exp_annotations: | ||
summary: "Instance localhost:9090 down" | ||
description: "localhost:9090 of job prometheus has been down for more than 5 minutes." | ||
# Unit tests for promql expressions. | ||
promql_expr_test: | ||
# Unit test 1. | ||
- expr: go_goroutines > 5 | ||
eval_time: 4m | ||
exp_samples: | ||
# Sample 1. | ||
- labels: 'go_goroutines{job="prometheus",instance="localhost:9090"}' | ||
value: 50 | ||
# Sample 2. | ||
- labels: 'go_goroutines{job="node_exporter",instance="localhost:9100"}' | ||
value: 50 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
exports_files([ | ||
"prometheus", | ||
"promtool", | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package(default_visibility = ["//visibility:public"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package( | ||
default_visibility = ["//prometheus:__subpackages__"], | ||
) | ||
|
||
exports_files( | ||
glob([ | ||
"*.bat", | ||
"*.sh", | ||
"*.sh.tpl", | ||
]), | ||
visibility = ["//visibility:public"], | ||
) |
Oops, something went wrong.