Skip to content

Prometheus Remote Write protocol support#8702

Closed
aleksey-novikov wants to merge 3 commits intoinfluxdata:masterfrom
aleksey-novikov:master
Closed

Prometheus Remote Write protocol support#8702
aleksey-novikov wants to merge 3 commits intoinfluxdata:masterfrom
aleksey-novikov:master

Conversation

@aleksey-novikov
Copy link
Copy Markdown

@aleksey-novikov aleksey-novikov commented Jan 15, 2021

Prometheus Remote Write protocol

This is basic implementation of Prometheus Remote Write Protocol. Includes:

  • Snappy Content-Encoding support
  • Prometheus Remote Write parser

Must be used with http_listener_v2

Sample input configuration:

[[inputs.http_listener_v2]]
  service_address = ":10000"
  data_format = "prometheusremotewrite"

Closes #8682

Copy link
Copy Markdown
Contributor

@telegraf-tiger telegraf-tiger bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for the pull request!
🤝 ✒️ Just a reminder that the CLA has not yet been signed, and we'll need it before merging. Please sign the CLA when you get a chance, then post a comment here saying !signed-cla

@lgtm-com
Copy link
Copy Markdown

lgtm-com bot commented Jan 15, 2021

This pull request introduces 1 alert when merging a3f26a6 into 76c2201 - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable

@sjwang90
Copy link
Copy Markdown
Contributor

Fixes #8682

@sjwang90 sjwang90 linked an issue Jan 15, 2021 that may be closed by this pull request
@sjwang90 sjwang90 added area/prometheus plugin/parser 1. Request for new parser plugins 2. Issues/PRs that are related to parser plugins labels Jan 15, 2021
Comment on lines +11 to +13
"github.com/prometheus/prometheus/prompb"
"github.com/gogo/protobuf/proto"
"github.com/prometheus/common/model"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please order alphabetically.

Comment on lines +24 to +25


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just one newline. Same for all of those instances below.

Comment on lines +52 to +53
metric, err := metric.New("prometheusremotewrite", tags, fields, t)
if err == nil {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might silently drop metrics here without allowing the user to be aware of this. Please either fail here (i.e. return err) or at least issue a log message in case we see an error here.

tags[l.Name] = l.Value
}

metricName := tags[model.MetricNameLabel]
Copy link
Copy Markdown
Member

@srebhan srebhan Jan 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be absolutely sure that tag exists? I will sleep better if we check that model.MetricNameLabel exists in tags by

Suggested change
metricName := tags[model.MetricNameLabel]
metricName := tags[model.MetricNameLabel]
if metricName == "" {
return fmt.Errorf("metric name %q not found in tag-set or empty", model.MetricNameLabel)
}

metricName := tags[model.MetricNameLabel]
delete(tags, model.MetricNameLabel)

for _, s := range ts.Samples {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we approximately know how many metrics we expect we might want to preallocate the array with the number of samples, i.e. capacity = len(ts.Samples) and len = 0.

for _, l := range ts.Labels {
tags[l.Name] = l.Value
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also have to add the DefaultTags here.

delete(tags, model.MetricNameLabel)

for _, s := range ts.Samples {
fields := getNameAndValue(&s, metricName)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should move the code here. It's not a lot and this would follow the tags handling.


// converting to telegraf metric
if len(fields) > 0 {
t := getTimestamp(&s, now)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might also move the body of the function here. See above.

Copy link
Copy Markdown
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @aleksey-novikov, this is really nice code! I have some comments in the code. Additionally I have some major comments/requests:

  1. Please split the http_listener, snappy encoding change into an own PR. I think this is independent of the prometheus parser a very useful change.
  2. Please add tests! This holds for both, the snappy support as well as the parser part. Provide some examples where you know the expected output.
  3. This is more a question/suggestion rather than a request: Do you think it makes sense to collect samples from the same timestamp into one metric? Not sure if this makes sense at all, but I want to know your opinion on this...
  4. You should add a README.md with some parsing result examples. Furthermore, you need to extend the list of available parsers etc.

@srebhan srebhan self-assigned this Jan 26, 2021
@sjwang90
Copy link
Copy Markdown
Contributor

Hi @aleksey-novikov 👋 ,

Just checking if you can address @srebhan's comments. We'd love to get this in our upcoming 1.18 feature release targeted for the end of March.

@sjwang90
Copy link
Copy Markdown
Contributor

@aleksey-novikov - Another ping. We'd love to get this into 1.18 so let us know if you want to make the changes otherwise someone on the influx side can finish it up. Thanks!

@helenosheaa
Copy link
Copy Markdown
Member

helenosheaa commented Mar 3, 2021

Hey @aleksey-novikov great work! We're really interested on working to get this merged in. Are you interested in carrying on with the PR? If you could address some of @srebhan's comments. If not I can take over the PR and get it to a ready to merge state to be merged.

@helenosheaa helenosheaa self-assigned this Mar 3, 2021
@aleksey-novikov
Copy link
Copy Markdown
Author

Hi @helenosheaa!
Unfortunately, I do not have enough experience in golang development and do not have enough time to adapt these changes. I needed to implement the collection of metrics from Kubernetes into the our company's monitoring system based on Kafka + Graphite + ClickHouse. As tests have shown, the Telegraf creates a significantly higher load on the CPU than Prometheus. Therefore, I implemented the functionality of transferring metrics from Prometheus to a dedicated stand-alone Telegraf instance. In our case, it works, it seems even quite stable. If someone is involved in the maintenance of this PR, I will be glad of it.

@helenosheaa
Copy link
Copy Markdown
Member

Hi @aleksey-novikov, thanks for getting back to me quickly. I'll start my own PR and link to this one and close when it's up. Thanks for getting it going and if you have any feedback when I submit mine please comment.

@helenosheaa
Copy link
Copy Markdown
Member

Closing to move forward with #8967

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/prometheus new plugin plugin/parser 1. Request for new parser plugins 2. Issues/PRs that are related to parser plugins

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Prometheus Remote Write Parser

5 participants