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

Making active series custom tracker configs marshalable for runtime c… #2065

Merged
merged 2 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions pkg/ingester/activeseries/custom_trackers_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ func (c *CustomTrackersConfig) UnmarshalYAML(unmarshal func(interface{}) error)
return err
}

// MarshalYAML implements yaml.Marshaler.
func (c CustomTrackersConfig) MarshalYAML() (interface{}, error) {
return c.source, nil
}

func NewCustomTrackersConfig(m map[string]string) (c CustomTrackersConfig, err error) {
c.source = m
c.config = map[string]labelsMatchers{}
Expand Down
18 changes: 18 additions & 0 deletions pkg/ingester/activeseries/custom_trackers_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,21 @@ func TestTrackersConfigs_Deserialization(t *testing.T) {
assert.Error(t, err, "should not deserialize malformed input")
})
}

func TestTrackersConfigs_SerializeDeserialize(t *testing.T) {
sourceYAML := `
baz: "{baz='bar'}"
foo: "{foo='bar'}"
`

obj := mustNewCustomTrackersConfigDeserializedFromYaml(t, sourceYAML)

t.Run("ShouldSerializeDeserializeResultsTheSame", func(t *testing.T) {
out, err := yaml.Marshal(obj)
require.NoError(t, err, "failed do serialize Custom trackers config")
reSerialized := CustomTrackersConfig{}
err = yaml.Unmarshal(out, &reSerialized)
require.NoError(t, err, "Failed to deserialize serialized object")
assert.Equal(t, obj, reSerialized)
})
}