Skip to content

Commit

Permalink
add marshaler to otel prometheus receiver to avoid any failures due t…
Browse files Browse the repository at this point in the history
…o yaml tags
  • Loading branch information
movence committed Oct 11, 2024
1 parent 90ec962 commit 9cb9e35
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions receiver/prometheusreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (cfg *TargetAllocator) Validate() error {
type PromConfig promconfig.Config

var _ confmap.Unmarshaler = (*PromConfig)(nil)
var _ confmap.Marshaler = (*PromConfig)(nil)

func (cfg *PromConfig) Unmarshal(componentParser *confmap.Conf) error {
cfgMap := componentParser.ToStringMap()
Expand All @@ -83,6 +84,20 @@ func (cfg *PromConfig) Unmarshal(componentParser *confmap.Conf) error {
return unmarshalYAML(cfgMap, (*promconfig.Config)(cfg))
}

func (cfg PromConfig) Marshal(componentParser *confmap.Conf) error {
yamlOut, err := yaml.Marshal(cfg)
if err != nil {
return fmt.Errorf("prometheus receiver: failed to marshal config to yaml: %w", err)
}

var result map[string]any
err = yaml.UnmarshalStrict(yamlOut, &result)
if err != nil {
return fmt.Errorf("prometheus receiver: failed to unmarshal yaml to prometheus config object: %w", err)
}
return componentParser.Merge(confmap.NewFromStringMap(result))
}

func (cfg *PromConfig) Validate() error {
// Reject features that Prometheus supports but that the receiver doesn't support:
// See:
Expand Down

0 comments on commit 9cb9e35

Please sign in to comment.