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

Multi-value template variable not properly interpolated for repeated panels #40

Closed
svet-b opened this issue Jan 13, 2021 · 4 comments · Fixed by #41
Closed

Multi-value template variable not properly interpolated for repeated panels #40

svet-b opened this issue Jan 13, 2021 · 4 comments · Fixed by #41
Labels
bug Something isn't working

Comments

@svet-b
Copy link

svet-b commented Jan 13, 2021

When panel repetition is enabled for a given template variable, the GraphQL query in each of the repeated panels is executed for all values of the template variable, rather than for the individual value in the specific panel.

For example, let's say we have a Grafana template variable called asset_id with multiple values 1, 2, 3. We also have a panel that's set to repeat for each value of asset_id. If in that panel we have the GraphQL query

query {
    Assets (where: { 
        id: $asset_id
      }) {
        name            
    }
}

then in principle the query in each panel should substitute each of the values of asset_id, with queries like id: 1, id: 2, id: 3. This is handled correctly for other datasources I've tried.

Instead, in each panel the query states id: 1,2,3, so the same (multi-value) result appears in each of the repeated panels.

I've reviewed some of the other issues/PRs relating to template variables, but I feel like this is separate. Happy to provide additional details if helpful!

@jazerda
Copy link

jazerda commented Jan 14, 2021

+1

@retzkek retzkek added the bug Something isn't working label Jan 14, 2021
@retzkek
Copy link
Contributor

retzkek commented Jan 14, 2021

Thanks for the report, I can confirm this behavior and agree it's not right. I'd expect Grafana should be handling what values go to each panel, so we're probably (still) using TemplateSrv wrong. https://github.com/fifemon/graphql-datasource/blob/master/src/DataSource.ts#L78

@retzkek
Copy link
Contributor

retzkek commented Jan 14, 2021

This seems to be a common issue with datasource plugins, e.g. stackdriver grafana/grafana#28672. That was fixed by adding scopedVars to the templateSrv.replace() call, which we already do. But maybe scopedVars isn't getting passed into createQuery() correctly...

@retzkek
Copy link
Contributor

retzkek commented Jan 14, 2021

Aha! But we make two calls to replace(), the first (that handles the legacy range variables) does not pass scopedVars: https://github.com/fifemon/graphql-datasource/blob/master/src/DataSource.ts#L73

Easy fix, I'll turn that into one call. PR shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants