From 5d97f17ff1fd8fdcdfed6e81588dfea21a959ca9 Mon Sep 17 00:00:00 2001 From: Liam Howe Date: Tue, 30 Apr 2024 15:45:56 +0100 Subject: [PATCH] Replace MarshalYAML() with IsZero() method for Regexp Signed-off-by: Liam Howe --- model/relabel/relabel.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/model/relabel/relabel.go b/model/relabel/relabel.go index 692ed66c1..3b4249234 100644 --- a/model/relabel/relabel.go +++ b/model/relabel/relabel.go @@ -111,15 +111,6 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { return c.Validate() } -// MarshalYAML implements the yaml.Marshaler interface. -func (c Config) MarshalYAML() (interface{}, error) { - // Omit the regex if it is the default regex as it was not provided in the first place. - if c.Regex == DefaultRelabelConfig.Regex { - c.Regex.Regexp = nil - } - return c, nil -} - func (c *Config) Validate() error { if c.Action == "" { return fmt.Errorf("relabel action cannot be empty") @@ -214,6 +205,11 @@ func (re Regexp) MarshalYAML() (interface{}, error) { return nil, nil } +// IsZero implements the yaml.IsZeroer interface. +func (re Regexp) IsZero() bool { + return re.Regexp == DefaultRelabelConfig.Regex.Regexp +} + // String returns the original string used to compile the regular expression. func (re Regexp) String() string { str := re.Regexp.String()