feat: Add option to disable Wavefront prefix conversion (#10252)

This commit is contained in:
crflanigan 2021-12-14 16:04:30 -06:00 committed by GitHub
parent c1550a7303
commit e7e50a8883
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 13 deletions

View File

@ -1590,6 +1590,7 @@ func (c *Config) buildSerializer(tbl *ast.Table) (serializers.Serializer, error)
c.getFieldStringSlice(tbl, "wavefront_source_override", &sc.WavefrontSourceOverride) c.getFieldStringSlice(tbl, "wavefront_source_override", &sc.WavefrontSourceOverride)
c.getFieldBool(tbl, "wavefront_use_strict", &sc.WavefrontUseStrict) c.getFieldBool(tbl, "wavefront_use_strict", &sc.WavefrontUseStrict)
c.getFieldBool(tbl, "wavefront_disable_prefix_conversion", &sc.WavefrontDisablePrefixConversion)
c.getFieldBool(tbl, "prometheus_export_timestamp", &sc.PrometheusExportTimestamp) c.getFieldBool(tbl, "prometheus_export_timestamp", &sc.PrometheusExportTimestamp)
c.getFieldBool(tbl, "prometheus_sort_metrics", &sc.PrometheusSortMetrics) c.getFieldBool(tbl, "prometheus_sort_metrics", &sc.PrometheusSortMetrics)

View File

@ -104,6 +104,9 @@ type Config struct {
// When enabled forward slash (/) and comma (,) will be accepted // When enabled forward slash (/) and comma (,) will be accepted
WavefrontUseStrict bool `toml:"wavefront_use_strict"` WavefrontUseStrict bool `toml:"wavefront_use_strict"`
// Convert "_" in prefixes to "." for Wavefront
WavefrontDisablePrefixConversion bool `toml:"wavefront_disable_prefix_conversion"`
// Include the metric timestamp on each sample. // Include the metric timestamp on each sample.
PrometheusExportTimestamp bool `toml:"prometheus_export_timestamp"` PrometheusExportTimestamp bool `toml:"prometheus_export_timestamp"`
@ -134,7 +137,7 @@ func NewSerializer(config *Config) (Serializer, error) {
case "carbon2": case "carbon2":
serializer, err = NewCarbon2Serializer(config.Carbon2Format, config.Carbon2SanitizeReplaceChar) serializer, err = NewCarbon2Serializer(config.Carbon2Format, config.Carbon2SanitizeReplaceChar)
case "wavefront": case "wavefront":
serializer, err = NewWavefrontSerializer(config.Prefix, config.WavefrontUseStrict, config.WavefrontSourceOverride) serializer, err = NewWavefrontSerializer(config.Prefix, config.WavefrontUseStrict, config.WavefrontSourceOverride, config.WavefrontDisablePrefixConversion)
case "prometheus": case "prometheus":
serializer, err = NewPrometheusSerializer(config) serializer, err = NewPrometheusSerializer(config)
case "prometheusremotewrite": case "prometheusremotewrite":
@ -187,8 +190,8 @@ func NewPrometheusSerializer(config *Config) (Serializer, error) {
}) })
} }
func NewWavefrontSerializer(prefix string, useStrict bool, sourceOverride []string) (Serializer, error) { func NewWavefrontSerializer(prefix string, useStrict bool, sourceOverride []string, disablePrefixConversions bool) (Serializer, error) {
return wavefront.NewSerializer(prefix, useStrict, sourceOverride) return wavefront.NewSerializer(prefix, useStrict, sourceOverride, disablePrefixConversions)
} }
func NewJSONSerializer(timestampUnits time.Duration, timestampFormat string) (Serializer, error) { func NewJSONSerializer(timestampUnits time.Duration, timestampFormat string) (Serializer, error) {

View File

@ -20,6 +20,10 @@ The `wavefront` serializer translates the Telegraf metric format to the [Wavefro
## more about them here: ## more about them here:
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md
data_format = "wavefront" data_format = "wavefront"
## Users who wish their prefix paths to not be converted may set the following:
## default behavior (enabled prefix/path conversion): prod.prefix.name.metric.name
## configurable behavior (disabled prefix/path conversion): prod.prefix_name.metric_name
# wavefront_disable_prefix_conversion = true
``` ```
## Metrics ## Metrics

View File

@ -15,6 +15,7 @@ type WavefrontSerializer struct {
Prefix string Prefix string
UseStrict bool UseStrict bool
SourceOverride []string SourceOverride []string
DisablePrefixConversions bool
scratch buffer scratch buffer
mu sync.Mutex // buffer mutex mu sync.Mutex // buffer mutex
} }
@ -40,11 +41,12 @@ var tagValueReplacer = strings.NewReplacer("\"", "\\\"", "*", "-")
var pathReplacer = strings.NewReplacer("_", ".") var pathReplacer = strings.NewReplacer("_", ".")
func NewSerializer(prefix string, useStrict bool, sourceOverride []string) (*WavefrontSerializer, error) { func NewSerializer(prefix string, useStrict bool, sourceOverride []string, disablePrefixConversion bool) (*WavefrontSerializer, error) {
s := &WavefrontSerializer{ s := &WavefrontSerializer{
Prefix: prefix, Prefix: prefix,
UseStrict: useStrict, UseStrict: useStrict,
SourceOverride: sourceOverride, SourceOverride: sourceOverride,
DisablePrefixConversions: disablePrefixConversion,
} }
return s, nil return s, nil
} }
@ -67,7 +69,9 @@ func (s *WavefrontSerializer) serializeMetric(m telegraf.Metric) {
name = sanitizedChars.Replace(name) name = sanitizedChars.Replace(name)
} }
if !s.DisablePrefixConversions {
name = pathReplacer.Replace(name) name = pathReplacer.Replace(name)
}
metricValue, valid := buildValue(value, name) metricValue, valid := buildValue(value, name)
if !valid { if !valid {