Skip to content

Commit

Permalink
Making active series custom tracker configs marshalable for runtime c… (
Browse files Browse the repository at this point in the history
#2065)

* Making active series custom tracker configs marshalable for runtime config

* Adding unit test
  • Loading branch information
gubjanos authored Jun 10, 2022
1 parent e17cb56 commit a665934
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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)
})
}

0 comments on commit a665934

Please sign in to comment.