Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metrics framework #926

Merged
merged 20 commits into from
Nov 26, 2024
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
Prev Previous commit
Next Next commit
Got latency metrics working.
Signed-off-by: Cody Littley <cody@eigenlabs.org>
  • Loading branch information
cody-littley committed Nov 21, 2024
commit e44484961678177a3a1f3286273c7c6a4b6f0b37
18 changes: 17 additions & 1 deletion common/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Metrics interface {
Stop() // TODO necessary?

// NewLatencyMetric creates a new LatencyMetric instance. Useful for reporting the latency of an operation.
NewLatencyMetric(name string, label string) (LatencyMetric, error)
NewLatencyMetric(name string, label string, quantiles ...*Quantile) (LatencyMetric, error)

// NewCountMetric creates a new CountMetric instance. Useful for tracking the count of a type of event.
NewCountMetric(name string, label string) (CountMetric, error)
Expand Down Expand Up @@ -51,6 +51,22 @@ type CountMetric interface {
Increment()
}

// Quantile describes a quantile of a latency metric that should be reported. For a description of how
// to interpret a quantile, see the prometheus documentation
// https://github.com/prometheus/client_golang/blob/v1.20.5/prometheus/summary.go#L126
type Quantile struct {
Quantile float64
Error float64
}

// NewQuantile creates a new Quantile instance. Error is set to 1% of the quantile.
func NewQuantile(quantile float64) *Quantile {
return &Quantile{
Quantile: quantile,
Error: quantile / 100.0,
}
}

// LatencyMetric allows the latency of an operation to be tracked. Similar to a gauge metric, but specialized for time.
type LatencyMetric interface {
Metric
Expand Down
27 changes: 18 additions & 9 deletions common/metrics/metrics_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (m *metrics) Stop() {
}

// NewLatencyMetric creates a new LatencyMetric instance.
func (m *metrics) NewLatencyMetric(name string, label string) (LatencyMetric, error) {
func (m *metrics) NewLatencyMetric(name string, label string, quantiles ...*Quantile) (LatencyMetric, error) {
m.creationLock.Lock()
defer m.creationLock.Unlock()

Expand All @@ -130,15 +130,20 @@ func (m *metrics) NewLatencyMetric(name string, label string) (LatencyMetric, er
m.metricMap[id] = metric
}

objectives := make(map[float64]float64, len(quantiles))
for _, q := range quantiles {
objectives[q.Quantile] = q.Error
}

vec, ok := m.summaryVecMap[name]
if !ok {
vec = promauto.With(m.registry).NewSummaryVec(
prometheus.SummaryOpts{
Namespace: m.config.Namespace,
Name: name,
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.95: 0.01, 0.99: 0.001}, // TODO expose this
Objectives: objectives,
},
[]string{"label"}, // TODO what is this?
[]string{"label"},
)
m.summaryVecMap[name] = vec
}
Expand Down Expand Up @@ -170,14 +175,18 @@ func (m *metrics) NewGaugeMetric(name string, label string) (GaugeMetric, error)
func (m *metrics) isBlacklisted(id metricID) bool {
metric := id.String()

for _, blacklisted := range m.config.MetricsBlacklist {
if metric == blacklisted {
return true
if m.config.MetricsBlacklist != nil {
for _, blacklisted := range m.config.MetricsBlacklist {
if metric == blacklisted {
return true
}
}
}
for _, blacklisted := range m.config.MetricsFuzzyBlacklist {
if strings.Contains(metric, blacklisted) {
return true
if m.config.MetricsFuzzyBlacklist != nil {
for _, blacklisted := range m.config.MetricsFuzzyBlacklist {
if strings.Contains(metric, blacklisted) {
return true
}
}
}
return false
Expand Down