Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions set.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ func (s *Set) WritePrometheus(w io.Writer) {
return fName1 < fName2
}

// Only summary and quantile(s) have different metric types.
// Sorting by metric type will stabilize the order for summary and quantile(s).
mType1 := s.a[i].metric.metricType()
mType2 := s.a[j].metric.metricType()
if mType1 != mType2 {
return mType1 < mType2
// if both has same family, check the auxiliary first.
// only summary quantile(s) is registered as auxiliary, and quantile(s) in summary should go first.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add comment to the isAux field in metric struct to note where and why it is used. So in future we can quickly figure out what it is for.

if s.a[i].isAux != s.a[j].isAux {
return s.a[i].isAux
}

// lastly by metric names, which is for quantiles and histogram buckets.
Expand Down
10 changes: 10 additions & 0 deletions set_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package metrics_test
import (
"bytes"
"fmt"
"time"

"github.com/VictoriaMetrics/metrics"
)
Expand Down Expand Up @@ -54,6 +55,11 @@ func ExampleExposeMetadata() {
// This summary will have quantiles printed before _sum/_count metrics
s.NewSummary(`vm_request_duration_seconds{path="/api/v1/query_range"}`).Update(1)

var testSummaryQuantilesNoop = []float64{0.5, 0.9, 0.97, 0.99, 1}
Comment thread
jiekun marked this conversation as resolved.
Outdated
testWindow := 50 * time.Millisecond
s.NewSummaryExt(`test_summary_expire_quick`, testWindow, testSummaryQuantilesNoop).Update(1)
time.Sleep(4 * testWindow)
Comment thread
jiekun marked this conversation as resolved.
Outdated

// Dump metrics from s.
var bb bytes.Buffer
s.WritePrometheus(&bb)
Expand Down Expand Up @@ -88,6 +94,10 @@ func ExampleExposeMetadata() {
// # HELP set_counter
// # TYPE set_counter counter
// set_counter 1
// # HELP test_summary_expire_quick
// # TYPE test_summary_expire_quick summary
// test_summary_expire_quick_sum 1
// test_summary_expire_quick_count 1
// # HELP unused_bytes
// # TYPE unused_bytes gauge
// unused_bytes{foo="bar"} 58
Expand Down
8 changes: 1 addition & 7 deletions summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,7 @@ func (sm *Summary) marshalTo(prefix string, w io.Writer) {
}

func (sm *Summary) metricType() string {
// this metric type should not be printed, because summary (sum and count)
// of the same metric family will be printed after quantile(s).
// If metadata is needed, the metadata from quantile(s) should be used.
// quantile will be printed first, so its metrics type won't be printed as metadata.
// Printing quantiles before sum and count aligns this code with Prometheus behavior.
// See: https://github.com/VictoriaMetrics/metrics/pull/99
return "unsupported"
return "summary"
}

func splitMetricName(name string) (string, string) {
Expand Down
Loading