Skip to content

Commit

Permalink
Emit row size metrics (#6683)
Browse files Browse the repository at this point in the history
  • Loading branch information
tubignat authored Feb 24, 2025
1 parent df2683f commit 6859e4f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 8 additions & 0 deletions common/metrics/defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2108,6 +2108,7 @@ const (
PersistenceErrDBUnavailableCounter
PersistenceSampledCounter
PersistenceEmptyResponseCounter
PersistenceResponseRowSize

PersistenceRequestsPerDomain
PersistenceRequestsPerShard
Expand Down Expand Up @@ -2810,6 +2811,7 @@ var MetricDefs = map[ServiceIdx]map[int]metricDefinition{
PersistenceErrDBUnavailableCounter: {metricName: "persistence_errors_db_unavailable", metricType: Counter},
PersistenceSampledCounter: {metricName: "persistence_sampled", metricType: Counter},
PersistenceEmptyResponseCounter: {metricName: "persistence_empty_response", metricType: Counter},
PersistenceResponseRowSize: {metricName: "persistence_response_row_size", metricType: Histogram, buckets: ResponseRowSizeBuckets},
PersistenceRequestsPerDomain: {metricName: "persistence_requests_per_domain", metricRollupName: "persistence_requests", metricType: Counter},
PersistenceRequestsPerShard: {metricName: "persistence_requests_per_shard", metricType: Counter},
PersistenceFailuresPerDomain: {metricName: "persistence_errors_per_domain", metricRollupName: "persistence_errors", metricType: Counter},
Expand Down Expand Up @@ -3524,6 +3526,12 @@ var GlobalRatelimiterUsageHistogram = append(
tally.MustMakeExponentialValueBuckets(1, 2, 17)..., // 1..65536
)

// ResponseRowSizeBuckets contains buckets for tracking how many rows are returned per persistence operation
var ResponseRowSizeBuckets = append(
tally.ValueBuckets{0}, // need an explicit 0 or zero is reported as 1
tally.MustMakeExponentialValueBuckets(1, 2, 17)..., // 1..65536
)

// ErrorClass is an enum to help with classifying SLA vs. non-SLA errors (SLA = "service level agreement")
type ErrorClass uint8

Expand Down
10 changes: 8 additions & 2 deletions common/persistence/wrappers/metered/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,17 @@ func (p *base) emptyMetric(methodName string, req any, res any, err error) {
return
}

if err != nil || resLen.Len() > 0 {
if err != nil {
return
}

metricScope := p.metricClient.Scope(scope.scope, getCustomMetricTags(req)...)
metricScope.IncCounter(metrics.PersistenceEmptyResponseCounter)

if resLen.Len() == 0 {
metricScope.IncCounter(metrics.PersistenceEmptyResponseCounter)
} else {
metricScope.RecordHistogramValue(metrics.PersistenceResponseRowSize, float64(resLen.Len()))
}
}

var emptyCountedMethods = map[string]struct {
Expand Down

0 comments on commit 6859e4f

Please sign in to comment.