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

[processor/deltatocumulative]: Sums #30707

Merged
merged 32 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
55828ea
[processor/deltatocumulative]: initial structure
sh0rez Jan 22, 2024
c88bb65
deltatocumulative: scaffold
sh0rez Nov 28, 2023
a2da277
delta: sum, guard, metadata
sh0rez Nov 28, 2023
fd61533
identity: ids for metric + series
sh0rez Nov 28, 2023
ab085e6
deltatocumulative: basic processor
sh0rez Nov 28, 2023
862eb02
deltatocumulative: primitives, sum aggregation
sh0rez Dec 10, 2023
72dc5b8
deltatocumulative: emit on interval
sh0rez Dec 11, 2023
94f0d9a
deltatocumulative: factory plumbing
sh0rez Dec 11, 2023
84f27ab
delta: use max timestamp
sh0rez Jan 18, 2024
b244cdd
processor/deltatocumulative: in-line processing
sh0rez Jan 19, 2024
e702012
processor/deltatocumulative: set go mod to 1.20
sh0rez Jan 23, 2024
a111fc7
*: forward to deltatocumulative-structure
sh0rez Jan 23, 2024
5f51197
*: forward to main
sh0rez Jan 29, 2024
da680fc
[processor/deltatocumulative] autogenerate files
sh0rez Jan 29, 2024
b15e6db
[processor/deltatocumulative] linter fixes
sh0rez Jan 29, 2024
60bdfdf
*: review feedback
sh0rez Jan 29, 2024
d42d70c
*: forward to structure
sh0rez Jan 29, 2024
0fb12dc
*: linter fixes
sh0rez Jan 29, 2024
a1d06e9
*: forward to main
sh0rez Jan 29, 2024
bd365a6
deltatocumulative: some test, benchmarks
sh0rez Feb 2, 2024
a85dff4
*: merge main to resolve conflicts
sh0rez Feb 14, 2024
b9dccf4
*: make goporto
sh0rez Feb 14, 2024
529bc03
*: forward to main
sh0rez Feb 15, 2024
722c4c7
*: addlicense
sh0rez Feb 15, 2024
fa0e044
*: lint fixes
sh0rez Feb 15, 2024
1f3df5b
deltatocumulative: changelog entry
sh0rez Feb 15, 2024
154385a
*: go mod tidy
sh0rez Feb 15, 2024
2613df9
delta: spell out times in error msgs
sh0rez Feb 15, 2024
6f214f5
delta: simplify test, add action to err
sh0rez Feb 15, 2024
957581b
deltatocumulative: add @RichieSams as CODEOWNER
sh0rez Feb 15, 2024
adc35b3
delta: fix test
sh0rez Feb 15, 2024
dc2ddd9
deltatocumulative: re-gen using latest mdatagen
sh0rez Feb 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ body:
- processor/attributes
- processor/cumulativetodelta
- processor/datadog
- processor/deltatocumulative
- processor/deltatorate
- processor/filter
- processor/groupbyattrs
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ body:
- processor/attributes
- processor/cumulativetodelta
- processor/datadog
- processor/deltatocumulative
- processor/deltatorate
- processor/filter
- processor/groupbyattrs
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/other.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ body:
- processor/attributes
- processor/cumulativetodelta
- processor/datadog
- processor/deltatocumulative
- processor/deltatorate
- processor/filter
- processor/groupbyattrs
Expand Down
1 change: 1 addition & 0 deletions processor/deltatocumulativeprocessor/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
29 changes: 29 additions & 0 deletions processor/deltatocumulativeprocessor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Delta to cumulative processor

<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Stability | [development]: metrics |
| Distributions | [contrib] |
| Warnings | [Statefulness](#warnings) |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aprocessor%2Fdeltatocumulative%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aprocessor%2Fdeltatocumulative) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aprocessor%2Fdeltatocumulative%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aprocessor%2Fdeltatocumulative) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@sh0rez](https://www.github.com/sh0rez) |

[development]: https://github.com/open-telemetry/opentelemetry-collector#development
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
<!-- end autogenerated section -->


## Description

The delta to cumulative processor (`deltatocumulativeprocessor`) converts
metrics from delta temporality to cumulative, by accumulating samples in memory.

## Configuration

``` yaml
processors:
deltatocumulative:
```

There is no further configuration required. All delta samples are converted to cumulative.
13 changes: 13 additions & 0 deletions processor/deltatocumulativeprocessor/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package deltatocumulativeprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor"

import (
"go.opentelemetry.io/collector/component"
)

var _ component.ConfigValidator = (*Config)(nil)

type Config struct{}
sh0rez marked this conversation as resolved.
Show resolved Hide resolved

func (c *Config) Validate() error {
return nil
}
8 changes: 8 additions & 0 deletions processor/deltatocumulativeprocessor/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:generate mdatagen metadata.yaml

// package deltatocumulativeprocessor implements a processor which
// converts metrics from delta temporality to cumulative.
package deltatocumulativeprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor"
32 changes: 32 additions & 0 deletions processor/deltatocumulativeprocessor/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package deltatocumulativeprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor"

import (
"context"
"fmt"

"github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor/internal/metadata"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/processor"
)

func NewFactory() processor.Factory {
return processor.NewFactory(
metadata.Type,
createDefaultConfig,
processor.WithMetrics(createMetricsProcessor, metadata.MetricsStability),
)
}

func createDefaultConfig() component.Config {
return &Config{}
}

func createMetricsProcessor(ctx context.Context, set processor.CreateSettings, cfg component.Config, next consumer.Metrics) (processor.Metrics, error) {
pcfg, ok := cfg.(*Config)
if !ok {
return nil, fmt.Errorf("configuration parsing error")
}

return newProcessor(pcfg, set.Logger, next), nil
}
43 changes: 43 additions & 0 deletions processor/deltatocumulativeprocessor/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor

go 1.20

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil => ../../pkg/pdatautil
sh0rez marked this conversation as resolved.
Show resolved Hide resolved

require (
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.0.0-00010101000000-000000000000
go.opentelemetry.io/collector/component v0.92.0
go.opentelemetry.io/collector/consumer v0.92.0
go.opentelemetry.io/collector/pdata v1.0.2-0.20240117180253-4371e14440ee
go.opentelemetry.io/collector/processor v0.92.0
go.opentelemetry.io/otel/metric v1.22.0
go.opentelemetry.io/otel/trace v1.22.0
go.uber.org/zap v1.26.0
)

require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.0.1 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.92.0 // indirect
go.opentelemetry.io/collector/confmap v0.92.0 // indirect
go.opentelemetry.io/collector/featuregate v1.0.1 // indirect
go.opentelemetry.io/otel v1.22.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/protobuf v1.32.0 // indirect
)
110 changes: 110 additions & 0 deletions processor/deltatocumulativeprocessor/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions processor/deltatocumulativeprocessor/internal/data/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package data

import "go.opentelemetry.io/collector/pdata/pmetric"

func (dp Number) Add(in Number) Number {
switch in.ValueType() {
case pmetric.NumberDataPointValueTypeDouble:
v := dp.DoubleValue() + in.DoubleValue()
dp.SetDoubleValue(v)
case pmetric.NumberDataPointValueTypeInt:
v := dp.IntValue() + in.IntValue()
dp.SetIntValue(v)
}
dp.SetTimestamp(in.Timestamp())
return dp
}

func (dp Histogram) Add(in Histogram) Histogram {
panic("todo")
}

func (dp ExpHistogram) Add(in ExpHistogram) ExpHistogram {
panic("todo")
}
74 changes: 74 additions & 0 deletions processor/deltatocumulativeprocessor/internal/data/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package data

import (
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
)

type Point[Self any] interface {
StartTimestamp() pcommon.Timestamp
Timestamp() pcommon.Timestamp
Attributes() pcommon.Map

Clone() Self
CopyTo(Self)

Add(Self) Self
}

type Number struct {
pmetric.NumberDataPoint
}

func (dp Number) Clone() Number {
new := Number{NumberDataPoint: pmetric.NewNumberDataPoint()}
sh0rez marked this conversation as resolved.
Show resolved Hide resolved
if dp.NumberDataPoint != (pmetric.NumberDataPoint{}) {
dp.CopyTo(new)
}
return new
}

func (dp Number) CopyTo(dst Number) {
dp.NumberDataPoint.CopyTo(dst.NumberDataPoint)
}

type Histogram struct {
pmetric.HistogramDataPoint
}

func (dp Histogram) Clone() Histogram {
new := Histogram{HistogramDataPoint: pmetric.NewHistogramDataPoint()}
if dp.HistogramDataPoint != (pmetric.HistogramDataPoint{}) {
dp.CopyTo(new)
}
return new
}

func (dp Histogram) CopyTo(dst Histogram) {
dp.HistogramDataPoint.CopyTo(dst.HistogramDataPoint)
}

type ExpHistogram struct {
pmetric.ExponentialHistogramDataPoint
}

func (dp ExpHistogram) Clone() ExpHistogram {
new := ExpHistogram{ExponentialHistogramDataPoint: pmetric.NewExponentialHistogramDataPoint()}
if dp.ExponentialHistogramDataPoint != (pmetric.ExponentialHistogramDataPoint{}) {
dp.CopyTo(new)
}
return new
}

func (dp ExpHistogram) CopyTo(dst ExpHistogram) {
dp.ExponentialHistogramDataPoint.CopyTo(dst.ExponentialHistogramDataPoint)
}


type mustPoint[D Point[D]] struct{ dp D }

var (
sh0rez marked this conversation as resolved.
Show resolved Hide resolved
_ = mustPoint[Number]{}
_ = mustPoint[Histogram]{}
_ = mustPoint[ExpHistogram]{}
)
Loading