Skip to content

append labels server side by incoming query param #23

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

norrs
Copy link

@norrs norrs commented Sep 27, 2019

This feature is useful for mobile clients.

This allows us to provide an endpoint via configuration containing specific labels we want to have appended on metrics sent from the client.

It also makes client code less bloated, as they don't have to provide client_version etc everywhere they use a Counter. It could also be other relevant metrics such as client participating in a experiment.

This allows users to construct their own main().  This is useful for
constructing your own webserver setup for adding features such as api
signing.
@norrs
Copy link
Author

norrs commented Sep 30, 2019

Fixed my commits to be signed. Forgot to update a few settings after migrating to yubikey5.

@norrs
Copy link
Author

norrs commented Sep 30, 2019

We have some more code that is work in progress, need a few more changes so we can easily just depend on this as a module and override and make our own main().

@norrs norrs changed the title append labels server side by incoming query param WIP: append labels server side by incoming query param Sep 30, 2019
@norrs norrs changed the title WIP: append labels server side by incoming query param append labels server side by incoming query param Oct 2, 2019
@norrs
Copy link
Author

norrs commented Oct 2, 2019

This is ready for being reviewed, this allowed us to reuse your code while replacing main() with our own http server setup using api signing etc.

@bboreham
Copy link
Contributor

Hi, thanks for the PR, and sorry it languished for a bit.

It's quite big (at least superficially) so may take a while longer to figure out what changed.
I wonder why git doesn't spot the file is mostly the same in the first commit and show it as a rename.

@norrs
Copy link
Author

norrs commented Jan 9, 2020

@bboreham : git diff -M -C master serversidelabels --summary might be helpful? Probably because file is copied and main then modified to remove what is put inside aggate.go. This one should clear up the "huge" copy for you: git show bbd18c6b8336425b73f9eb9bc1768ab8729e154d -M -C

https://www.reddit.com/r/git/comments/1oi0tw/is_there_any_way_have_git_diff_show_that_a_file/ccsfh1d/

Copy link
Contributor

@bboreham bboreham left a comment

Choose a reason for hiding this comment

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

I have read through this now; nothing jumps out as a problem, but I think it deserves some explanation in the README how to use this new feature.
It looks like you supply one name which will appear in the URL like http://x/...?name=foo:bar which will be appended as a Prometheus label foo=bar.
If anything goes wrong (e.g. the query param has the wrong format) then it is silently ignored.

Would it be simpler just to add query parameters ?foo=bar as labels? Then we don't need a flag and code to split around :.

If you are making changes I would prefer the split to a separate package to be a separate PR - that has nothing to do with labels.

Also #31 did a similar change for endpoint configuration, so that is a merge clash now.

for _, m := range metrics {
if _, foundLabel := queryArguments[labelQueryParam]; foundLabel {
for _, label := range queryArguments[labelQueryParam] {
l := strings.Split(label, ":")
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be more flexible as SplitN() ?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, if we would want to support using the separator in its value.
Thanks, will update after #23 (comment)

@norrs
Copy link
Author

norrs commented Feb 6, 2020

@bboreham : > Would it be simpler just to add query parameters ?foo=bar as labels?

Sadly this would include other query parameters we need to send to the service for doing API signing which we have added internally for our http router.

Hence they are sent as request parameter (which is configurable) which is read as an array according to the http spec for query arguments.

Not sure how I would add filtering on my side in additional if you wanted to create prometheus labels based from any query parameter and its value. (as I would then need to filter a few query parameters that shouldn't be prometheus labels).

I guess I could split up into two PRs, but however I do think that #31 (review) needs to be fixed first before I rebase and split the PR.

@bboreham
Copy link
Contributor

bboreham commented Apr 8, 2020

I notice the Prometheus Pushgateway has a similar feature, but the labels form part of the http path - see https://github.com/prometheus/pushgateway#url . Would that work for you? It would be great to make the projects more compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants