Skip to content

Commit

Permalink
fix for integrations v2 masrhaling multiplexes (#6284)
Browse files Browse the repository at this point in the history
* fix for integrations v2 marshaling multiplexes

Signed-off-by: erikbaranowski <[email protected]>

* Update pkg/integrations/v2/register.go

Co-authored-by: Robert Fratto <[email protected]>

---------

Signed-off-by: erikbaranowski <[email protected]>
Co-authored-by: Robert Fratto <[email protected]>
  • Loading branch information
erikbaranowski and rfratto authored Feb 1, 2024
1 parent 73253f7 commit 755e1b7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ Main (unreleased)
- Fix an issue where blocks having the same type and the same label across
modules could result in missed updates. (@thampiotr)

- Fix an issue with static integrations-next marshaling where non singletons
would cause `/-/config` to fail to marshal. (@erikbaranowski)

### Other changes

- Removed support for Windows 2012 in line with Microsoft end of life. (@mattdurham)
Expand Down
2 changes: 1 addition & 1 deletion pkg/integrations/v2/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func MarshalYAML(v interface{}) (interface{}, error) {
panic(fmt.Sprintf("config not registered: %T", data))
}

if _, exists := uniqueSingletons[fieldName]; exists {
if _, exists := uniqueSingletons[fieldName]; exists && integrationType == TypeSingleton {
return nil, fmt.Errorf("integration %q may not be defined more than once", fieldName)
}
uniqueSingletons[fieldName] = struct{}{}
Expand Down
33 changes: 33 additions & 0 deletions pkg/integrations/v2/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,39 @@ func TestIntegrationRegistration_Marshal_MultipleSingleton(t *testing.T) {
require.EqualError(t, err, `integration "test" may not be defined more than once`)
}

func TestIntegrationRegistration_Marshal_Multiplex(t *testing.T) {
setRegistered(t, map[Config]Type{
&testIntegrationA{}: TypeMultiplex,
&testIntegrationB{}: TypeMultiplex,
})

// Generate an invalid config, which has two instances of a Singleton
// integration.
input := testFullConfig{
Name: "John Doe",
Duration: 500 * time.Millisecond,
Default: 12345,
Configs: []Config{
&testIntegrationA{Text: "Hello, world!", Truth: true},
&testIntegrationA{Text: "Hello again!", Truth: true},
},
}

expectedCfg := `name: John Doe
duration: 500ms
default: 12345
test_configs:
- text: Hello, world!
truth: true
- text: Hello again!
truth: true
`

cfg, err := yaml.Marshal(&input)
require.NoError(t, err)
require.Equal(t, expectedCfg, string(cfg))
}

type legacyConfig struct {
Text string `yaml:"text"`
}
Expand Down

0 comments on commit 755e1b7

Please sign in to comment.