Skip to content

Commit ebc25a0

Browse files
committed
Merge branch 'thomasjpfan-prometheus2'
2 parents e9084c9 + fe0a5cc commit ebc25a0

19 files changed

+443
-160
lines changed

Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.8 AS build
1+
FROM golang:1.9.2 AS build
22
ADD . /src
33
WORKDIR /src
44
RUN go get -t github.com/stretchr/testify/suite
@@ -8,7 +8,7 @@ RUN CGO_ENABLED=0 GOOS=linux go build -v -o docker-flow-monitor
88

99

1010

11-
FROM prom/prometheus:v1.8.1
11+
FROM prom/prometheus:v2.0.0
1212

1313
ENV GLOBAL_SCRAPE_INTERVAL=10s \
1414
ARG_CONFIG_FILE=/etc/prometheus/prometheus.yml \
@@ -24,7 +24,10 @@ ENTRYPOINT ["docker-flow-monitor"]
2424
HEALTHCHECK --interval=5s CMD /bin/check.sh
2525

2626
COPY --from=build /src/docker-flow-monitor /bin/docker-flow-monitor
27-
RUN chmod +x /bin/docker-flow-monitor
2827
COPY check.sh /bin/check.sh
28+
29+
USER root
2930
RUN chmod +x /bin/check.sh
31+
RUN chmod +x /bin/docker-flow-monitor
32+
USER nobody
3033

Jenkinsfile

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,15 @@ pipeline {
2424
branch "master"
2525
}
2626
steps {
27-
withCredentials([usernamePassword(
28-
credentialsId: "docker",
29-
usernameVariable: "USER",
30-
passwordVariable: "PASS"
31-
)]) {
32-
sh "docker login -u $USER -p $PASS"
33-
}
34-
sh "docker tag vfarcic/docker-flow-monitor vfarcic/docker-flow-monitor:${currentBuild.displayName}"
27+
dockerLogin()
28+
sh "docker tag vfarcic/docker-flow-monitor vfarcic/docker-flow-monitor:2-${currentBuild.displayName}"
3529
sh "docker image push vfarcic/docker-flow-monitor:latest"
36-
sh "docker image push vfarcic/docker-flow-monitor:${currentBuild.displayName}"
37-
sh "docker tag vfarcic/docker-flow-monitor-docs vfarcic/docker-flow-monitor-docs:${currentBuild.displayName}"
30+
sh "docker image push vfarcic/docker-flow-monitor:2-${currentBuild.displayName}"
31+
sh "docker tag vfarcic/docker-flow-monitor-docs vfarcic/docker-flow-monitor-docs:2-${currentBuild.displayName}"
3832
sh "docker image push vfarcic/docker-flow-monitor-docs:latest"
39-
sh "docker image push vfarcic/docker-flow-monitor-docs:${currentBuild.displayName}"
33+
sh "docker image push vfarcic/docker-flow-monitor-docs:2-${currentBuild.displayName}"
34+
dockerLogout()
35+
dfReleaseGithub("docker-flow-monitor")
4036
}
4137
}
4238
stage("deploy") {
@@ -47,8 +43,8 @@ pipeline {
4743
label "prod"
4844
}
4945
steps {
50-
sh "docker service update --image vfarcic/docker-flow-monitor:${currentBuild.displayName} monitor_monitor"
51-
sh "docker service update --image vfarcic/docker-flow-monitor-docs:${currentBuild.displayName} monitor_docs"
46+
sh "docker service update --image vfarcic/docker-flow-monitor:2-${currentBuild.displayName} monitor_monitor"
47+
sh "docker service update --image vfarcic/docker-flow-monitor-docs:2-${currentBuild.displayName} monitor_docs"
5248
}
5349
}
5450
}

docs/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,4 +846,4 @@ Before you leave, please remove the Docker machines we created and free the reso
846846

847847
```bash
848848
docker-machine rm -f swarm-1 swarm-2 swarm-3
849-
```
849+
```

docs/auto-scaling.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,19 +321,31 @@ You should see three alerts that correspond to the three labels define in the `m
321321
If you expand the *godemo_main_resp_time_above* alert, you'll see that DFM translated the service labels into the alert definition that follows.
322322
323323
```
324-
ALERT godemo_main_resp_tim_eabove
325-
IF sum(rate(http_server_resp_time_bucket{job="go-demo_main",le="0.1"}[5m])) / sum(rate(http_server_resp_time_count{job="go-demo_main"}[5m])) < 0.99
326-
LABELS {receiver="system", scale="up", service="go-demo_main"}
327-
ANNOTATIONS {summary="Response time of the service go-demo_main is above 0.1"}
324+
alert: godemo_main_resptimeabove
325+
expr: sum(rate(http_server_resp_time_bucket{job="go-demo_main",le="0.1"}[5m]))
326+
/ sum(rate(http_server_resp_time_count{job="go-demo_main"}[5m])) < 0.99
327+
labels:
328+
receiver: system
329+
scale: up
330+
service: go-demo_main
331+
type: service
332+
annotations:
333+
summary: Response time of the service go-demo_main is above 0.1
328334
```
329335
330336
Similarly, the *godemo_main_resp_time_below* alert is defined as follows.
331337
332338
```
333-
ALERT godemo_main_resp_time_below
334-
IF sum(rate(http_server_resp_time_bucket{job="go-demo_main",le="0.025"}[5m])) / sum(rate(http_server_resp_time_count{job="go-demo_main"}[5m])) > 0.75
335-
LABELS {receiver="system", scale="down", service="go-demo_main"}
336-
ANNOTATIONS {summary="Response time of the service go-demo_main is below 0.025"}
339+
alert: godemo_main_resptimebelow
340+
expr: sum(rate(http_server_resp_time_bucket{job="go-demo_main",le="0.025"}[5m]))
341+
/ sum(rate(http_server_resp_time_count{job="go-demo_main"}[5m])) > 0.75
342+
labels:
343+
receiver: system
344+
scale: down
345+
service: go-demo_main
346+
type: service
347+
annotations:
348+
summary: Response time of the service go-demo_main is below 0.025
337349
```
338350
339351
Let's confirm that the `go-demo` stack is up-and-running.

docs/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ The formatting rules for the `REMOTE_WRITE` variables follow the same pattern as
8585

8686
Additional scrapes can be added through files prefixed with `scrape_`. By default, all such files located in `/run/secrets` are automatically added to the `scrape_configs` section of the configuration. The directory can be changed by setting a different value to the environment variable `CONFIGS_DIR`.
8787

88-
The simplest way to add scrape configs is to use Docker [secrets](https://docs.docker.com/engine/swarm/secrets/) or [configs](https://docs.docker.com/engine/swarm/configs/).
88+
The simplest way to add scrape configs is to use Docker [secrets](https://docs.docker.com/engine/swarm/secrets/) or [configs](https://docs.docker.com/engine/swarm/configs/).

docs/migration.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Migration Guide
2+
3+
*Docker Flow Monitor* (DFM) now supports Prometheus 2! Prometheus 2 includes a new storage subsystem that has reduce CPU usage and lower disk space usage compared to Prometheus 1. This guide highlights issues that you may encounter when upgrading to Prometheus 2.
4+
5+
## Database
6+
7+
When upgrading from DFM backed by Prometheus 1 to Prometheus 2, DFM will create a new database supported by Prometheus 2. If you need to access the previous data scraped by Prometheus 1, downgrade your DFM instance using tag: `17.12.12-36`. DFM will launch with Prometheus 1, and continue using the previous database.
8+
9+
## Backwards Compatibility
10+
11+
The command line arguments for Prometheus 2 has changed. This is detailed in Prometheus's [Official Migration Guide](https://prometheus.io/docs/prometheus/latest/migration/). *DFM* will continue to support the previous command line arguments prefixed by `ARG_`:
12+
13+
1. Setting `ARG_ALERTMANAGER_URL` configures the alertmanager correctly for Prometheus 2.
14+
2. `ARG_STORAGE_LOCAL_PATH` maps to `--storage.tsdb.path`.
15+
3. `ARG_STORAGE_LOCAL_RETENTION` maps to `--storage.tsdb.retention`.
16+
4. `ARG_QUERY_STALENESS-DELTA` maps to `--query.lookback-delta`.
17+
5. Setting `ARG_ENABLE-REMOTE-SHUTDOWN=true` sets flag `--web.enable-lifecycle`
18+
19+
You can explore the new flags in Prometheus 2 by downloading the binary from their [Download Page](https://prometheus.io/download/) and running `./prometheus -h`.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pages:
66
- Auto-Scaling Services Using Instrumented Metrics: auto-scaling.md
77
- Configuration: config.md
88
- Usage: usage.md
9+
- Migration Guide: migration.md
910
- About:
1011
- Release Notes: release-notes.md
1112
- License: license.md

prometheus/alert.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,28 @@ import (
77

88
// GetAlertConfig returns Prometheus configuration snippet related to alerts.
99
func GetAlertConfig(alerts map[string]Alert) string {
10-
templateString := `{{range .}}
11-
ALERT {{.AlertNameFormatted}}
12-
IF {{.AlertIf}}{{if .AlertFor}}
13-
FOR {{.AlertFor}}{{end}}
14-
{{- if .AlertLabels}}
15-
LABELS {
16-
{{- range $key, $value := .AlertLabels}}
17-
{{$key}} = "{{$value}}",
10+
templateString := `groups:
11+
- name: alert.rules
12+
rules:
13+
{{- range . }}
14+
- alert: {{ .AlertNameFormatted }}
15+
expr: {{ .AlertIf }}
16+
{{- if .AlertFor }}
17+
for: {{ .AlertFor }}
18+
{{- end }}
19+
{{- if .AlertLabels }}
20+
labels:
21+
{{- range $key, $value := .AlertLabels }}
22+
{{ $key }}: {{ $value }}
1823
{{- end}}
19-
}
20-
{{- end}}
21-
{{- if .AlertAnnotations}}
22-
ANNOTATIONS {
23-
{{- range $key, $value := .AlertAnnotations}}
24-
{{$key}} = "{{$value}}",
24+
{{- end }}
25+
{{- if .AlertAnnotations }}
26+
annotations:
27+
{{- range $key, $value := .AlertAnnotations }}
28+
{{ $key }}: "{{ $value }}"
2529
{{- end}}
26-
}
27-
{{- end}}
28-
{{end}}`
30+
{{- end }}
31+
{{- end }}`
2932
tmpl, _ := template.New("").Parse(templateString)
3033
var b bytes.Buffer
3134
tmpl.Execute(&b, alerts)

prometheus/alert_test.go

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package prometheus
22

33
import (
44
"fmt"
5-
"github.com/stretchr/testify/suite"
65
"testing"
6+
7+
"github.com/stretchr/testify/suite"
78
)
89

910
type AlertTestSuite struct {
@@ -24,14 +25,15 @@ func TestAlertUnitTestSuite(t *testing.T) {
2425
// GetAlertConfig
2526

2627
func (s *AlertTestSuite) Test_GetAlertConfig_ReturnsConfigWithData() {
27-
expected := ""
28+
expected := `groups:
29+
- name: alert.rules
30+
rules:`
2831
alerts := s.getTestAlerts()
2932
for _, i := range []int{1, 2} {
3033
expected += fmt.Sprintf(`
31-
ALERT alertNameFormatted%d
32-
IF alert-if-%d
33-
FOR alert-for-%d
34-
`, i, i, i)
34+
- alert: alertNameFormatted%d
35+
expr: alert-if-%d
36+
for: alert-for-%d`, i, i, i)
3537
}
3638

3739
actual := GetAlertConfig(alerts)
@@ -40,18 +42,19 @@ ALERT alertNameFormatted%d
4042
}
4143

4244
func (s *AlertTestSuite) Test_GetAlertConfig_ReturnsConfigWithLabels_WhenPresent() {
43-
expected := ""
45+
expected := `groups:
46+
- name: alert.rules
47+
rules:`
4448
alerts := s.getTestAlerts()
4549
for _, i := range []int{1, 2} {
4650
expected += fmt.Sprintf(`
47-
ALERT alertNameFormatted%d
48-
IF alert-if-%d
49-
FOR alert-for-%d
50-
LABELS {
51-
alert-label-%d-1 = "alert-label-value-%d-1",
52-
alert-label-%d-2 = "alert-label-value-%d-2",
53-
}
54-
`, i, i, i, i, i, i, i)
51+
- alert: alertNameFormatted%d
52+
expr: alert-if-%d
53+
for: alert-for-%d
54+
labels:
55+
alert-label-%d-1: alert-label-value-%d-1
56+
alert-label-%d-2: alert-label-value-%d-2`,
57+
i, i, i, i, i, i, i)
5558
key := fmt.Sprintf("alert-name-%d", i)
5659
alert := alerts[key]
5760
alert.AlertLabels = map[string]string{
@@ -67,18 +70,19 @@ ALERT alertNameFormatted%d
6770
}
6871

6972
func (s *AlertTestSuite) Test_GetAlertConfig_ReturnsConfigWithAnnotations_WhenPresent() {
70-
expected := ""
73+
expected := `groups:
74+
- name: alert.rules
75+
rules:`
7176
alerts := s.getTestAlerts()
7277
for _, i := range []int{1, 2} {
7378
expected += fmt.Sprintf(`
74-
ALERT alertNameFormatted%d
75-
IF alert-if-%d
76-
FOR alert-for-%d
77-
ANNOTATIONS {
78-
alert-annotation-%d-1 = "alert-annotation-value-%d-1",
79-
alert-annotation-%d-2 = "alert-annotation-value-%d-2",
80-
}
81-
`, i, i, i, i, i, i, i)
79+
- alert: alertNameFormatted%d
80+
expr: alert-if-%d
81+
for: alert-for-%d
82+
annotations:
83+
alert-annotation-%d-1: "alert-annotation-value-%d-1"
84+
alert-annotation-%d-2: "alert-annotation-value-%d-2"`,
85+
i, i, i, i, i, i, i)
8286
key := fmt.Sprintf("alert-name-%d", i)
8387
alert := alerts[key]
8488
alert.AlertAnnotations = map[string]string{

0 commit comments

Comments
 (0)