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

Promote ConvertBetweenSumAndGaugeMetricContext feature flag to beta #34580

Merged
merged 20 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f2a8aa0
Promote ConvertBetweenSumAndGaugeMetricContext feature flag to beta
iblancasa Aug 9, 2024
13b6d6e
Merge branch 'main' into feature/34567
iblancasa Aug 9, 2024
37b240c
Change issue type
iblancasa Aug 12, 2024
4cf73eb
Merge branch 'feature/34567' of github.com:iblancasa/opentelemetry-co…
iblancasa Aug 12, 2024
3b3acbe
Merge branch 'main' into feature/34567
iblancasa Aug 12, 2024
61d30a0
Merge branch 'feature/34567' of github.com:iblancasa/opentelemetry-co…
iblancasa Aug 13, 2024
990fd9f
Merge branch 'main' into feature/34567
iblancasa Aug 13, 2024
90e0698
Add logging warning
iblancasa Aug 13, 2024
a0d2cc6
Merge branch 'feature/34567' of github.com:iblancasa/opentelemetry-co…
iblancasa Aug 13, 2024
7dd5bbd
Merge branch 'main' into feature/34567
iblancasa Aug 13, 2024
ba961e8
Update processor/transformprocessor/config.go
iblancasa Aug 14, 2024
517e977
Merge branch 'main' into feature/34567
iblancasa Aug 14, 2024
4f0e53e
Merge branch 'main' into feature/34567
iblancasa Aug 14, 2024
aa98374
Merge branch 'main' into feature/34567
iblancasa Aug 19, 2024
284fb42
Merge branch 'main' into feature/34567
iblancasa Aug 20, 2024
3efa839
Merge branch 'main' into feature/34567
iblancasa Aug 20, 2024
7be4223
Merge branch 'main' into feature/34567
iblancasa Aug 20, 2024
d36f27e
Merge branch 'main' into feature/34567
iblancasa Aug 21, 2024
f9273cd
Merge branch 'main' into feature/34567
iblancasa Aug 22, 2024
cc68622
Merge branch 'main' into feature/34567
iblancasa Aug 22, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: transformprocessor

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Promote processor.transform.ConvertBetweenSumAndGaugeMetricContext feature flag from alpha to beta"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [34567]

# (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:

# 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]
5 changes: 5 additions & 0 deletions processor/transformprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ type Config struct {
LogStatements []common.ContextStatements `mapstructure:"log_statements"`

FlattenData bool `mapstructure:"flatten_data"`
logger *zap.Logger
}

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

func (c *Config) Validate() error {
var errors error

if c.logger != nil && metrics.UseConvertBetweenSumAndGaugeMetricContext.IsEnabled() {
c.logger.Sugar().Infof("Metric conversion functions use metric context since %s is enabled", metrics.UseConvertBetweenSumAndGaugeMetricContext.ID())
iblancasa marked this conversation as resolved.
Show resolved Hide resolved
}

if len(c.TraceStatements) > 0 {
pc, err := common.NewTraceParserCollection(component.TelemetrySettings{Logger: zap.NewNop()}, common.WithSpanParser(traces.SpanFunctions()), common.WithSpanEventParser(traces.SpanEventFunctions()))
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions processor/transformprocessor/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func createMetricsProcessor(
nextConsumer consumer.Metrics,
) (processor.Metrics, error) {
oCfg := cfg.(*Config)
oCfg.logger = set.Logger

proc, err := metrics.NewProcessor(oCfg.MetricStatements, oCfg.ErrorMode, set.TelemetrySettings)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions processor/transformprocessor/internal/metrics/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottlfuncs"
)

var useConvertBetweenSumAndGaugeMetricContext = featuregate.GlobalRegistry().MustRegister(
var UseConvertBetweenSumAndGaugeMetricContext = featuregate.GlobalRegistry().MustRegister(
"processor.transform.ConvertBetweenSumAndGaugeMetricContext",
featuregate.StageAlpha,
featuregate.StageBeta,
featuregate.WithRegisterDescription("When enabled will use metric context for conversion between sum and gauge"),
)

Expand All @@ -26,7 +26,7 @@ func DataPointFunctions() map[string]ottl.Factory[ottldatapoint.TransformContext
newConvertSummaryCountValToSumFactory(),
)

if !useConvertBetweenSumAndGaugeMetricContext.IsEnabled() {
if !UseConvertBetweenSumAndGaugeMetricContext.IsEnabled() {
for _, f := range []ottl.Factory[ottldatapoint.TransformContext]{
newConvertDatapointSumToGaugeFactory(),
newConvertDatapointGaugeToSumFactory(),
Expand All @@ -53,7 +53,7 @@ func MetricFunctions() map[string]ottl.Factory[ottlmetric.TransformContext] {
newAggregateOnAttributesFactory(),
)

if useConvertBetweenSumAndGaugeMetricContext.IsEnabled() {
if UseConvertBetweenSumAndGaugeMetricContext.IsEnabled() {
for _, f := range []ottl.Factory[ottlmetric.TransformContext]{
newConvertSumToGaugeFactory(),
newConvertGaugeToSumFactory(),
Expand Down
46 changes: 36 additions & 10 deletions processor/transformprocessor/internal/metrics/functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,45 @@ import (
)

func Test_DataPointFunctions(t *testing.T) {
expected := ottlfuncs.StandardFuncs[ottldatapoint.TransformContext]()
expected["convert_sum_to_gauge"] = newConvertDatapointSumToGaugeFactory()
expected["convert_gauge_to_sum"] = newConvertDatapointGaugeToSumFactory()
expected["convert_summary_sum_val_to_sum"] = newConvertSummarySumValToSumFactory()
expected["convert_summary_count_val_to_sum"] = newConvertSummaryCountValToSumFactory()
type testCase struct {
name string
flagEnabled bool
}

actual := DataPointFunctions()
tests := []testCase{
{
name: "ConvertBetweenSumAndGaugeMetricContextEnabled enabled",
flagEnabled: true,
},
{
name: "ConvertBetweenSumAndGaugeMetricContextEnabled disabled",
flagEnabled: false,
},
}

require.Equal(t, len(expected), len(actual))
for k := range actual {
assert.Contains(t, expected, k)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defer testutil.SetFeatureGateForTest(t, UseConvertBetweenSumAndGaugeMetricContext, tt.flagEnabled)()

expected := ottlfuncs.StandardFuncs[ottldatapoint.TransformContext]()
expected["convert_summary_sum_val_to_sum"] = newConvertSummarySumValToSumFactory()
expected["convert_summary_count_val_to_sum"] = newConvertSummaryCountValToSumFactory()

if !tt.flagEnabled {
expected["convert_sum_to_gauge"] = newConvertDatapointSumToGaugeFactory()
expected["convert_gauge_to_sum"] = newConvertDatapointGaugeToSumFactory()
}

actual := DataPointFunctions()

require.Equal(t, len(expected), len(actual))
for k := range actual {
assert.Contains(t, expected, k)
}
},
)
}

}

func Test_MetricFunctions(t *testing.T) {
Expand All @@ -40,7 +67,6 @@ func Test_MetricFunctions(t *testing.T) {
expected["copy_metric"] = newCopyMetricFactory()
expected["scale_metric"] = newScaleMetricFactory()

defer testutil.SetFeatureGateForTest(t, useConvertBetweenSumAndGaugeMetricContext, true)()
actual := MetricFunctions()
require.Equal(t, len(expected), len(actual))
for k := range actual {
Expand Down