prometheus: Target Scraped Twice Race Condition - Possibly Due to Reload
What did you do?
- Reloaded the prometheus configuration file by using the http endpoint
- It is possible that there were some configuration changes related to scrape targets but I am not able to provide details as this is a derived file that is heavily automated and does not contain a log of changes made. I expect this to not be the case because the relevant configuration was not being modified at the time when this happened
What did you expect to see?
- Continued steady-state operation
What did you see instead? Under which circumstances?
- Immediately after a reload, a target had two separate data samples with an almost identical timestamp with a tiny difference in some of the values
- The data gathered first ends up with a later timestamp than the data gathered second
- A
ratecalculated based on the data produces a massive spike because prometheus considers the second sample, which has lower counter values, to have undergone a reset
| time | value | time change | value change |
|---|---|---|---|
| 1582378204.022 | 1183407.023 | ||
| 1582378234.022 | 1183412.101 | 30.000 | 5.078 |
| 1582378264.022 | 1183412.767 | 30.000 | 0.666 |
| 1582378294.032 | 1183419.399 | 30.010 | 6.632 |
| 1582378294.033(13:31:34.033) | 1183419.398 | 0.001 | -0.001 |
| 1582378324.122 | 1183424.997 | 30.089 | 5.599 |
| 1582378354.032 | 1183430.620 | 29.910 | 5.623 |
Environment
-
System information:
Linux 5.0.0-1032-azure x86_64 -
Prometheus version:
prometheus, version 2.15.2 (branch: HEAD, revision: d9613e5c466c6e9de548c4dae1b9aabf9aaf7c57)
build user: root@688433cf4ff7
build date: 20200106-14:50:51
go version: go1.13.5
- Prometheus configuration file:
I’d rather not include the entire configuration file since it is extremely large and does not seem relevant. There are 40
jobsand 565instances
global:
scrape_interval: 30s
scrape_timeout: 10s
evaluation_interval: 30s
external_labels:
prometheus: infrastructure
prometheus_replica: "0"
alerting:
alert_relabel_configs:
- separator: ;
regex: prometheus_replica
replacement: $1
action: labeldrop
alertmanagers:
- kubernetes_sd_configs:
- role: endpoints
namespaces:
names:
- monitoring
scheme: http
path_prefix: /
timeout: 10s
api_version: v1
relabel_configs:
- source_labels: [__meta_kubernetes_service_name]
separator: ;
regex: prom-op-prometheus-operato-alertmanager
replacement: $1
action: keep
- source_labels: [__meta_kubernetes_endpoint_port_name]
separator: ;
regex: web
replacement: $1
action: keep
rule_files:
- /etc/prometheus/rules/prometheus-prom-op-prometheus-operato-prometheus-rulefiles-0/*.yaml
- Logs:
{"caller":"main.go:762","filename":"/etc/prometheus/config_out/prometheus.env.yaml","level":"info","msg":"Completed loading of configuration file","ts":"2020-02-22T13:28:27.884Z"}
{"caller":"manager.go:566","component":"rule manager","group":"infrastructure-remote-metrics-remote-write-metrics","level":"warn","msg":"Error on ingesting results from rule evaluation with different value but same timestamp","numDropped":2,"ts":"2020-02-22T13:28:37.523Z"}
{"caller":"manager.go:566","component":"rule manager","group":"infrastructure-remote-metrics-remote-write-metrics","level":"warn","msg":"Error on ingesting results from rule evaluation with different value but same timestamp","numDropped":2,"ts":"2020-02-22T13:28:37.653Z"}
{"caller":"manager.go:563","component":"rule manager","group":"kube-apiserver.rules","level":"warn","msg":"Error on ingesting out-of-order result from rule evaluation","numDropped":603,"ts":"2020-02-22T13:31:03.237Z"}
{"caller":"main.go:734","filename":"/etc/prometheus/config_out/prometheus.env.yaml","level":"info","msg":"Loading configuration file","ts":"2020-02-22T13:31:27.322Z"}
{"caller":"kubernetes.go:190","component":"discovery manager scrape","discovery":"k8s","level":"info","msg":"Using pod service account via in-cluster config","ts":"2020-02-22T13:31:27.614Z"}
{"caller":"kubernetes.go:190","component":"discovery manager scrape","discovery":"k8s","level":"info","msg":"Using pod service account via in-cluster config","ts":"2020-02-22T13:31:27.616Z"}
{"caller":"kubernetes.go:190","component":"discovery manager scrape","discovery":"k8s","level":"info","msg":"Using pod service account via in-cluster config","ts":"2020-02-22T13:31:27.617Z"}
{"caller":"kubernetes.go:190","component":"discovery manager scrape","discovery":"k8s","level":"info","msg":"Using pod service account via in-cluster config","ts":"2020-02-22T13:31:27.618Z"}
{"caller":"kubernetes.go:190","component":"discovery manager scrape","discovery":"k8s","level":"info","msg":"Using pod service account via in-cluster config","ts":"2020-02-22T13:31:27.619Z"}
{"caller":"kubernetes.go:190","component":"discovery manager scrape","discovery":"k8s","level":"info","msg":"Using pod service account via in-cluster config","ts":"2020-02-22T13:31:27.620Z"}
{"caller":"kubernetes.go:190","component":"discovery manager scrape","discovery":"k8s","level":"info","msg":"Using pod service account via in-cluster config","ts":"2020-02-22T13:31:27.621Z"}
{"caller":"kubernetes.go:190","component":"discovery manager scrape","discovery":"k8s","level":"info","msg":"Using pod service account via in-cluster config","ts":"2020-02-22T13:31:27.623Z"}
{"caller":"kubernetes.go:190","component":"discovery manager scrape","discovery":"k8s","level":"info","msg":"Using pod service account via in-cluster config","ts":"2020-02-22T13:31:27.624Z"}
{"caller":"kubernetes.go:190","component":"discovery manager scrape","discovery":"k8s","level":"info","msg":"Using pod service account via in-cluster config","ts":"2020-02-22T13:31:27.625Z"}
{"caller":"kubernetes.go:190","component":"discovery manager scrape","discovery":"k8s","level":"info","msg":"Using pod service account via in-cluster config","ts":"2020-02-22T13:31:27.626Z"}
{"caller":"kubernetes.go:190","component":"discovery manager scrape","discovery":"k8s","level":"info","msg":"Using pod service account via in-cluster config","ts":"2020-02-22T13:31:27.627Z"}
{"caller":"kubernetes.go:190","component":"discovery manager scrape","discovery":"k8s","level":"info","msg":"Using pod service account via in-cluster config","ts":"2020-02-22T13:31:27.629Z"}
{"caller":"kubernetes.go:190","component":"discovery manager scrape","discovery":"k8s","level":"info","msg":"Using pod service account via in-cluster config","ts":"2020-02-22T13:31:27.630Z"}
{"caller":"kubernetes.go:190","component":"discovery manager scrape","discovery":"k8s","level":"info","msg":"Using pod service account via in-cluster config","ts":"2020-02-22T13:31:27.632Z"}
{"caller":"kubernetes.go:190","component":"discovery manager notify","discovery":"k8s","level":"info","msg":"Using pod service account via in-cluster config","ts":"2020-02-22T13:31:27.633Z"}
{"caller":"main.go:762","filename":"/etc/prometheus/config_out/prometheus.env.yaml","level":"info","msg":"Completed loading of configuration file","ts":"2020-02-22T13:31:27.898Z"}
{"caller":"manager.go:563","component":"rule manager","group":"kube-apiserver.rules","level":"warn","msg":"Error on ingesting out-of-order result from rule evaluation","numDropped":603,"ts":"2020-02-22T13:34:03.863Z"}
{"caller":"main.go:734","filename":"/etc/prometheus/config_out/prometheus.env.yaml","level":"info","msg":"Loading configuration file","ts":"2020-02-22T13:34:27.322Z"}
{"caller":"kubernetes.go:190","component":"discovery manager scrape","discovery":"k8s","level":"info","msg":"Using pod service account via in-cluster config","ts":"2020-02-22T13:34:27.633Z"}
Speculation I would expect this to be related to a configuration reload - otherwise we would be seeing this more frequently.
I do not know the prometheus internals to a sufficient degree to know, but I suspect that there is a channel for scrapes that need to be handled that is populated based on the configuration in memory. The same target ended up being added to this channel after a reload, which caused the double-scrape. I don’t know what logic exists in Prometheus to handle not adding the same target twice, but whatever happened was either not caught by it due to a bug in the reload logic, or by design because the target configuration was modified.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 15 (15 by maintainers)
Commits related to this issue
- Fix Target Scraped Twice Race Condition ? See #6894 Just POC Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu> — committed to roidelapluie/prometheus by deleted user 7 years ago
Moving start seems a better fix. I will propose a PR in the coming days.