Skip to content

Commit 491cd91

Browse files
authored
refactor prom metric creation (#1498)
1 parent 0c55255 commit 491cd91

File tree

6 files changed

+214
-71
lines changed

6 files changed

+214
-71
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ require (
2323
github.com/go-kit/log v0.2.1
2424
github.com/grafana/regexp v0.0.0-20221123153739-15dc172cd2db
2525
github.com/prometheus/client_golang v1.20.2
26+
github.com/prometheus/client_model v0.6.1
2627
github.com/prometheus/common v0.57.0
2728
github.com/r3labs/diff/v3 v3.0.1
2829
github.com/stretchr/testify v1.9.0
2930
github.com/urfave/cli/v2 v2.27.4
31+
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948
3032
golang.org/x/sync v0.8.0
3133
gopkg.in/yaml.v2 v2.4.0
3234
)
@@ -50,7 +52,6 @@ require (
5052
github.com/kr/text v0.2.0 // indirect
5153
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
5254
github.com/pmezard/go-difflib v1.0.0 // indirect
53-
github.com/prometheus/client_model v0.6.1 // indirect
5455
github.com/prometheus/procfs v0.15.1 // indirect
5556
github.com/russross/blackfriday/v2 v2.1.0 // indirect
5657
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAh
108108
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
109109
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
110110
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
111+
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 h1:kx6Ds3MlpiUHKj7syVnbp57++8WpuKPcR5yjLBjvLEA=
112+
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
111113
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
112114
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
113115
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=

pkg/promutil/migrate.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func BuildNamespaceInfoMetrics(tagData []model.TaggedResourceResult, metrics []*
6666

6767
observedMetricLabels = recordLabelsForMetric(metricName, promLabels, observedMetricLabels)
6868
metrics = append(metrics, &PrometheusMetric{
69-
Name: &metricName,
69+
Name: metricName,
7070
Labels: promLabels,
7171
Value: 0,
7272
})
@@ -116,7 +116,7 @@ func BuildMetrics(results []model.CloudwatchMetricResult, labelsSnakeCase bool,
116116
observedMetricLabels = recordLabelsForMetric(name, promLabels, observedMetricLabels)
117117

118118
output = append(output, &PrometheusMetric{
119-
Name: &name,
119+
Name: name,
120120
Labels: promLabels,
121121
Value: exportedDatapoint,
122122
Timestamp: ts,
@@ -285,13 +285,13 @@ func EnsureLabelConsistencyAndRemoveDuplicates(metrics []*PrometheusMetric, obse
285285
output := make([]*PrometheusMetric, 0, len(metrics))
286286

287287
for _, metric := range metrics {
288-
for observedLabels := range observedMetricLabels[*metric.Name] {
288+
for observedLabels := range observedMetricLabels[metric.Name] {
289289
if _, ok := metric.Labels[observedLabels]; !ok {
290290
metric.Labels[observedLabels] = ""
291291
}
292292
}
293293

294-
metricKey := fmt.Sprintf("%s-%d", *metric.Name, prom_model.LabelsToSignature(metric.Labels))
294+
metricKey := fmt.Sprintf("%s-%d", metric.Name, prom_model.LabelsToSignature(metric.Labels))
295295
if _, exists := metricKeys[metricKey]; !exists {
296296
metricKeys[metricKey] = struct{}{}
297297
output = append(output, metric)

0 commit comments

Comments
 (0)