Skip to content

Commit

Permalink
metrics: assign histogram metric type on histogram construction
Browse files Browse the repository at this point in the history
This commit assigns prometheusgo.MetricType_HISTOGRAM to the
Metadata.MetricType on histogram construction.

Before this change, GetMetadata() was returning the
Metadata.MetricType zero value (prometheusgo.MetricType_COUNTER)
for all histograms that did not explicitly specify the
prometheusgo.MetricType_HISTOGRAM for Metadata.MetricType in
their Metadata definitions. This prevented checks on histogram
Metadata.MetricType from properly evaluating the metrics as
histograms.

Fixes cockroachdb#106448.
Fixes cockroachdb#107701.

Releaes note: None
  • Loading branch information
ericharmeling committed Aug 28, 2023
1 parent b05ca5c commit 8e79004
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/ts/catalog/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ var histogramMetricsNames = map[string]struct{}{
"kv.replica_read_batch_evaluate.latency": {},
"kv.replica_write_batch_evaluate.latency": {},
"leases.requests.latency": {},
"changefeed.nprocs_flush_nanos": {},
"changefeed.nprocs_consume_event_nanos": {},
"rebalancing.replicas.queriespersecond": {},
"rebalancing.replicas.cpunanospersecond": {},
"sql.pre_serve.mem.max": {},
}

func allInternalTSMetricsNames() []string {
Expand Down
2 changes: 2 additions & 0 deletions pkg/util/metric/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ type HistogramOptions struct {
}

func NewHistogram(opt HistogramOptions) IHistogram {
opt.Metadata.MetricType = prometheusgo.MetricType_HISTOGRAM
if hdrEnabled && opt.Mode != HistogramModePrometheus {
if opt.Mode == HistogramModePreferHdrLatency {
return NewHdrLatency(opt.Metadata, opt.Duration)
Expand Down Expand Up @@ -481,6 +482,7 @@ func NewManualWindowHistogram(
panic(err.Error())
}

meta.MetricType = prometheusgo.MetricType_HISTOGRAM
h := &ManualWindowHistogram{
Metadata: meta,
}
Expand Down
1 change: 1 addition & 0 deletions pkg/util/schedulerlatency/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func newRuntimeHistogram(metadata metric.Metadata, buckets []float64) *runtimeHi
if buckets[0] == math.Inf(-1) {
buckets = buckets[1:]
}
metadata.MetricType = prometheusgo.MetricType_HISTOGRAM
h := &runtimeHistogram{
Metadata: metadata,
// Go runtime histograms as of go1.19 are always in seconds whereas
Expand Down

0 comments on commit 8e79004

Please sign in to comment.