Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loki: Modified heroku drain target to make any url query parameters available as labels #7619

Merged

Conversation

cadrake
Copy link
Contributor

@cadrake cadrake commented Nov 7, 2022

What this PR does / why we need it:

This PR reads the url query parameters included in Heroku drain POST request and creates __param_<name> labels similar to how the parameters work with prometheus metrics and metric endpoints as a way to allow setting the true application name when ingesting logs from a Heroku drain.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

The existing app field coming from Heroku only specifies application source (either the application itself or Heroku) and thus is insufficient for uniquely identifying a log lines source.

Checklist

  • Reviewed the CONTRIBUTING.md guide
  • Documentation added
  • Tests updated
  • CHANGELOG.md updated
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/upgrading/_index.md

@cadrake cadrake requested a review from a team as a code owner November 7, 2022 19:57
@CLAassistant
Copy link

CLAassistant commented Nov 7, 2022

CLA assistant check
All committers have signed the CLA.

@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-target-branch/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0.1%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0.4%
+               loki	0%

@cadrake cadrake changed the title Modified heroku drain target to make any url query parameters available as labels Loki: Modified heroku drain target to make any url query parameters available as labels Nov 7, 2022
@cadrake
Copy link
Contributor Author

cadrake commented Nov 7, 2022

Note that I didnt update documentation because the section on Heroku drains already mentions url parameters being available as __param_<name> labels; however, that looks to have possibly been a typo or copied from another section and not updated.

@thepalbi
Copy link
Contributor

thepalbi commented Nov 9, 2022

Note that I didnt update documentation because the section on Heroku drains already mentions url parameters being available as __param_<name> labels; however, that looks to have possibly been a typo or copied from another section and not updated.

Hi @cadrake , thanks for bringing this up. As for what you mention in the docs, I think you refer to this:

The _param label is set to the value of the first passed URL parameter called .

That quoted sentence comes from the relabel_configs section, and it refers that if you use a relabel_config with __param_<name> it will affect how the URL takes shape in the scraped targets. Almost sure this doesn't apply in this case, but I agree the documentation is kid of misleading, will take this back and correct it.

However, I think what you brought up in this PR is a nice addition to the Heroku target. Commenting on the PR.

Copy link
Contributor

@thepalbi thepalbi left a comment

Choose a reason for hiding this comment

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

In order for this PR to be sound, we need some other changes:

  • Update docs here and here adding the new available labels
  • Add a test case covering query params being extracted AND dropped
  • Add entry to changelog here

clients/pkg/promtail/targets/heroku/target.go Outdated Show resolved Hide resolved
@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-target-branch/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
+               loki	0%

@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-target-branch/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0.4%
+               loki	0%

@cadrake
Copy link
Contributor Author

cadrake commented Nov 10, 2022

For the unit tests, can I piggy-back off of the existing tests or would you like me to create new ones?

@thepalbi
Copy link
Contributor

For the unit tests, can I piggy-back off of the existing tests or would you like me to create new ones?

I think copying one of these as a new test exercising the URL with query params will do

@github-actions github-actions bot added the type/docs Issues related to technical documentation; the Docs Squad uses this label across many repositories label Nov 10, 2022
@cadrake
Copy link
Contributor Author

cadrake commented Nov 10, 2022

I ended up expanding TestHerokuDrainTarget to run additional tests with and without query parameters, also updated all the documentation and changelog

@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-target-branch/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
+               loki	0%

Copy link
Contributor

@thepalbi thepalbi left a comment

Choose a reason for hiding this comment

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

LGTM. Left some nits regarding extra-spaces. Will bump this through Loki to get a review from them, since it's required.

docs/sources/clients/promtail/scraping.md Show resolved Hide resolved
docs/sources/clients/promtail/scraping.md Outdated Show resolved Hide resolved
docs/sources/clients/promtail/configuration.md Outdated Show resolved Hide resolved
@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-target-branch/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

-           ingester	-0.1%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
+               loki	0%

@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-target-branch/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
+               loki	0%

@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-target-branch/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
+               loki	0%

// Create __heroku_drain_param_<name> labels from query parameters
params := r.URL.Query()
for k, v := range params {
lb.Set(fmt.Sprintf("__heroku_drain_param_%s", k), strings.Join(v, ","))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason to prefix the keys? would it be better for users to just use the url param key as the label name?

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh I see, I think the intent is to use a relabel rule to turn these into actual labels sent to Loki?

That seems reasonable to me 👍

Copy link
Collaborator

@slim-bean slim-bean left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!!

@slim-bean slim-bean merged commit ea9ad33 into grafana:main Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L type/docs Issues related to technical documentation; the Docs Squad uses this label across many repositories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants