diff --git a/deployment/docker/Makefile b/deployment/docker/Makefile index 358337f59..6cafcb412 100644 --- a/deployment/docker/Makefile +++ b/deployment/docker/Makefile @@ -6,7 +6,8 @@ ROOT_IMAGE ?= alpine:3.20.2 ROOT_IMAGE_SCRATCH ?= scratch CERTS_IMAGE := alpine:3.20.2 -GO_BUILDER_IMAGE := golang:1.22.5-alpine +GO_BUILDER_IMAGE := golang:1.20.4-alpine + BUILDER_IMAGE := local/builder:2.0.0-$(shell echo $(GO_BUILDER_IMAGE) | tr :/ __)-1 BASE_IMAGE := local/base:1.1.4-$(shell echo $(ROOT_IMAGE) | tr :/ __)-$(shell echo $(CERTS_IMAGE) | tr :/ __) DOCKER ?= docker diff --git a/go.mod b/go.mod index 1fc58ea91..3b1cfe97f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/VictoriaMetrics/VictoriaMetrics -go 1.22.5 +go 1.20 require ( cloud.google.com/go/storage v1.43.0 diff --git a/lib/prompbmarshal/util.go b/lib/prompbmarshal/util.go index eb281fed1..08ecb62c0 100644 --- a/lib/prompbmarshal/util.go +++ b/lib/prompbmarshal/util.go @@ -26,7 +26,9 @@ func (wr *WriteRequest) Reset() { // ResetTimeSeries clears all the GC references from tss and returns an empty tss ready for further use. func ResetTimeSeries(tss []TimeSeries) []TimeSeries { - clear(tss) + for i := range tss { + tss[i] = TimeSeries{} + } return tss[:0] } diff --git a/lib/promrelabel/relabel.go b/lib/promrelabel/relabel.go index 601a0297d..28c0daa46 100644 --- a/lib/promrelabel/relabel.go +++ b/lib/promrelabel/relabel.go @@ -589,7 +589,9 @@ func GetLabelByName(labels []prompbmarshal.Label, name string) *prompbmarshal.La // // This should help GC cleaning up label.Name and label.Value strings. func CleanLabels(labels []prompbmarshal.Label) { - clear(labels) + for i := range labels { + labels[i] = prompbmarshal.Label{} + } } // LabelsToString returns Prometheus string representation for the given labels. diff --git a/lib/promutils/labels.go b/lib/promutils/labels.go index 53da300f3..d19acb916 100644 --- a/lib/promutils/labels.go +++ b/lib/promutils/labels.go @@ -115,9 +115,15 @@ func (x *Labels) String() string { return bytesutil.ToUnsafeString(b) } +func cleanLabels(labels []prompbmarshal.Label) { + for i := range labels { + labels[i] = prompbmarshal.Label{} + } +} + // Reset resets x. func (x *Labels) Reset() { - clear(x.Labels) + cleanLabels(x.Labels) x.Labels = x.Labels[:0] } @@ -245,7 +251,7 @@ func (x *Labels) RemoveDuplicates() { prevName = label.Name } } - clear(labels[len(tmp):]) + cleanLabels(labels[len(tmp):]) x.Labels = tmp } @@ -261,7 +267,7 @@ func (x *Labels) RemoveMetaLabels() { } dst = append(dst, label) } - clear(src[len(dst):]) + cleanLabels(src[len(dst):]) x.Labels = dst } @@ -276,7 +282,7 @@ func (x *Labels) RemoveLabelsWithDoubleUnderscorePrefix() { } dst = append(dst, label) } - clear(src[len(dst):]) + cleanLabels(src[len(dst):]) x.Labels = dst } diff --git a/lib/promutils/labelscompressor.go b/lib/promutils/labelscompressor.go index 391b8f3c5..2f64dc86a 100644 --- a/lib/promutils/labelscompressor.go +++ b/lib/promutils/labelscompressor.go @@ -218,6 +218,8 @@ func (lm *labelsMap) moveMutableToReadOnlyLocked(pReadOnly *[]*prompbmarshal.Lab labels = append(labels, pLabel) } } - clear(lm.mutable) + for k := range lm.mutable { + delete(lm.mutable, k) + } lm.readOnly.Store(&labels) } diff --git a/lib/protoparser/opentelemetry/stream/sanitize.go b/lib/protoparser/opentelemetry/stream/sanitize.go index 6b020344c..2e0ec8bbb 100644 --- a/lib/protoparser/opentelemetry/stream/sanitize.go +++ b/lib/protoparser/opentelemetry/stream/sanitize.go @@ -2,17 +2,14 @@ package stream import ( "flag" - "slices" "strings" "github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel" "github.com/VictoriaMetrics/VictoriaMetrics/lib/protoparser/opentelemetry/pb" ) -var ( - usePrometheusNaming = flag.Bool("opentelemetry.usePrometheusNaming", false, "Whether to convert metric names and labels into Prometheus-compatible format for the metrics ingested "+ - "via OpenTelemetry protocol; see https://docs.victoriametrics.com/#sending-data-via-opentelemetry") -) +var usePrometheusNaming = flag.Bool("opentelemetry.usePrometheusNaming", false, "Whether to convert metric names and labels into Prometheus-compatible format for the metrics ingested "+ + "via OpenTelemetry protocol; see https://docs.victoriametrics.com/#sending-data-via-opentelemetry") // unitMap is obtained from https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/b8655058501bed61a06bb660869051491f46840b/pkg/translator/prometheus/normalize_name.go#L19 var unitMap = map[string]string{ @@ -91,6 +88,15 @@ func sanitizeMetricName(m *pb.Metric) string { return sanitizePrometheusMetricName(m) } +func contains(src []string, value string) bool { + for _, v := range src { + if v == value { + return true + } + } + return false +} + func sanitizePrometheusMetricName(m *pb.Metric) string { nameTokens := promrelabel.SplitMetricNameToTokens(m.Name) @@ -101,7 +107,7 @@ func sanitizePrometheusMetricName(m *pb.Metric) string { if u, ok := unitMap[mainUnit]; ok { mainUnit = u } - if mainUnit != "" && !slices.Contains(nameTokens, mainUnit) { + if mainUnit != "" && !contains(nameTokens, mainUnit) { nameTokens = append(nameTokens, mainUnit) } } @@ -112,7 +118,7 @@ func sanitizePrometheusMetricName(m *pb.Metric) string { if u, ok := perUnitMap[perUnit]; ok { perUnit = u } - if perUnit != "" && !slices.Contains(nameTokens, perUnit) { + if perUnit != "" && !contains(nameTokens, perUnit) { nameTokens = append(nameTokens, "per", perUnit) } } diff --git a/lib/protoparser/opentelemetry/stream/streamparser.go b/lib/protoparser/opentelemetry/stream/streamparser.go index f2e60a820..870e5f89f 100644 --- a/lib/protoparser/opentelemetry/stream/streamparser.go +++ b/lib/protoparser/opentelemetry/stream/streamparser.go @@ -238,7 +238,11 @@ type writeContext struct { func (wr *writeContext) reset() { wr.bb.Reset() - clear(wr.tss) + for i := range wr.tss { + ts := &wr.tss[i] + ts.Labels = nil + ts.Samples = nil + } wr.tss = wr.tss[:0] wr.baseLabels = resetLabels(wr.baseLabels) @@ -249,7 +253,9 @@ func (wr *writeContext) reset() { } func resetLabels(labels []prompbmarshal.Label) []prompbmarshal.Label { - clear(labels) + for i := range labels { + labels[i] = prompbmarshal.Label{} + } return labels[:0] }