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 querying multiple repos at a time via query variables #90

Closed
jsheffield-roblox opened this issue Oct 21, 2020 · 5 comments
Closed
Labels
type/feature-request Requested new feature or enhancement

Comments

@jsheffield-roblox
Copy link

jsheffield-roblox commented Oct 21, 2020

Problem

I would like to get metrics on multiple repos at a time. Technically, this is possible at the moment, just not with query variables.

I.E. Given the repos:

  • Org/repo_a
  • Org/repo_a

I can put the following in the query box repo:Org/repo_a repo:Org/repo_b
Screen Shot 2020-10-21 at 12 06 06 PM

This works. However, the issue becomes when trying to use query variables to accomplish this.
Screen Shot 2020-10-21 at 12 06 58 PM

Using this variable like so:
Screen Shot 2020-10-21 at 12 07 51 PM

Just results in the query string being repo:{Org/repo_a,Org/repo_b}

I was unable to find any way to transform this string into what I need using the builtin grafana interpolation, as it seems to only support either plugin defined formats or a list of predefined formats here

Proposed solution

I believe this could be accomplished by simply splitting on commas in the repository field, then separating each of those into their own repo:x field in the query here, but I'm not sure if this is the best/desired way of accomplishing this.

So the final result would look something like this
Screen Shot 2020-10-21 at 12 27 08 PM

where $repo_name is: Org/repo_a,Org/repo_b etc, then the generated query is repo:Org/repo_a repo:Org/repo_b

I'd be happy to create a pr to this effect, just want to make sure this is the "grafana" way of doing things and I'm not missing a better solution here!

@kminehart
Copy link
Contributor

This is probably related to this:

#43

Basically we have to refactor the replaceVariables function to support these kinds of operations.

https://github.com/grafana/github-datasource/blob/master/src/DataSource.ts#L29

There are some default formatting options you can try, though I am not sure that they will work.
https://grafana.com/docs/grafana/latest/variables/advanced-variable-format-options/

Maybe try the CSV option? ${variable:csv}

@jsheffield-roblox
Copy link
Author

Hm, I'm not sure I'm communicating the problem correctly (or perhaps I just don't understand what you're saying!)

Basically, the variable replacement does work, it just doesn't substitute it as anything meaningful for repos.

Github's api seems to only support repo:org/repo_a repo:org/repo_b repo:org/repo_c as syntax for including multiple repos. The plugin currently only offers the ability to do repo:org/repo_a,org/repo_b,org/repo_c (this is the csv format method).

My suggestion is splitting on the csv's commas in the code go code here, and turning those comma separated values into the format that github expects, repo:org/repo_a repo:org/repo_b repo:org/repo_c

@mjseaman mjseaman added the type/feature-request Requested new feature or enhancement label Nov 4, 2020
@jsheffield-roblox
Copy link
Author

@kminehart would you be willing to accept a pr to this effect? For the metrics we plan on collating with this plugin, we need support for multiple repos.

@kminehart
Copy link
Contributor

kminehart commented Nov 4, 2020

Absolutely!

Sorry I haven't quite gotten to a lot of the issues on here yet. This plugin is part of our work on the Enterprise Plugins team and we support a lot of datasources. :D

To point you in the right direction, this should involve some changes in this function:

https://github.com/grafana/github-datasource/blob/master/src/DataSource.ts#L29

@marcoaaguiar
Copy link

@jsheffield-roblox did you ever manage to make any implementation to solve this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature-request Requested new feature or enhancement
Projects
None yet
Development

No branches or pull requests

5 participants