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

Fix yaml unmarshaling of inlined config #596

Merged
merged 1 commit into from
Feb 19, 2024
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
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)
}
Loading