Skip to content

Commit

Permalink
[exporter/awsemf] Add feature gate for default dimension rollup (#24274)
Browse files Browse the repository at this point in the history
**Description:** Add feature gate to change default
DimensionRollupOption. This was introduced as a feature gate since it
will be a breaking change when switching to Beta.

**Link to tracking Issue:** #23997

**Testing:** Added unit tests

**Documentation:** Updated readme.

---------

Co-authored-by: Antoine Toulme <[email protected]>
Co-authored-by: Anthony Mirabella <[email protected]>
Co-authored-by: Tyler Helmuth <[email protected]>
  • Loading branch information
4 people authored Aug 4, 2023
1 parent 29f6acf commit d18d6f2
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 7 deletions.
22 changes: 22 additions & 0 deletions .chloggen/awsemf_defaultrollup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

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

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add awsemf.nodimrollupdefault feature gate to aws emf exporter

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

# (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: |
Enabling the awsemf.nodimrollupdefault will cause the AWS EMF Exporter to use the NoDimensionRollup configuration
setting by default instead of ZeroAndSingleDimensionRollup.
8 changes: 4 additions & 4 deletions exporter/awsemfexporter/README.md

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions exporter/awsemfexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/featuregate"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter/internal/metadata"
Expand Down Expand Up @@ -260,3 +261,12 @@ func TestValidateTags(t *testing.T) {
})
}
}

func TestNoDimensionRollupFeatureGate(t *testing.T) {
err := featuregate.GlobalRegistry().Set("awsemf.nodimrollupdefault", true)
require.NoError(t, err)
cfg := createDefaultConfig()

assert.Equal(t, cfg.(*Config).DimensionRollupOption, "NoDimensionRollup")
_ = featuregate.GlobalRegistry().Set("awsemf.nodimrollupdefault", false)
}
4 changes: 4 additions & 0 deletions exporter/awsemfexporter/emf_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func newEmfExporter(config *Config, set exporter.CreateSettings) (*emfExporter,
pusherMap: map[cwlogs.PusherKey]cwlogs.Pusher{},
}

config.logger.Warn("the default value for DimensionRollupOption will be changing to NoDimensionRollup" +
"in a future release. See https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/23997 for more" +
"information")

return emfExporter, nil
}

Expand Down
8 changes: 7 additions & 1 deletion exporter/awsemfexporter/emf_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,12 @@ func TestNewExporterWithMetricDeclarations(t *testing.T) {

// Test output warning logs
expectedLogs := []observer.LoggedEntry{
{
Entry: zapcore.Entry{Level: zap.WarnLevel, Message: "the default value for DimensionRollupOption will be changing to NoDimensionRollup" +
"in a future release. See https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/23997 for more" +
"information"},
Context: []zapcore.Field{},
},
{
Entry: zapcore.Entry{Level: zap.WarnLevel, Message: "Dropped metric declaration."},
Context: []zapcore.Field{zap.Error(errors.New("invalid metric declaration: no metric name selectors defined"))},
Expand All @@ -598,7 +604,7 @@ func TestNewExporterWithMetricDeclarations(t *testing.T) {
Context: []zapcore.Field{zap.String("dimensions", "a,b,c,d,e,f,g,h,i,j,k")},
},
}
assert.Equal(t, 2, logs.Len())
assert.Equal(t, len(expectedLogs), logs.Len())
assert.Equal(t, expectedLogs, logs.AllUntimed())
}

Expand Down
14 changes: 13 additions & 1 deletion exporter/awsemfexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/featuregate"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry"
)

var defaultNoRollupfg = featuregate.GlobalRegistry().MustRegister("awsemf.nodimrollupdefault", featuregate.StageAlpha,
featuregate.WithRegisterFromVersion("v0.83.0"),
featuregate.WithRegisterDescription("Changes the default AWS EMF Exporter Dimension rollup option to "+
"NoDimensionRollup"))

// NewFactory creates a factory for AWS EMF exporter.
func NewFactory() exporter.Factory {
return exporter.NewFactory(
Expand All @@ -26,12 +32,18 @@ func NewFactory() exporter.Factory {

// CreateDefaultConfig creates the default configuration for exporter.
func createDefaultConfig() component.Config {
var defaultDimensionRollupOption string
if defaultNoRollupfg.IsEnabled() {
defaultDimensionRollupOption = "NoDimensionRollup"
} else {
defaultDimensionRollupOption = "ZeroAndSingleDimensionRollup"
}
return &Config{
AWSSessionSettings: awsutil.CreateDefaultSessionConfig(),
LogGroupName: "",
LogStreamName: "",
Namespace: "",
DimensionRollupOption: "ZeroAndSingleDimensionRollup",
DimensionRollupOption: defaultDimensionRollupOption,
Version: "1",
RetainInitialValueOfDeltaMetric: false,
OutputDestination: "cloudwatch",
Expand Down
2 changes: 1 addition & 1 deletion exporter/awsemfexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
go.opentelemetry.io/collector/confmap v0.82.0
go.opentelemetry.io/collector/consumer v0.82.0
go.opentelemetry.io/collector/exporter v0.82.0
go.opentelemetry.io/collector/featuregate v1.0.0-rcv0014
go.opentelemetry.io/collector/pdata v1.0.0-rcv0014
go.opentelemetry.io/collector/semconv v0.82.0
go.uber.org/zap v1.25.0
Expand Down Expand Up @@ -45,7 +46,6 @@ require (
go.opentelemetry.io/collector v0.82.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.82.0 // indirect
go.opentelemetry.io/collector/extension v0.82.0 // indirect
go.opentelemetry.io/collector/featuregate v1.0.0-rcv0014 // indirect
go.opentelemetry.io/collector/processor v0.82.0 // indirect
go.opentelemetry.io/collector/receiver v0.82.0 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
Expand Down

0 comments on commit d18d6f2

Please sign in to comment.