Support string field glob matching in json parser (#6102)
This commit is contained in:
@@ -70,7 +70,7 @@ type Config struct {
|
||||
|
||||
// TagKeys only apply to JSON data
|
||||
TagKeys []string `toml:"tag_keys"`
|
||||
// FieldKeys only apply to JSON
|
||||
// Array of glob pattern strings keys that should be added as string fields.
|
||||
JSONStringFields []string `toml:"json_string_fields"`
|
||||
|
||||
JSONNameKey string `toml:"json_name_key"`
|
||||
@@ -153,15 +153,19 @@ func NewParser(config *Config) (Parser, error) {
|
||||
var parser Parser
|
||||
switch config.DataFormat {
|
||||
case "json":
|
||||
parser = newJSONParser(config.MetricName,
|
||||
config.TagKeys,
|
||||
config.JSONNameKey,
|
||||
config.JSONStringFields,
|
||||
config.JSONQuery,
|
||||
config.JSONTimeKey,
|
||||
config.JSONTimeFormat,
|
||||
config.JSONTimezone,
|
||||
config.DefaultTags)
|
||||
parser, err = json.New(
|
||||
&json.Config{
|
||||
MetricName: config.MetricName,
|
||||
TagKeys: config.TagKeys,
|
||||
NameKey: config.JSONNameKey,
|
||||
StringFields: config.JSONStringFields,
|
||||
Query: config.JSONQuery,
|
||||
TimeKey: config.JSONTimeKey,
|
||||
TimeFormat: config.JSONTimeFormat,
|
||||
Timezone: config.JSONTimezone,
|
||||
DefaultTags: config.DefaultTags,
|
||||
},
|
||||
)
|
||||
case "value":
|
||||
parser, err = NewValueParser(config.MetricName,
|
||||
config.DataType, config.DefaultTags)
|
||||
@@ -283,31 +287,6 @@ func newCSVParser(metricName string,
|
||||
return parser, nil
|
||||
}
|
||||
|
||||
func newJSONParser(
|
||||
metricName string,
|
||||
tagKeys []string,
|
||||
jsonNameKey string,
|
||||
stringFields []string,
|
||||
jsonQuery string,
|
||||
timeKey string,
|
||||
timeFormat string,
|
||||
timezone string,
|
||||
defaultTags map[string]string,
|
||||
) Parser {
|
||||
parser := &json.JSONParser{
|
||||
MetricName: metricName,
|
||||
TagKeys: tagKeys,
|
||||
StringFields: stringFields,
|
||||
JSONNameKey: jsonNameKey,
|
||||
JSONQuery: jsonQuery,
|
||||
JSONTimeKey: timeKey,
|
||||
JSONTimeFormat: timeFormat,
|
||||
JSONTimezone: timezone,
|
||||
DefaultTags: defaultTags,
|
||||
}
|
||||
return parser
|
||||
}
|
||||
|
||||
func newGrokParser(metricName string,
|
||||
patterns []string, nPatterns []string,
|
||||
cPatterns string, cPatternFiles []string,
|
||||
@@ -326,19 +305,6 @@ func newGrokParser(metricName string,
|
||||
return &parser, err
|
||||
}
|
||||
|
||||
func NewJSONParser(
|
||||
metricName string,
|
||||
tagKeys []string,
|
||||
defaultTags map[string]string,
|
||||
) (Parser, error) {
|
||||
parser := &json.JSONParser{
|
||||
MetricName: metricName,
|
||||
TagKeys: tagKeys,
|
||||
DefaultTags: defaultTags,
|
||||
}
|
||||
return parser, nil
|
||||
}
|
||||
|
||||
func NewNagiosParser() (Parser, error) {
|
||||
return &nagios.NagiosParser{}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user