Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/otelcol/receiver/prometheus/internal/metadata.go
5414 views
1
// Copyright The OpenTelemetry Authors
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver/internal"
16
17
import (
18
"github.com/prometheus/prometheus/model/textparse"
19
"github.com/prometheus/prometheus/scrape"
20
)
21
22
type dataPoint struct {
23
value float64
24
boundary float64
25
}
26
27
// internalMetricMetadata allows looking up metadata for internal scrape metrics
28
var internalMetricMetadata = map[string]*scrape.MetricMetadata{
29
scrapeUpMetricName: {
30
Metric: scrapeUpMetricName,
31
Type: textparse.MetricTypeGauge,
32
Help: "The scraping was successful",
33
},
34
"scrape_duration_seconds": {
35
Metric: "scrape_duration_seconds",
36
Unit: "seconds",
37
Type: textparse.MetricTypeGauge,
38
Help: "Duration of the scrape",
39
},
40
"scrape_samples_scraped": {
41
Metric: "scrape_samples_scraped",
42
Type: textparse.MetricTypeGauge,
43
Help: "The number of samples the target exposed",
44
},
45
"scrape_series_added": {
46
Metric: "scrape_series_added",
47
Type: textparse.MetricTypeGauge,
48
Help: "The approximate number of new series in this scrape",
49
},
50
"scrape_samples_post_metric_relabeling": {
51
Metric: "scrape_samples_post_metric_relabeling",
52
Type: textparse.MetricTypeGauge,
53
Help: "The number of samples remaining after metric relabeling was applied",
54
},
55
}
56
57
func metadataForMetric(metricName string, mc scrape.MetricMetadataStore) (*scrape.MetricMetadata, string) {
58
if metadata, ok := internalMetricMetadata[metricName]; ok {
59
return metadata, metricName
60
}
61
if metadata, ok := mc.GetMetadata(metricName); ok {
62
return &metadata, metricName
63
}
64
// If we didn't find metadata with the original name,
65
// try with suffixes trimmed, in-case it is a "merged" metric type.
66
normalizedName := normalizeMetricName(metricName)
67
if metadata, ok := mc.GetMetadata(normalizedName); ok {
68
if metadata.Type == textparse.MetricTypeCounter {
69
return &metadata, metricName
70
}
71
return &metadata, normalizedName
72
}
73
// Otherwise, the metric is unknown
74
return &scrape.MetricMetadata{
75
Metric: metricName,
76
Type: textparse.MetricTypeUnknown,
77
}, metricName
78
}
79
80