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

refactor(sdk/metrics): add histogramAggs method #2648

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions sdk/metric/selector/simple/simple.go
Expand Up @@ -65,15 +65,18 @@ func lastValueAggs(aggPtrs []*aggregator.Aggregator) {
}
}

func histogramAggs(aggPtrs []*aggregator.Aggregator,
desc *sdkapi.Descriptor, opts ...histogram.Option) {
aggs := histogram.New(len(aggPtrs), desc, opts...)
for i := range aggPtrs {
*aggPtrs[i] = &aggs[i]
}
}

func (selectorInexpensive) AggregatorFor(descriptor *sdkapi.Descriptor, aggPtrs ...*aggregator.Aggregator) {
switch descriptor.InstrumentKind() {
case sdkapi.GaugeObserverInstrumentKind:
lastValueAggs(aggPtrs)
case sdkapi.HistogramInstrumentKind:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just commenting here because it took me a few seconds to understand why this code was removed.
The sumAggs method does the same thing, so there's no need for the repetition.

aggs := sum.New(len(aggPtrs))
for i := range aggPtrs {
*aggPtrs[i] = &aggs[i]
}
default:
sumAggs(aggPtrs)
}
Expand All @@ -84,10 +87,7 @@ func (s selectorHistogram) AggregatorFor(descriptor *sdkapi.Descriptor, aggPtrs
case sdkapi.GaugeObserverInstrumentKind:
lastValueAggs(aggPtrs)
case sdkapi.HistogramInstrumentKind:
aggs := histogram.New(len(aggPtrs), descriptor, s.options...)
for i := range aggPtrs {
*aggPtrs[i] = &aggs[i]
}
histogramAggs(aggPtrs, descriptor, s.options...)
default:
sumAggs(aggPtrs)
}
Expand Down