perf: avoid string concatenation in loops (#7572)

* perf: avoid string concatenation in loops

Apply perfpsrint linter

Signed-off-by: Philippe Antoine <contact@catenacyber.fr>

* ci: enable perfsprint

Signed-off-by: Philippe Antoine <contact@catenacyber.fr>

---------

Signed-off-by: Philippe Antoine <contact@catenacyber.fr>
This commit is contained in:
Catena cyber
2025-10-06 09:05:58 +02:00
committed by GitHub
parent 51f94b0bb4
commit 625f6c9307
8 changed files with 36 additions and 24 deletions

View File

@@ -157,14 +157,14 @@ func newMetricFamily(dtoMF *dto.MetricFamily) *MetricFamily {
mf.Metrics[i] = summary{
Labels: makeLabels(m),
Quantiles: makeQuantiles(m),
Count: fmt.Sprint(m.GetSummary().GetSampleCount()),
Count: strconv.FormatUint(m.GetSummary().GetSampleCount(), 10),
Sum: fmt.Sprint(m.GetSummary().GetSampleSum()),
}
} else if dtoMF.GetType() == dto.MetricType_HISTOGRAM {
mf.Metrics[i] = histogram{
Labels: makeLabels(m),
Buckets: makeBuckets(m),
Count: fmt.Sprint(m.GetHistogram().GetSampleCount()),
Count: strconv.FormatUint(m.GetHistogram().GetSampleCount(), 10),
Sum: fmt.Sprint(m.GetSummary().GetSampleSum()),
}
} else {
@@ -209,7 +209,7 @@ func makeQuantiles(m *dto.Metric) map[string]string {
func makeBuckets(m *dto.Metric) map[string]string {
result := map[string]string{}
for _, b := range m.GetHistogram().GetBucket() {
result[fmt.Sprint(b.GetUpperBound())] = fmt.Sprint(b.GetCumulativeCount())
result[fmt.Sprint(b.GetUpperBound())] = strconv.FormatUint(b.GetCumulativeCount(), 10)
}
return result
}