From 367cdb089f8e10f192af9744f26caaa8503cf121 Mon Sep 17 00:00:00 2001 From: Max Kotliar Date: Fri, 12 Sep 2025 14:14:49 +0300 Subject: [PATCH] vendor: update metrics package to v1.40.1 (#9725) ### Describe Your Changes Includes fix https://github.com/VictoriaMetrics/metrics/pull/99 ### Checklist The following checks are **mandatory**: - [ ] My change adheres to [VictoriaMetrics contributing guidelines](https://docs.victoriametrics.com/victoriametrics/contributing/#pull-request-checklist). - [ ] My change adheres to [VictoriaMetrics development goals](https://docs.victoriametrics.com/victoriametrics/goals/). --- docs/victoriametrics/changelog/CHANGELOG.md | 2 + go.mod | 2 +- go.sum | 2 + .../VictoriaMetrics/metrics/metrics.go | 4 ++ .../metrics/process_metrics_linux.go | 3 +- .../github.com/VictoriaMetrics/metrics/set.go | 51 ++++++++++++++++--- .../VictoriaMetrics/metrics/summary.go | 4 ++ vendor/modules.txt | 2 +- 8 files changed, 58 insertions(+), 12 deletions(-) diff --git a/docs/victoriametrics/changelog/CHANGELOG.md b/docs/victoriametrics/changelog/CHANGELOG.md index c02bd79b46..823dac3b76 100644 --- a/docs/victoriametrics/changelog/CHANGELOG.md +++ b/docs/victoriametrics/changelog/CHANGELOG.md @@ -35,6 +35,8 @@ See also [LTS releases](https://docs.victoriametrics.com/victoriametrics/lts-rel * BUGFIX: [vmui](https://docs.victoriametrics.com/victoriametrics/single-server-victoriametrics/#vmui): properly apply rollup functions to metrics based on their name in vmui's [metrics explorer](https://docs.victoriametrics.com/victoriametrics/#metrics-explorer). See [#9655](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/9655) for details. Thanks to @wbwren-eric for the fix. * BUGFIX: all VictoriaMetrics [enterprise](https://docs.victoriametrics.com/enterprise/) components: fix support for automatic issuing of TLS certificates for HTTPS server via [Let's Encrypt service](https://letsencrypt.org/) using [TLS-ALPN-01 challenge](https://letsencrypt.org/docs/challenge-types/#tls-alpn-01). See [Automatic issuing of TLS certificates](https://docs.victoriametrics.com/victoriametrics/#automatic-issuing-of-tls-certificates) for more info. * BUGFIX: [vmui](https://docs.victoriametrics.com/victoriametrics/single-server-victoriametrics/#vmui): fix VMUI backend URL, while using multitenant API. See more in [#9703](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/9703). +* BUGFIX: all components: properly expose metadata for summaries and histograms in VictoriaMetrics components with enabled `-metrics.exposeMetadata` cmd-line flag. See [metrics#98](https://github.com/VictoriaMetrics/metrics/issues/98) for details. +* BUGFIX: all components: lower severity of the log message for unavailable [Pressure Stall Information (PSI)](https://docs.kernel.org/accounting/psi.html) metrics from `ERROR` to `INFO` level. See [#9161](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/9161) for details. ## [v1.125.1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.125.1) diff --git a/go.mod b/go.mod index 8e7b812455..5ced5eb466 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( github.com/VictoriaMetrics/VictoriaLogs v0.0.0-20250728123024-98593029b5aa github.com/VictoriaMetrics/easyproto v0.1.4 github.com/VictoriaMetrics/fastcache v1.13.0 - github.com/VictoriaMetrics/metrics v1.39.1 + github.com/VictoriaMetrics/metrics v1.40.1 github.com/VictoriaMetrics/metricsql v0.84.8 github.com/aws/aws-sdk-go-v2 v1.37.1 github.com/aws/aws-sdk-go-v2/config v1.30.2 diff --git a/go.sum b/go.sum index f258df93de..3ca1f8ea7b 100644 --- a/go.sum +++ b/go.sum @@ -60,6 +60,8 @@ github.com/VictoriaMetrics/fastcache v1.13.0 h1:AW4mheMR5Vd9FkAPUv+NH6Nhw+fmbTMG github.com/VictoriaMetrics/fastcache v1.13.0/go.mod h1:hHXhl4DA2fTL2HTZDJFXWgW0LNjo6B+4aj2Wmng3TjU= github.com/VictoriaMetrics/metrics v1.39.1 h1:AT7jz7oSpAK9phDl5O5Tmy06nXnnzALwqVnf4ros3Ow= github.com/VictoriaMetrics/metrics v1.39.1/go.mod h1:XE4uudAAIRaJE614Tl5HMrtoEU6+GDZO4QTnNSsZRuA= +github.com/VictoriaMetrics/metrics v1.40.1 h1:FrF5uJRpIVj9fayWcn8xgiI+FYsKGMslzPuOXjdeyR4= +github.com/VictoriaMetrics/metrics v1.40.1/go.mod h1:XE4uudAAIRaJE614Tl5HMrtoEU6+GDZO4QTnNSsZRuA= github.com/VictoriaMetrics/metricsql v0.84.7 h1:zMONjtEULMbwEYU/qL4Hkc3GDfTTrv1bO+a9lmJf3do= github.com/VictoriaMetrics/metricsql v0.84.7/go.mod h1:d4EisFO6ONP/HIGDYTAtwrejJBBeKGQYiRl095bS4QQ= github.com/VictoriaMetrics/metricsql v0.84.8 h1:5JXrvPJiYkYNqJVT7+hMZmpAwRHd3txBdlVIw4rJ1VM= diff --git a/vendor/github.com/VictoriaMetrics/metrics/metrics.go b/vendor/github.com/VictoriaMetrics/metrics/metrics.go index 3af670541d..fc121f81bf 100644 --- a/vendor/github.com/VictoriaMetrics/metrics/metrics.go +++ b/vendor/github.com/VictoriaMetrics/metrics/metrics.go @@ -338,6 +338,10 @@ func WriteMetadataIfNeeded(w io.Writer, metricName, metricType string) { return } metricFamily := getMetricFamily(metricName) + writeMetadata(w, metricFamily, metricType) +} + +func writeMetadata(w io.Writer, metricFamily, metricType string) { fmt.Fprintf(w, "# HELP %s\n", metricFamily) fmt.Fprintf(w, "# TYPE %s %s\n", metricFamily, metricType) } diff --git a/vendor/github.com/VictoriaMetrics/metrics/process_metrics_linux.go b/vendor/github.com/VictoriaMetrics/metrics/process_metrics_linux.go index df79a2e92a..6c07cecb69 100644 --- a/vendor/github.com/VictoriaMetrics/metrics/process_metrics_linux.go +++ b/vendor/github.com/VictoriaMetrics/metrics/process_metrics_linux.go @@ -240,7 +240,6 @@ func writeProcessMemMetrics(w io.Writer) { WriteGaugeUint64(w, "process_resident_memory_anon_bytes", ms.rssAnon) WriteGaugeUint64(w, "process_resident_memory_file_bytes", ms.rssFile) WriteGaugeUint64(w, "process_resident_memory_shared_bytes", ms.rssShmem) - } func getMemStats(path string) (*memStats, error) { @@ -321,7 +320,7 @@ func psiTotalSecs(microsecs uint64) float64 { var psiMetricsStart = func() *psiMetrics { m, err := getPSIMetrics() if err != nil { - log.Printf("ERROR: metrics: disable exposing PSI metrics because of failed init: %s", err) + log.Printf("INFO: metrics: disable exposing PSI metrics because of failed init: %s", err) return nil } return m diff --git a/vendor/github.com/VictoriaMetrics/metrics/set.go b/vendor/github.com/VictoriaMetrics/metrics/set.go index 31f9f69cac..ffe7b9fcab 100644 --- a/vendor/github.com/VictoriaMetrics/metrics/set.go +++ b/vendor/github.com/VictoriaMetrics/metrics/set.go @@ -37,6 +37,25 @@ func (s *Set) WritePrometheus(w io.Writer) { // Collect all the metrics in in-memory buffer in order to prevent from long locking due to slow w. var bb bytes.Buffer lessFunc := func(i, j int) bool { + // the sorting must be stable. + // see edge cases why we can't simply do `s.a[i].name < s.a[j].name` here: + // https://github.com/VictoriaMetrics/metrics/pull/99#issuecomment-3277072175 + + // sort by metric family name first, to group the same metric family in one place. + fName1, fName2 := getMetricFamily(s.a[i].name), getMetricFamily(s.a[j].name) + if fName1 != fName2 { + return fName1 < fName2 + } + + mType1 := s.a[i].metric.metricType() + mType2 := s.a[j].metric.metricType() + + // stabilize the order for summary and quantiles. + if mType1 != mType2 { + return mType1 < mType2 + } + + // lastly by metric names, which is for quantiles and histogram buckets. return s.a[i].name < s.a[j].name } s.mu.Lock() @@ -50,18 +69,34 @@ func (s *Set) WritePrometheus(w io.Writer) { metricsWriters := s.metricsWriters s.mu.Unlock() - prevMetricFamily := "" + // metricsWithMetadataBuf is used to hold marshalTo temporary, and decide whether metadata is needed. + // it will be written to `bb` at the end and then reset for next *namedMetric in for-loop. + var metricsWithMetadataBuf bytes.Buffer + var prevMetricFamily string for _, nm := range sa { - metricFamily := getMetricFamily(nm.name) - if metricFamily != prevMetricFamily { - // write meta info only once per metric family - metricType := nm.metric.metricType() - WriteMetadataIfNeeded(&bb, nm.name, metricType) - prevMetricFamily = metricFamily + if !isMetadataEnabled() { + // Call marshalTo without the global lock, since certain metric types such as Gauge + // can call a callback, which, in turn, can try calling s.mu.Lock again. + nm.metric.marshalTo(nm.name, &bb) + continue } + + metricsWithMetadataBuf.Reset() // Call marshalTo without the global lock, since certain metric types such as Gauge // can call a callback, which, in turn, can try calling s.mu.Lock again. - nm.metric.marshalTo(nm.name, &bb) + nm.metric.marshalTo(nm.name, &metricsWithMetadataBuf) + if metricsWithMetadataBuf.Len() == 0 { + continue + } + + metricFamily := getMetricFamily(nm.name) + if metricFamily != prevMetricFamily { + // write metadata only once per metric family + metricType := nm.metric.metricType() + writeMetadata(&bb, metricFamily, metricType) + prevMetricFamily = metricFamily + } + bb.Write(metricsWithMetadataBuf.Bytes()) } w.Write(bb.Bytes()) diff --git a/vendor/github.com/VictoriaMetrics/metrics/summary.go b/vendor/github.com/VictoriaMetrics/metrics/summary.go index 0469b98348..1b62988bba 100644 --- a/vendor/github.com/VictoriaMetrics/metrics/summary.go +++ b/vendor/github.com/VictoriaMetrics/metrics/summary.go @@ -201,6 +201,10 @@ func (qv *quantileValue) marshalTo(prefix string, w io.Writer) { } func (qv *quantileValue) metricType() string { + // this metricsType should not be printed, because summary (sum and count) of the same metric family will be printed first, + // and if metadata is needed, the metadata from summary should be used. + // quantile will be printed later, so its metrics type won't be printed as metadata. + // See: https://github.com/VictoriaMetrics/metrics/pull/99 return "unsupported" } diff --git a/vendor/modules.txt b/vendor/modules.txt index 7eda41bd7f..747ee9810d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -139,7 +139,7 @@ github.com/VictoriaMetrics/easyproto # github.com/VictoriaMetrics/fastcache v1.13.0 ## explicit; go 1.24.0 github.com/VictoriaMetrics/fastcache -# github.com/VictoriaMetrics/metrics v1.39.1 +# github.com/VictoriaMetrics/metrics v1.40.1 ## explicit; go 1.18 github.com/VictoriaMetrics/metrics # github.com/VictoriaMetrics/metricsql v0.84.8