-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Feature/1363: Additional configuration for JSON parser #4351
Changes from 8 commits
420dafd
c50bfc2
7f2b2a0
4db6675
885193b
674b957
e25fbed
9196488
22e28e0
6207324
dca5e99
5e22ec4
867c3a7
fa4b2f0
197c474
e2ebce0
ab3433a
8445d14
aff2697
cabf688
145c5ef
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 |
---|---|---|
|
@@ -56,6 +56,8 @@ type Config struct { | |
|
||
// TagKeys only apply to JSON data | ||
TagKeys []string | ||
// FieldKeys only apply to JSON | ||
FieldKeys []string | ||
// MetricName applies to JSON & value. This will be the name of the measurement. | ||
MetricName string | ||
|
||
|
@@ -95,8 +97,8 @@ func NewParser(config *Config) (Parser, error) { | |
var parser Parser | ||
switch config.DataFormat { | ||
case "json": | ||
parser, err = NewJSONParser(config.MetricName, | ||
config.TagKeys, config.DefaultTags) | ||
parser, err = newJSONParser(config.MetricName, | ||
config.TagKeys, config.FieldKeys, config.DefaultTags) | ||
case "value": | ||
parser, err = NewValueParser(config.MetricName, | ||
config.DataType, config.DefaultTags) | ||
|
@@ -126,6 +128,22 @@ func NewParser(config *Config) (Parser, error) { | |
return parser, err | ||
} | ||
|
||
func newJSONParser( | ||
metricName string, | ||
tagKeys []string, | ||
fieldKeys []string, | ||
defaultTags map[string]string, | ||
) (Parser, error) { | ||
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. Returning an error isn't useful here. Where it's an unexported function not matching any interface, I'd remove it, or remove the function altogether and just instantiate a 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. No error is ever returned by the new_Parser functions, but i thought i'd include it here to match the format of the rest of the parsers |
||
parser := &json.JSONParser{ | ||
MetricName: metricName, | ||
TagKeys: tagKeys, | ||
FieldKeys: fieldKeys, | ||
DefaultTags: defaultTags, | ||
} | ||
return parser, nil | ||
} | ||
|
||
//Deprecated: Use NewParser to get a JSONParser object | ||
func NewJSONParser( | ||
metricName string, | ||
tagKeys []string, | ||
|
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.
Generally we want to avoid changing exported function signatures, as it destabilizes packages. Perhaps what we could do is add a
newJSONParser
that takes different (or functional) parameters. We could then update those things that callNewJSONParser
directly to callNewParser
, which will in turn callnewJSONParser
.