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 all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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. If your statements are not parsing, check if you're using the metrics conversion functions via the datapoint context.", metrics.UseConvertBetweenSumAndGaugeMetricContext.ID())
}

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