Skip to content

Commit

Permalink
pkg/util/metric: make v22.2 linter happy
Browse files Browse the repository at this point in the history
The v22.2 backport of #96029
experienced some linter issues that didn't occur in the original patch.

This patch fixes those linter errors.

Release note: none
  • Loading branch information
abarganier committed Feb 3, 2023
1 parent bade062 commit 5b84381
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions pkg/util/metric/hdrhistogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,24 @@ func (h *HdrHistogram) GetMetadata() Metadata {
return baseMetadata
}

// ValueAtQuantileWindowed calculates the windowed quantile value for
// this HdrHistogram.
func (h *HdrHistogram) ValueAtQuantileWindowed(q float64) float64 {
h.mu.Lock()
defer h.mu.Unlock()

return ValueAtQuantileWindowed(h.toPrometheusMetricWindowedLocked().Histogram, q)
}

// Mean calculates the cumulative mean value for this HdrHistogram.
func (h *HdrHistogram) Mean() float64 {
h.mu.Lock()
defer h.mu.Unlock()

return h.mu.cumulative.Mean()
}

// TotalSum calculates the cumulative sample sum value for this HdrHistogram.
func (h *HdrHistogram) TotalSum() float64 {
h.mu.Lock()
defer h.mu.Unlock()
Expand Down
15 changes: 11 additions & 4 deletions pkg/util/metric/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ func HdrEnabled() bool {
return hdrEnabled
}

// HistogramMode specifies which type of histogram should be preferred
// under various circumstances. See various constants for details.
type HistogramMode byte

const (
Expand All @@ -215,6 +217,8 @@ const (
HistogramModePreferHdrLatency
)

// HistogramOptions offers various configuration options available when
// creating a new Histogram.
type HistogramOptions struct {
// Metadata is the metric Metadata associated with the histogram.
Metadata Metadata
Expand All @@ -235,16 +239,17 @@ type HistogramOptions struct {
Mode HistogramMode
}

// NewHistogram creates a new IHistogram. The returned type is determined
// based on the provided HistogramOptions, and/or the value of the
// useHdrHistogramsEnvVar environment variable.
func NewHistogram(opt HistogramOptions) IHistogram {
if hdrEnabled && opt.Mode != HistogramModePrometheus {
if opt.Mode == HistogramModePreferHdrLatency {
return NewHdrLatency(opt.Metadata, opt.Duration)
} else {
return NewHdrHistogram(opt.Metadata, opt.Duration, opt.MaxVal, opt.SigFigs)
}
} else {
return newHistogram(opt.Metadata, opt.Duration, opt.Buckets)
return NewHdrHistogram(opt.Metadata, opt.Duration, opt.MaxVal, opt.SigFigs)
}
return newHistogram(opt.Metadata, opt.Duration, opt.Buckets)
}

// NewHistogram is a prometheus-backed histogram. Depending on the value of
Expand Down Expand Up @@ -307,6 +312,8 @@ type Histogram struct {
}
}

// IHistogram is the interface that all core histogram
// implementations should adhere to.
type IHistogram interface {
Iterable
PrometheusExportable
Expand Down

0 comments on commit 5b84381

Please sign in to comment.