Skip to content

Commit

Permalink
Define OverflowLogging
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonip committed Aug 14, 2023
1 parent 4ecc44a commit 87b7d3d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
5 changes: 3 additions & 2 deletions aggregators/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,9 @@ func (a *Aggregator) getAndLogOverflowStats(hs *harvestStats, cm *aggregationpb.
hs.servicesOverflowed = hllSketchEstimate(cm.OverflowServicesEstimator)

logFunc := func(msg string, fields ...zap.Field) {
if a.cfg.OverflowLogFunc != nil {
a.cfg.OverflowLogFunc(msg, fields...)
if a.cfg.OverflowLogging.Func != nil &&
(a.cfg.OverflowLogging.AggregationInterval == 0 || a.cfg.OverflowLogging.AggregationInterval == aggIvl) {
a.cfg.OverflowLogging.Func(msg, fields...)
}
}

Expand Down
5 changes: 4 additions & 1 deletion aggregators/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,10 @@ func TestHarvestOverflowCount(t *testing.T) {
WithCombinedMetricsIDToKVs(func(id [16]byte) []attribute.KeyValue {
return []attribute.KeyValue{attribute.String("id_key", "id_value")}
}),
WithOverflowLogFunc(observedLogger.Warn),
WithOverflowLogging(OverflowLogging{
Func: observedLogger.Warn,
AggregationInterval: time.Minute,
}),
)

var batch modelpb.Batch
Expand Down
15 changes: 11 additions & 4 deletions aggregators/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ type Processor func(
aggregationIvl time.Duration,
) error

// OverflowLogging defines the logging function when overflow happens,
// and for which aggregation interval is overflow logging enabled.
type OverflowLogging struct {
Func func(msg string, fields ...zap.Field)
AggregationInterval time.Duration
}

// Config contains the required config for running the aggregator.
type Config struct {
DataDir string
Expand All @@ -48,7 +55,7 @@ type Config struct {
Meter metric.Meter
Tracer trace.Tracer
Logger *zap.Logger
OverflowLogFunc func(msg string, fields ...zap.Field)
OverflowLogging OverflowLogging
}

// Option allows configuring aggregator based on functional options.
Expand Down Expand Up @@ -175,10 +182,10 @@ func WithLogger(logger *zap.Logger) Option {
}
}

// WithOverflowLogFunc defines log function for overflow logging.
func WithOverflowLogFunc(logFunc func(msg string, fields ...zap.Field)) Option {
// WithOverflowLogging defines log function and aggregation interval for overflow logging.
func WithOverflowLogging(logging OverflowLogging) Option {
return func(c Config) Config {
c.OverflowLogFunc = logFunc
c.OverflowLogging = logging
return c
}
}
Expand Down

0 comments on commit 87b7d3d

Please sign in to comment.