mirror of https://github.com/prometheus/prometheus
sanitize scrape health recording code
parent
1a7f701359
commit
6d0f58dcf3
|
@ -38,12 +38,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// ScrapeHealthMetricName is the metric name for the synthetic health
|
scrapeHealthMetricName = "up"
|
||||||
// variable.
|
scrapeDurationMetricName = "scrape_duration_seconds"
|
||||||
scrapeHealthMetricName model.LabelValue = "up"
|
|
||||||
// ScrapeTimeMetricName is the metric name for the synthetic scrape duration
|
|
||||||
// variable.
|
|
||||||
scrapeDurationMetricName model.LabelValue = "scrape_duration_seconds"
|
|
||||||
// Capacity of the channel to buffer samples during ingestion.
|
// Capacity of the channel to buffer samples during ingestion.
|
||||||
ingestedSamplesCap = 256
|
ingestedSamplesCap = 256
|
||||||
|
|
||||||
|
@ -85,6 +82,13 @@ func (t TargetHealth) String() string {
|
||||||
panic("unknown state")
|
panic("unknown state")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t TargetHealth) value() model.SampleValue {
|
||||||
|
if t == HealthGood {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Unknown is the state of a Target before it is first scraped.
|
// Unknown is the state of a Target before it is first scraped.
|
||||||
HealthUnknown TargetHealth = iota
|
HealthUnknown TargetHealth = iota
|
||||||
|
@ -565,17 +569,12 @@ func recordScrapeHealth(
|
||||||
healthMetric := make(model.Metric, len(baseLabels)+1)
|
healthMetric := make(model.Metric, len(baseLabels)+1)
|
||||||
durationMetric := make(model.Metric, len(baseLabels)+1)
|
durationMetric := make(model.Metric, len(baseLabels)+1)
|
||||||
|
|
||||||
healthMetric[model.MetricNameLabel] = model.LabelValue(scrapeHealthMetricName)
|
healthMetric[model.MetricNameLabel] = scrapeHealthMetricName
|
||||||
durationMetric[model.MetricNameLabel] = model.LabelValue(scrapeDurationMetricName)
|
durationMetric[model.MetricNameLabel] = scrapeDurationMetricName
|
||||||
|
|
||||||
for label, value := range baseLabels {
|
for ln, lv := range baseLabels {
|
||||||
healthMetric[label] = value
|
healthMetric[ln] = lv
|
||||||
durationMetric[label] = value
|
durationMetric[ln] = lv
|
||||||
}
|
|
||||||
|
|
||||||
healthValue := model.SampleValue(0)
|
|
||||||
if health == HealthGood {
|
|
||||||
healthValue = model.SampleValue(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ts := model.TimeFromUnixNano(timestamp.UnixNano())
|
ts := model.TimeFromUnixNano(timestamp.UnixNano())
|
||||||
|
@ -583,7 +582,7 @@ func recordScrapeHealth(
|
||||||
healthSample := &model.Sample{
|
healthSample := &model.Sample{
|
||||||
Metric: healthMetric,
|
Metric: healthMetric,
|
||||||
Timestamp: ts,
|
Timestamp: ts,
|
||||||
Value: healthValue,
|
Value: health.value(),
|
||||||
}
|
}
|
||||||
durationSample := &model.Sample{
|
durationSample := &model.Sample{
|
||||||
Metric: durationMetric,
|
Metric: durationMetric,
|
||||||
|
|
Loading…
Reference in New Issue