Skip to content

Commit

Permalink
1687 otelcol.exporter.awss3 config fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joelacrisp committed Sep 21, 2024
1 parent c438560 commit 1c693bb
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Main (unreleased)

- Update yet-another-cloudwatch-exporter from v0.60.0 vo v0.61.0: (@morremeyer)
- Fixes a bug where cloudwatch S3 metrics are reported as `0`
- Issue 1687 - otelcol.exporter.awss3 fails to configure (@cydergoth)
- Fix parsing of the Level configuration attribute in debug_metrics config block
- Ensure "optional" debug_metrics config block really is optional


### Other changes
Expand Down
17 changes: 17 additions & 0 deletions internal/component/otelcol/config/config_debug_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ const (
LevelDetailed = "detailed"
)

var levels = map[Level]bool{
LevelNone: true,
LevelBasic: true,
LevelNormal:true,
LevelDetailed: true,
}

func (l Level) Convert() (configtelemetry.Level, error) {
switch l {
case LevelNone:
Expand All @@ -34,6 +41,16 @@ func (l Level) Convert() (configtelemetry.Level, error) {
}
}

// UnmarshalText implements encoding.TextUnmarshaler for Level.
func (l *Level) UnmarshalText(text []byte) error {
alloyLevelStr := Level(text)
if _, exists := levels[alloyLevelStr]; exists {
*l = alloyLevelStr
return nil
}
return fmt.Errorf("unrecognized debug level %q", string(text))
}

// DebugMetricsArguments configures internal metrics of the components
type DebugMetricsArguments struct {
DisableHighCardinalityMetrics bool `alloy:"disable_high_cardinality_metrics,attr,optional"`
Expand Down
1 change: 1 addition & 0 deletions internal/component/otelcol/exporter/awss3/awss3.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var _ exporter.Arguments = Arguments{}
func (args *Arguments) SetToDefault() {
args.MarshalerName.SetToDefault()
args.S3Uploader.SetToDefault()
args.DebugMetrics.SetToDefault()
}

func (args Arguments) Convert() (otelcomponent.Config, error) {
Expand Down
29 changes: 29 additions & 0 deletions internal/component/otelcol/exporter/awss3/awss3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ func TestDebugMetricsConfig(t *testing.T) {
Level: otelcolCfg.LevelDetailed,
},
},
{
testName: "no_optional_debug",
agentCfg: `
s3_uploader {
s3_bucket = "test"
s3_prefix = "logs"
}
`,
expected: otelcolCfg.DebugMetricsArguments{
DisableHighCardinalityMetrics: true,
Level: otelcolCfg.LevelDetailed,
},
},
{
testName: "explicit_false",
agentCfg: `
Expand Down Expand Up @@ -63,6 +76,22 @@ func TestDebugMetricsConfig(t *testing.T) {
Level: otelcolCfg.LevelDetailed,
},
},
{
testName: "explicit_debug_level",
agentCfg: `
s3_uploader {
s3_bucket = "test"
s3_prefix = "logs"
}
debug_metrics {
level = "none"
}
`,
expected: otelcolCfg.DebugMetricsArguments{
DisableHighCardinalityMetrics: true,
Level: otelcolCfg.LevelNone,
},
},
}

for _, tc := range tests {
Expand Down

0 comments on commit 1c693bb

Please sign in to comment.