-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[processor/deltatocumulative] partial linear pipeline (#35048)
**Description:** Partially introduces a highly decoupled, linear processing pipeline. Implemented as a standalone struct to make review easier, will refactor this later. Instead of overloading `Map.Store()` to do aggregation, staleness and limiting, this functionality is now explcitly handled in `ConsumeMetrics`. This highly aids readability and makes understanding this processor a lot easier, as less mental context needs to be kept. *Notes to reviewer*: See [`68dc901`](68dc901) for the main added logic. Compare `processor.go` (old, nested) to `linear.go` (new, linear) Replaces #34757 **Link to tracking Issue:** none **Testing:** This is a refactor. Existing tests were not modified and still pass **Documentation:** not needed
- Loading branch information
Showing
16 changed files
with
589 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package deltatocumulativeprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor" | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/consumer" | ||
"go.opentelemetry.io/collector/pdata/pmetric" | ||
"go.opentelemetry.io/collector/processor" | ||
) | ||
|
||
var _ processor.Metrics = Chain(nil) | ||
|
||
// Chain calls processors in series. | ||
// They must be manually setup so that their ConsumeMetrics() invoke each other | ||
type Chain []processor.Metrics | ||
|
||
func (c Chain) Capabilities() consumer.Capabilities { | ||
if len(c) == 0 { | ||
return consumer.Capabilities{} | ||
} | ||
return c[0].Capabilities() | ||
} | ||
|
||
func (c Chain) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error { | ||
if len(c) == 0 { | ||
return nil | ||
} | ||
return c[0].ConsumeMetrics(ctx, md) | ||
} | ||
|
||
func (c Chain) Shutdown(ctx context.Context) error { | ||
for _, proc := range c { | ||
if err := proc.Shutdown(ctx); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (c Chain) Start(ctx context.Context, host component.Host) error { | ||
for _, proc := range c { | ||
if err := proc.Start(ctx, host); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
processor/deltatocumulativeprocessor/internal/lineartelemetry/metrics.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// 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 ( | ||
"context" | ||
"errors" | ||
"reflect" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/metric" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor/internal/metadata" | ||
) | ||
|
||
func New(set component.TelemetrySettings) (Metrics, error) { | ||
m := Metrics{ | ||
tracked: func() int { return 0 }, | ||
} | ||
|
||
trackedCb := metadata.WithDeltatocumulativeStreamsTrackedLinearCallback(func() int64 { | ||
return int64(m.tracked()) | ||
}) | ||
|
||
telb, err := metadata.NewTelemetryBuilder(set, trackedCb) | ||
if err != nil { | ||
return Metrics{}, err | ||
} | ||
m.TelemetryBuilder = *telb | ||
|
||
return m, nil | ||
} | ||
|
||
type Metrics struct { | ||
metadata.TelemetryBuilder | ||
|
||
tracked func() int | ||
} | ||
|
||
func (m Metrics) Datapoints() Counter { | ||
return Counter{Int64Counter: m.DeltatocumulativeDatapointsLinear} | ||
} | ||
|
||
func (m *Metrics) WithTracked(streams func() int) { | ||
m.tracked = streams | ||
} | ||
|
||
func Error(msg string) attribute.KeyValue { | ||
return attribute.String("error", msg) | ||
} | ||
|
||
func Cause(err error) attribute.KeyValue { | ||
for { | ||
uw := errors.Unwrap(err) | ||
if uw == nil { | ||
break | ||
} | ||
err = uw | ||
} | ||
|
||
return Error(reflect.TypeOf(err).String()) | ||
} | ||
|
||
type Counter struct{ metric.Int64Counter } | ||
|
||
func (c Counter) Inc(ctx context.Context, attrs ...attribute.KeyValue) { | ||
c.Add(ctx, 1, metric.WithAttributes(attrs...)) | ||
} |
Oops, something went wrong.