Skip to content

Commit

Permalink
Fix yaml unmarshaling of inlined config
Browse files Browse the repository at this point in the history
  • Loading branch information
jotak committed Feb 16, 2024
1 parent 18ed417 commit 2a25eb3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ type Profile struct {
// Also, currently FLP doesn't support defining more than one PromEncode stage. If this feature is added later, these global settings
// will help configuring common setting for all PromEncode stages - PromEncode settings would then act as overrides.
type MetricsSettings struct {
api.PromConnectionInfo
DisableGlobalServer bool `yaml:"disableGlobalServer,omitempty" json:"disableGlobalServer,omitempty" doc:"disabling the global metrics server makes operational metrics unavailable. If prometheus-encoding stages are defined, they need to contain their own metrics server parameters."`
Prefix string `yaml:"prefix,omitempty" json:"prefix,omitempty" doc:"prefix for names of the operational metrics"`
NoPanic bool `yaml:"noPanic,omitempty" json:"noPanic,omitempty"`
SuppressGoMetrics bool `yaml:"suppressGoMetrics,omitempty" json:"suppressGoMetrics,omitempty" doc:"filter out Go and process metrics"`
api.PromConnectionInfo `yaml:",inline"`
DisableGlobalServer bool `yaml:"disableGlobalServer,omitempty" json:"disableGlobalServer,omitempty" doc:"disabling the global metrics server makes operational metrics unavailable. If prometheus-encoding stages are defined, they need to contain their own metrics server parameters."`
Prefix string `yaml:"prefix,omitempty" json:"prefix,omitempty" doc:"prefix for names of the operational metrics"`
NoPanic bool `yaml:"noPanic,omitempty" json:"noPanic,omitempty"`
SuppressGoMetrics bool `yaml:"suppressGoMetrics,omitempty" json:"suppressGoMetrics,omitempty" doc:"filter out Go and process metrics"`
}

// PerfSettings allows setting some internal configuration parameters
Expand Down
16 changes: 16 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
package config

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
)

func TestJsonUnmarshalStrict(t *testing.T) {
Expand All @@ -39,3 +41,17 @@ func TestJsonUnmarshalStrict(t *testing.T) {
err = JsonUnmarshalStrict([]byte(msg), &actualMsg)
require.Error(t, err)
}

func TestUnmarshalInline(t *testing.T) {
cfg := `{"metricsSettings":{"port":9102,"prefix":"netobserv_"}}`
var cfs ConfigFileStruct
err := yaml.Unmarshal([]byte(cfg), &cfs)
require.NoError(t, err)
require.Equal(t, "netobserv_", cfs.MetricsSettings.Prefix)
require.Equal(t, 9102, cfs.MetricsSettings.PromConnectionInfo.Port)

err = json.Unmarshal([]byte(cfg), &cfs)
require.NoError(t, err)
require.Equal(t, "netobserv_", cfs.MetricsSettings.Prefix)
require.Equal(t, 9102, cfs.MetricsSettings.PromConnectionInfo.Port)
}

0 comments on commit 2a25eb3

Please sign in to comment.