-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[processor/deltatocumulative]: explicit-bounds histograms #33983
Changes from all commits
8a2928b
3b5ad77
8fcb5f0
8e4af9d
1455f98
b89bee5
79f0ce1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: deltatocumulative | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: explicit-bounds histograms | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [30705] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | ||
implements aggregation of explicit-bounds (traditional) histograms. | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [user] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"go.opentelemetry.io/collector/pdata/pmetric" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor/internal/data/expo" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor/internal/putil/pslice" | ||
) | ||
|
||
func (dp Number) Add(in Number) Number { | ||
|
@@ -24,9 +25,44 @@ func (dp Number) Add(in Number) Number { | |
return dp | ||
} | ||
|
||
// nolint | ||
func (dp Histogram) Add(in Histogram) Histogram { | ||
panic("todo") | ||
// bounds different: no way to merge, so reset observation to new boundaries | ||
if !pslice.Equal(dp.ExplicitBounds(), in.ExplicitBounds()) { | ||
in.MoveTo(dp.HistogramDataPoint) | ||
return dp | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to do the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are! the code I think you talk about is in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahhh. that's why I missed it :) |
||
// spec requires len(BucketCounts) == len(ExplicitBounds)+1. | ||
// given we have limited error handling at this stage (and already verified boundaries are correct), | ||
// doing a best-effort add of whatever we have appears reasonable. | ||
n := min(dp.BucketCounts().Len(), in.BucketCounts().Len()) | ||
for i := 0; i < n; i++ { | ||
sum := dp.BucketCounts().At(i) + in.BucketCounts().At(i) | ||
dp.BucketCounts().SetAt(i, sum) | ||
} | ||
|
||
dp.SetTimestamp(in.Timestamp()) | ||
dp.SetCount(dp.Count() + in.Count()) | ||
|
||
if dp.HasSum() && in.HasSum() { | ||
dp.SetSum(dp.Sum() + in.Sum()) | ||
} else { | ||
dp.RemoveSum() | ||
} | ||
|
||
if dp.HasMin() && in.HasMin() { | ||
dp.SetMin(math.Min(dp.Min(), in.Min())) | ||
} else { | ||
dp.RemoveMin() | ||
} | ||
|
||
if dp.HasMax() && in.HasMax() { | ||
dp.SetMax(math.Max(dp.Max(), in.Max())) | ||
} else { | ||
dp.RemoveMax() | ||
} | ||
|
||
return dp | ||
} | ||
|
||
func (dp ExpHistogram) Add(in ExpHistogram) ExpHistogram { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package compare // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor/internal/data/datatest/compare" | ||
|
||
import ( | ||
"reflect" | ||
"strings" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
) | ||
|
||
var Opts = []cmp.Option{ | ||
cmpopts.EquateApprox(0, 1e-9), | ||
cmp.Exporter(func(ty reflect.Type) bool { | ||
return strings.HasPrefix(ty.PkgPath(), "go.opentelemetry.io/collector/pdata") | ||
}), | ||
} | ||
|
||
func Equal[T any](a, b T) bool { | ||
return cmp.Equal(a, b, Opts...) | ||
} | ||
|
||
func Diff[T any](a, b T) string { | ||
return cmp.Diff(a, b, Opts...) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a metric for how often this occurs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sgtm, but will do later as we don't have a good way of accessing a
Meter
here without refactoring thetelemetry
package