-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[AGENTCFG-79] Remove usage of Viper from comp/logs/agent/config/parser.go #34427
base: main
Are you sure you want to change the base?
Changes from 9 commits
f6d99c5
66e1fb8
5767fb8
7002c49
dbdece7
d24decd
69dd42a
1c79606
48d2b50
2d162ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,15 @@ | |
package config | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/DataDog/viper" | ||
yaml "gopkg.in/yaml.v3" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We seems to have a split in the code base between v2 and v3 (108 import of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seems that we are migrating to yaml.v3, so I thought that I would get ahead of the curve: #33450 |
||
) | ||
|
||
type yamlLogsConfigsWrapper struct { | ||
Logs []*LogsConfig | ||
} | ||
|
||
// ParseJSON parses the data formatted in JSON | ||
// returns an error if the parsing failed. | ||
func ParseJSON(data []byte) ([]*LogsConfig, error) { | ||
|
@@ -24,23 +26,13 @@ func ParseJSON(data []byte) ([]*LogsConfig, error) { | |
return configs, nil | ||
} | ||
|
||
const yaml = "yaml" | ||
const logsPath = "logs" | ||
|
||
// ParseYAML parses the data formatted in YAML, | ||
// returns an error if the parsing failed. | ||
func ParseYAML(data []byte) ([]*LogsConfig, error) { | ||
var configs []*LogsConfig | ||
var err error | ||
v := viper.New() | ||
v.SetConfigType(yaml) | ||
err = v.ReadConfig(bytes.NewBuffer(data)) | ||
var yamlConfigsWrapper yamlLogsConfigsWrapper | ||
err := yaml.Unmarshal(data, &yamlConfigsWrapper) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not decode YAML logs config: %v", err) | ||
} | ||
err = v.UnmarshalKey(logsPath, &configs) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not parse YAML logs config: %v", err) | ||
} | ||
return configs, nil | ||
return yamlConfigsWrapper.Logs, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this error could also be more customer facing. could we update the log to something like:
"could not parse YAML config, please double check the yaml files"
Or whatever is supposed to use the function?