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

Support requesting only active tags from influxdb in a time range #7919

Conversation

mkutsevol
Copy link

@mkutsevol mkutsevol commented Mar 23, 2017

Issues involved
#5327 #1322 #7918

It adds two things to templating.

  1. If the query starts with a select, then it takes the second column from the output (skips the time column)
  2. $timeFilter is processed as in annotation queries.

Example usage:

In template query input something like this:
SELECT pod_name,last(value) FROM uptime WHERE $timeFilter AND namespace_name = '$namespace' GROUP BY pod_name

The output from this query is time, pod_name lines, and pod_name is being taken.
The query output will be limited to only active pod_names in the time range!

Works like a charm for me :D

@CLAassistant
Copy link

CLAassistant commented Mar 23, 2017

CLA assistant check
All committers have signed the CLA.

@mkutsevol
Copy link
Author

mkutsevol commented Mar 23, 2017

@torkelo torkelo added type/feature-request pr/early-feedback WIP state but looking for early feedback labels Mar 24, 2017
@daniellee daniellee self-assigned this Mar 27, 2017
var part = query.substr(query.indexOf(';;'));

arbitraryColumn = part.split(';').length - 2;
console.log(arbitraryColumn);
Copy link
Member

Choose a reason for hiding this comment

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

Can you describe what this part does? and please remove console log line :)

Copy link
Author

@mkutsevol mkutsevol Mar 28, 2017

Choose a reason for hiding this comment

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

It counts the number of ';', starting from the two consecutive ';;'

Copy link
Author

Choose a reason for hiding this comment

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

and represents it as an index (the -2 part)

@torkelo torkelo added pr/changes-needed pr/needs-unit-tests Unit tests are required before merge labels Mar 28, 2017
@torkelo
Copy link
Member

torkelo commented Mar 28, 2017

I think the use of ; as column selector needs to change, creative solution but not great :)

@mkutsevol
Copy link
Author

mkutsevol commented Mar 28, 2017

How did the log() get through :D
The other way is to modify the interface, 'cos besides ; I don't think we can use anything else

@mkutsevol mkutsevol force-pushed the feature/templating_influx_time_filter branch from efb5c81 to 1db369a Compare March 28, 2017 06:46
@mkutsevol
Copy link
Author

mkutsevol commented Mar 28, 2017

@torkelo , thank you for the review, pushed an update

@mkutsevol
Copy link
Author

mkutsevol commented Mar 28, 2017

Also there is a way to keep the interface as is and use a regexp.
I can join all fields in influxdb return with some string (like ___ or $$$ or any other string with a low probability of encountering in the wild) and then use regexp to extract the needed part. @torkelo , what's your opinion?

@torkelo
Copy link
Member

torkelo commented Mar 28, 2017

I can join all fields in influxdb return with some string (like ___ or $$$ or any other string with a low probability of encountering in the wild) and then use regexp to extract the needed part. @torkelo , what's your opinion?

Not sure what your trying to solve. Is the problem figuring out which field (column) to use in the InfluxDB response? Can you not write the query so that it only returns a single column? (beside time)

@mkutsevol
Copy link
Author

@torkelo, you can see the precise description of the problem and the workarounds taken (not solved) in heapser issue kubernetes-retired/heapster#1179

In influxdb I can't change the position of the time field, and I cant make it output my_tag, time. It does time, my_tag. To output two columns only, you need really latest influx with subquery support.

The problem:
In short - imagine a situation, when you have a high rotation of tags. The tags/names/hostnames whatever are short lived. When I tried vanilla grafana on my influxdb after a week of data collection it tried to render 10k tags in one namespace. 9900 of them being dead and not being interesting to me at all. I wanted stats for the past 30mins from the last rollout.

@torkelo
Copy link
Member

torkelo commented Mar 28, 2017

I understand the bigger problem (query for only active series/tags). But not the need to use number of ; to know which column to use

@mkutsevol
Copy link
Author

@torkelo, I'm open to any proposal you've got.
How this should be implemented, share your idea!

@torkelo
Copy link
Member

torkelo commented Mar 28, 2017

is not always the second column? (or first non time column) ?

@mkutsevol
Copy link
Author

No, it is not,
It is up to the user to construct the query. If SHOW metadata query is used then it will output one column. If SELECT is used when whatever the user wrote is in the result.

Sure, parsing for select query and (always) taking the second column will work, but is it better than a special query syntax, which imposes no constraints on the user which writes the query?

@torkelo
Copy link
Member

torkelo commented Mar 28, 2017

but is it better than a special query syntax, which imposes no constraints on the user which writes the query?

yes, by miles compared to using a the number of semi colons at the end of the statement :)

@mkutsevol
Copy link
Author

@torkelo ok, not a problem at all.

@mkutsevol
Copy link
Author

@torkelo, I've pushed a variant w/o semicolumns :D
I don't squash it while you are reviewing it, will do as it will be ready for merge.

@nocamin
Copy link

nocamin commented Apr 25, 2017

I'm unable to get the second column values in templating, just got the time column in Preview of values (shows max 20) option.

Can you write a simple query for me to get the second column output in templating.

OR How to get the only second column output ?

screenshot

@nocamin
Copy link

nocamin commented Apr 25, 2017

All changes done as per given in two Commits. But still getting time column only as per screenshot.

@mkutsevol
Copy link
Author

@nocamin
your query is correct. If you applied this PR it should just work.
There is no activity in it after my last posts, so I assume the authors are not interested in this use case.

@torkelo
Copy link
Member

torkelo commented Apr 28, 2017

this is very close to mergable.

  1. accessing this.timeSrv.time is not good, should call this.timeSrv.timeRange(),
  2. missing tests change to influxdb response_parser

@yinhua-dai
Copy link

@torkelo , when I can get a formal package for this? Thank you.

@daniellee
Copy link
Contributor

@yinhua-dai this is not merged yet as it still needs changes. So hard to say which Grafana release it will be included in.

@mkutsevol
Copy link
Author

@torkelo, thanks for feedback, will update soon.

@Darkmyr
Copy link

Darkmyr commented Jul 10, 2017

@mkutsevol any updates? Would love to see this in grafana.

Thanks,
Darkmyr

@mkutsevol
Copy link
Author

Switched jobs ~ a couple of month ago, was running out of time completely, moving to a new city, etc.
I remember about my open PRs on github, will try to do my best to address the issues and get it merged.

@mkutsevol mkutsevol force-pushed the feature/templating_influx_time_filter branch 2 times, most recently from 25c8267 to ffb157b Compare July 10, 2017 18:11
@mkutsevol
Copy link
Author

@torkelo, hi!
can I get a review here?
Thanks!

@Darkmyr
Copy link

Darkmyr commented Jul 10, 2017

@mkutsevol Thank you! I appreciate you taking the time.

Darkmyr

@mkutsevol
Copy link
Author

@Darkmyr, it's my pleasure :D

@elyzion
Copy link

elyzion commented Oct 20, 2017

I really need this for my AWS environments as well. I'm using immutable deployments for my Elastic Beanstalk and this results in a horde of old instances showing up when I try and filter by host tag.

@mkutsevol
Copy link
Author

Seems like removing one on my email addresses from GH account revoked CLA here, will push again.
@torkelo is anything else needed to get it merged?
Thanks!

@mkutsevol mkutsevol force-pushed the feature/templating_influx_time_filter branch from ffb157b to c420bdc Compare October 23, 2017 13:35
@daniellee
Copy link
Contributor

daniellee commented Oct 31, 2017

Would it be possible to do this the same way we do for the Postgres and MySQL data sources with an alias for the field name. Something like:

SELECT pod_name as "__text", last(value) FROM uptime WHERE $timeFilter AND namespace_name = '$namespace' GROUP BY pod_name

and maybe could support both text and value like this:

SELECT pod_name as "__text", pod_template_hash as "__value", last(value) FROM uptime WHERE $timeFilter AND namespace_name = '$namespace' GROUP BY pod_name

@mkutsevol
Copy link
Author

Unfortunately, no.
It's not an SQL db, they just try not to invent a completely new syntax.

@daniellee
Copy link
Contributor

Don’t understand. InfluxDB has support for field alias. So why is not possible?

@mkutsevol
Copy link
Author

Ah, ok. I haven't checked influx. You may be right. But I don't have any more will to change this PR. At least in a dramatic way. And I don't see a clear benefit in that approach with aliases.

@daniellee
Copy link
Contributor

@mkutsevol I'm sorry we have been so slow with feedback and that you don't want to work on the PR anymore. We felt that this solution was a bit clunky but we discovered a better way when working on mysql/postgres and I only just now made the connection that this PR is really similar.

Is it OK if I take over the PR and finish it then?

The benefit with aliases is that:

  1. you do not have to hard code that the text value is the second value in the list of columns. (this code -> addUnique(res, value[1] || value[0]);)
  2. You can have a template variable with a text value (that is a user friendly value) and a value that is not so user friendly but is used in the query. E.g. text: server name value: ip address
  3. It is not a big change to your PR. And this type of parsing has already been done in the mysql and postgres response parsers if a reference point is needed.

@mkutsevol
Copy link
Author

@daniellee, yes, sure, take it over!
Thanks!

@torkelo
Copy link
Member

torkelo commented May 7, 2018

closing this PR as it targets an old branch, and the author has abandoned it. Maybe this PR can solve this, #11846

@torkelo torkelo closed this May 7, 2018
@ying-jeanne ying-jeanne added the pr/external This PR is from external contributor label Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/changes-needed pr/early-feedback WIP state but looking for early feedback pr/external This PR is from external contributor pr/needs-unit-tests Unit tests are required before merge type/feature-request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants