Fix dropwizard parsing error for metrics that need escaped (#4142)

If the dropwizard parser cannot convert the metric name into a valid
line protocol series then we will accept the name as is.
This commit is contained in:
Daniel Nelson
2018-05-14 11:00:03 -07:00
committed by GitHub
parent 558caf57de
commit 0af40a8a5d
10 changed files with 8949 additions and 8197 deletions

View File

@@ -26,11 +26,15 @@ type Parser interface {
// Parse takes a byte buffer separated by newlines
// ie, `cpu.usage.idle 90\ncpu.usage.busy 10`
// and parses it into telegraf metrics
//
// Must be thread-safe.
Parse(buf []byte) ([]telegraf.Metric, error)
// ParseLine takes a single string metric
// ie, "cpu.usage.idle 90"
// and parses it into a telegraf metric.
//
// Must be thread-safe.
ParseLine(line string) (telegraf.Metric, error)
// SetDefaultTags tells the parser to add all of the given tags
@@ -107,9 +111,15 @@ func NewParser(config *Config) (Parser, error) {
parser, err = NewCollectdParser(config.CollectdAuthFile,
config.CollectdSecurityLevel, config.CollectdTypesDB)
case "dropwizard":
parser, err = NewDropwizardParser(config.DropwizardMetricRegistryPath,
config.DropwizardTimePath, config.DropwizardTimeFormat, config.DropwizardTagsPath, config.DropwizardTagPathsMap, config.DefaultTags,
config.Separator, config.Templates)
parser, err = NewDropwizardParser(
config.DropwizardMetricRegistryPath,
config.DropwizardTimePath,
config.DropwizardTimeFormat,
config.DropwizardTagsPath,
config.DropwizardTagPathsMap,
config.DefaultTags,
config.Separator,
config.Templates)
default:
err = fmt.Errorf("Invalid data format: %s", config.DataFormat)
}
@@ -177,17 +187,16 @@ func NewDropwizardParser(
templates []string,
) (Parser, error) {
parser := &dropwizard.Parser{
MetricRegistryPath: metricRegistryPath,
TimePath: timePath,
TimeFormat: timeFormat,
TagsPath: tagsPath,
TagPathsMap: tagPathsMap,
DefaultTags: defaultTags,
Separator: separator,
Templates: templates,
parser := dropwizard.NewParser()
parser.MetricRegistryPath = metricRegistryPath
parser.TimePath = timePath
parser.TimeFormat = timeFormat
parser.TagsPath = tagsPath
parser.TagPathsMap = tagPathsMap
parser.DefaultTags = defaultTags
err := parser.SetTemplates(separator, templates)
if err != nil {
return nil, err
}
err := parser.InitTemplating()
return parser, err
}