Skip to content

Commit

Permalink
fix: Update prometheusremotewrite parser to be a new style parser plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
reimda committed Jul 7, 2022
1 parent a0aa408 commit 6293e9a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions plugins/parsers/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
_ "github.com/influxdata/telegraf/plugins/parsers/logfmt"
_ "github.com/influxdata/telegraf/plugins/parsers/nagios"
_ "github.com/influxdata/telegraf/plugins/parsers/prometheus"
_ "github.com/influxdata/telegraf/plugins/parsers/prometheusremotewrite"
_ "github.com/influxdata/telegraf/plugins/parsers/value"
_ "github.com/influxdata/telegraf/plugins/parsers/wavefront"
_ "github.com/influxdata/telegraf/plugins/parsers/xpath"
Expand Down
12 changes: 12 additions & 0 deletions plugins/parsers/prometheusremotewrite/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/metric"
"github.com/influxdata/telegraf/plugins/parsers"

"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/prompb"
Expand Down Expand Up @@ -82,3 +83,14 @@ func (p *Parser) ParseLine(line string) (telegraf.Metric, error) {
func (p *Parser) SetDefaultTags(tags map[string]string) {
p.DefaultTags = tags
}

func (p *Parser) InitFromConfig(config *parsers.Config) error {
return nil
}

func init() {
parsers.Add("prometheusremotewrite",
func(defaultMetricName string) telegraf.Parser {
return &Parser{}
})
}
6 changes: 0 additions & 6 deletions plugins/parsers/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/parsers/prometheusremotewrite"
"github.com/influxdata/telegraf/plugins/parsers/temporary/json_v2"
"github.com/influxdata/telegraf/plugins/parsers/temporary/xpath"
)
Expand Down Expand Up @@ -193,8 +192,6 @@ func NewParser(config *Config) (Parser, error) {
var err error
var parser Parser
switch config.DataFormat {
case "prometheusremotewrite":
parser, err = NewPrometheusRemoteWriteParser(config.DefaultTags)
default:
creator, found := Parsers[config.DataFormat]
if !found {
Expand All @@ -213,8 +210,5 @@ func NewParser(config *Config) (Parser, error) {
return parser, err
}

func NewPrometheusRemoteWriteParser(defaultTags map[string]string) (Parser, error) {
return &prometheusremotewrite.Parser{
DefaultTags: defaultTags,
}, nil
}

0 comments on commit 6293e9a

Please sign in to comment.