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

[pkg/ottl] Add support for scaling values #33246

Merged

Conversation

bacherfl
Copy link
Contributor

@bacherfl bacherfl commented May 28, 2024

Description:

Adds a Scale function to the OTTL package. This function can be applied to int/double values, as well as metrics of the following types:

  • Sum
  • Gauge
  • Histogram

Link to tracking Issue: #16214

Testing: Added Unit and E2E tests in the OTTL package. Tested manually in a sample environment with the following example configuration:

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317

processors:
  transform:
    error_mode: ignore
    metric_statements:
      - context: metric
        statements:
          - set(data_points, Scale(data_points, 10.0))

exporters:
  debug:
    verbosity: detailed
  otlphttp:
    endpoint: "######"
    headers:
      Authorization: "#####"

service:
  pipelines:
    metrics:
      receivers: [otlp]
      exporters: [otlphttp, debug]
      processors: [transform]

Documentation: Added documentation in the README describing all functions in the ottl package

Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Copy link

linux-foundation-easycla bot commented May 28, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@bacherfl bacherfl marked this pull request as ready for review May 29, 2024 07:53
@bacherfl bacherfl requested a review from a team May 29, 2024 07:53
@evan-bradley evan-bradley changed the title [processor/transform] Add support for scaling values [pkg/ottl] Add support for scaling values May 29, 2024
Copy link
Contributor

@evan-bradley evan-bradley left a comment

Choose a reason for hiding this comment

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

Thanks for taking this one on, it's looking a bit more involved than I thought at first glance.

pkg/ottl/ottlfuncs/func_scale.go Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_scale.go Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_scale.go Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/README.md Outdated Show resolved Hide resolved
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
pkg/ottl/ottlfuncs/func_scale.go Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/README.md Outdated Show resolved Hide resolved
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
pkg/ottl/ottlfuncs/README.md Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_scale.go Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_scale.go Outdated Show resolved Hide resolved

type ScaleArguments[K any] struct {
Value ottl.GetSetter[K]
Multiplier float64
Copy link
Contributor

Choose a reason for hiding this comment

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

Like @TylerHelmuth mentioned, could we add an optional parameter to adjust the unit? I think it would be nice for usability to do all scaling in one statement.

bacherfl and others added 2 commits June 19, 2024 14:49
Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
@github-actions github-actions bot added the processor/transform Transform processor label Jun 19, 2024
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
@bacherfl
Copy link
Contributor Author

@TylerHelmuth @evan-bradley Thanks for the reviews- I have made the requested changes (moved the implementation to the transformprocessor and added an optional unit parameter)

Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
.chloggen/add-scale-function.yaml Outdated Show resolved Hide resolved
pkg/ottl/e2e/e2e_test.go Outdated Show resolved Hide resolved
Comment on lines 55 to 61
if !args.Unit.IsEmpty() {
unit, err := args.Unit.Get().Get(ctx, tCtx)
if err != nil {
return nil, fmt.Errorf("could not get unit from ScaleArguments: %w", err)
}
metric.SetUnit(unit)
}
Copy link
Member

Choose a reason for hiding this comment

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

We should do this check first - if a unit is specified and we can't retrieve it we shouldnt scale the metric. Actually setting the unit can happen after the switch statement to ensure we only update the metric if we pass the error checks in the switch statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good suggestion, I have adapted the logic accordingly

bacherfl and others added 2 commits July 2, 2024 06:55
Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
@bacherfl
Copy link
Contributor Author

@TylerHelmuth can you please have another look?

bacherfl and others added 2 commits July 23, 2024 06:56
Co-authored-by: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
@TylerHelmuth TylerHelmuth merged commit 1f88246 into open-telemetry:main Jul 25, 2024
156 checks passed
@github-actions github-actions bot added this to the next release milestone Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants