Skip to content

Commit

Permalink
[chore] [deltatocumulative]: linear histograms (open-telemetry#36486)
Browse files Browse the repository at this point in the history
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Finishes work started in
open-telemetry#35048

That PR only partially introduced a less complex processor architecture
by only using it for Sums.
Back then I was not sure of the best way to do it for multiple
datatypes, as generics seemed to introduce a lot of complexity
regardless of usage.

I since then did of a lot of perf analysis and due to the way Go works
(see gcshapes), we do not really gain anything at runtime from using
generics, given method calls are still dynamic.

This implementation uses regular Go interfaces and a good old type
switch in the hot path (ConsumeMetrics), which lowers mental complexity
quite a lot imo.

The value of the new architecture is backed up by the following
benchmark:

```
goos: linux
goarch: arm64
pkg: github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor
                 │ sums.nested │             sums.linear             │
                 │   sec/op    │   sec/op     vs base                │
Processor/sums-8   56.35µ ± 1%   39.99µ ± 1%  -29.04% (p=0.000 n=10)

                 │  sums.nested  │             sums.linear              │
                 │     B/op      │     B/op      vs base                │
Processor/sums-8   11.520Ki ± 0%   3.683Ki ± 0%  -68.03% (p=0.000 n=10)

                 │ sums.nested │            sums.linear             │
                 │  allocs/op  │ allocs/op   vs base                │
Processor/sums-8    365.0 ± 0%   260.0 ± 0%  -28.77% (p=0.000 n=10)

```

<!--Describe what testing was performed and which tests were added.-->
#### Testing

This is a refactor, existing tests pass unaltered.

<!--Describe the documentation added.-->
#### Documentation

not needed

<!--Please delete paragraphs that you did not use before submitting.-->
  • Loading branch information
sh0rez authored and chengchuanpeng committed Jan 26, 2025
1 parent 6929bf6 commit c51fded
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions processor/deltatocumulativeprocessor/internal/delta/delta.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ type Type interface {
Timestamp() pcommon.Timestamp
}

type Type interface {
pmetric.NumberDataPoint | pmetric.HistogramDataPoint | pmetric.ExponentialHistogramDataPoint

StartTimestamp() pcommon.Timestamp
Timestamp() pcommon.Timestamp
}

// AccumulateInto adds state and dp, storing the result in state
//
// state = state + dp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package telemetry // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor/internal/lineartelemetry"

import "go.opentelemetry.io/otel/attribute"

type Attributes []attribute.KeyValue

func (a *Attributes) Set(attr attribute.KeyValue) {
*a = append(*a, attr)
}

0 comments on commit c51fded

Please sign in to comment.