Compare commits

...

1 Commits

11 changed files with 74 additions and 5 deletions

2
go.mod
View File

@@ -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.39.2-0.20250904092412-1913632726be
github.com/VictoriaMetrics/metricsql v0.84.7
github.com/aws/aws-sdk-go-v2 v1.37.1
github.com/aws/aws-sdk-go-v2/config v1.30.2

8
go.sum
View File

@@ -58,8 +58,10 @@ github.com/VictoriaMetrics/easyproto v0.1.4 h1:r8cNvo8o6sR4QShBXQd1bKw/VVLSQma/V
github.com/VictoriaMetrics/easyproto v0.1.4/go.mod h1:QlGlzaJnDfFd8Lk6Ci/fuLxfTo3/GThPs2KH23mv710=
github.com/VictoriaMetrics/fastcache v1.13.0 h1:AW4mheMR5Vd9FkAPUv+NH6Nhw+fmbTMGMsNAoA/+4G0=
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.39.2-0.20250904083602-75a0bd0c00ff h1:8QkUm2YSJ9+8yf7aCotsKIc87Q1TaLMcqFkU+I7ho+c=
github.com/VictoriaMetrics/metrics v1.39.2-0.20250904083602-75a0bd0c00ff/go.mod h1:XE4uudAAIRaJE614Tl5HMrtoEU6+GDZO4QTnNSsZRuA=
github.com/VictoriaMetrics/metrics v1.39.2-0.20250904092412-1913632726be h1:Ub3UGPqsXSsxQjzpJbwW3jqef403VNu+/sUPMADOenc=
github.com/VictoriaMetrics/metrics v1.39.2-0.20250904092412-1913632726be/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/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
@@ -508,6 +510,8 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/term v0.33.0 h1:NuFncQrRcaRvVmgRkvM3j/F00gWIAlcmlB8ACEKmGIg=
golang.org/x/term v0.33.0/go.mod h1:s18+ql9tYWp1IfpV9DmCtQDDSRBUjKaw9M1eAv5UeF0=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

View File

@@ -67,6 +67,11 @@ func (c *Counter) metricType() string {
return "counter"
}
func (c *Counter) display() bool {
// always display, align with `marshalTo`
return true
}
// GetOrCreateCounter returns registered counter with the given name
// or creates new counter if the registry doesn't contain counter with
// the given name.

View File

@@ -67,6 +67,11 @@ func (fc *FloatCounter) metricType() string {
return "counter"
}
func (fc *FloatCounter) display() bool {
// always display, align with `marshalTo`
return true
}
// GetOrCreateFloatCounter returns registered FloatCounter with the given name
// or creates new FloatCounter if the registry doesn't contain FloatCounter with
// the given name.

View File

@@ -101,6 +101,11 @@ func (g *Gauge) metricType() string {
return "gauge"
}
func (g *Gauge) display() bool {
// always display, align with `marshalTo`
return true
}
// GetOrCreateGauge returns registered gauge with the given name
// or creates new gauge if the registry doesn't contain gauge with
// the given name.

View File

@@ -268,3 +268,15 @@ func (h *Histogram) getSum() float64 {
func (h *Histogram) metricType() string {
return "histogram"
}
func (h *Histogram) display() bool {
// display if buckets contain at least 1 sample, align with `marshalTo`
countTotal := uint64(0)
h.VisitNonZeroBuckets(func(_ string, count uint64) {
countTotal += count
})
if countTotal == 0 {
return false
}
return true
}

View File

@@ -31,6 +31,9 @@ type namedMetric struct {
type metric interface {
marshalTo(prefix string, w io.Writer)
metricType() string
// display: Whether this metric will be printed. it's based on whether sample is recorded.
// It should align with `marshalTo` of each metrics type.
display() bool
}
var defaultSet = NewSet()

View File

@@ -271,3 +271,8 @@ func (h *PrometheusHistogram) marshalTo(prefix string, w io.Writer) {
func (h *PrometheusHistogram) metricType() string {
return "histogram"
}
func (h *PrometheusHistogram) display() bool {
// always display, align with `marshalTo`
return true
}

View File

@@ -52,6 +52,12 @@ func (s *Set) WritePrometheus(w io.Writer) {
prevMetricFamily := ""
for _, nm := range sa {
if !nm.metric.display() {
// For histogram and summary, the metric will not be printed if no sample recorded,
// and we can skip the rest operation such as metadata print.
// For other metrics type, they'll always be printed.
continue
}
metricFamily := getMetricFamily(nm.name)
if metricFamily != prevMetricFamily {
// write meta info only once per metric family

View File

@@ -123,6 +123,18 @@ func (sm *Summary) metricType() string {
return "summary"
}
func (sm *Summary) display() bool {
// display if contains at least 1 sample, align with `marshalTo`
sm.mu.Lock()
count := sm.count
sm.mu.Unlock()
if count > 0 {
return true
}
return false
}
func splitMetricName(name string) (string, string) {
n := strings.IndexByte(name, '{')
if n < 0 {
@@ -201,7 +213,19 @@ func (qv *quantileValue) marshalTo(prefix string, w io.Writer) {
}
func (qv *quantileValue) metricType() string {
return "unsupported"
return "summary"
}
func (qv *quantileValue) display() bool {
// display if not NaN
qv.sm.mu.Lock()
v := qv.sm.quantileValues[qv.idx]
qv.sm.mu.Unlock()
if !math.IsNaN(v) {
return true
}
return false
}
func addTag(name, tag string) string {

2
vendor/modules.txt vendored
View File

@@ -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.39.2-0.20250904092412-1913632726be
## explicit; go 1.18
github.com/VictoriaMetrics/metrics
# github.com/VictoriaMetrics/metricsql v0.84.7