Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ajwerner
Copy link
Contributor

What is this feature?

Fixes a bug whereby data links in Stat panels (and probably other "reduced" data panels) could not refer to the ${__data.fields} macros available in other panels.

For these panels, data links which referred to fields did not end up rendering because the rowIndex ended up being undefined. When the row index is undefined, the data macro expansion for fields does not trigger (see 0).

Why do we need this feature?

It's often very nice to link to data that you are not displaying. See the chatter in #60297.

Who is this feature for?

Grafana users who like data links.

Which issue(s) does this PR fix?:

Fixes #60297

Special notes for your reviewer:

Please check that:

  • It works as expected from a user's perspective.
    • I tested it manually; I don't have the context on how to write the appropriate test. All the tests passed.

@ajwerner ajwerner requested review from a team as code owners January 17, 2024 02:43
@ajwerner ajwerner requested review from Clarity-89, eledobleefe and oshirohugo and removed request for a team January 17, 2024 02:43
@CLAassistant
Copy link

CLAassistant commented Jan 17, 2024

CLA assistant check
All committers have signed the CLA.

@grafana-pr-automation grafana-pr-automation bot added area/frontend pr/external This PR is from external contributor labels Jan 17, 2024
@baldm0mma baldm0mma added the no-changelog Skip including change in changelog/release notes label Jan 18, 2024
@baldm0mma baldm0mma added this to the 10.4.x milestone Jan 18, 2024
@baldm0mma baldm0mma requested review from a team, Develer and leeoniya and removed request for a team January 18, 2024 16:56
@baldm0mma
Copy link
Contributor

Thanks @ajwerner . The fix looks good to me, but I would love a few others on the @grafana/dataviz-squad to take a look too make sure this doesn't adversely/unexpectedly touch anything and have unintended interactions elsewhere.

Copy link
Contributor

@codeincarnate codeincarnate left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! This appears to be working and it makes sense that the value field for a reduction would be the first field (i.e. index 0). I'm not sure if this has broader impact however and it would be good to get someone to chime in on that.

Going by file history maybe @drew08t or @ryantxu might know?

@nmarrs nmarrs added add to changelog no-backport Skip backport of PR and removed no-changelog Skip including change in changelog/release notes labels Jan 26, 2024
@nmarrs nmarrs changed the title grafana-data/src/field/fieldDisplay.ts: fix links Stat: Fix data links Jan 26, 2024
@nmarrs nmarrs changed the title Stat: Fix data links Stat: Fix data links that refer to fields Jan 26, 2024
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure of the implications of hard coding the value row index here, @leeoniya do you have any insights on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've narrowed the change and added more commentary. The change is now more minimal.

On some level, choosing valueRowIndex: 0 can be wrong. If you have more than one row in the data frame then the calc that was run may not be totally meaningful. Indeed this is referring to the entire data frame here when we talk about the ${__data} macros and then scoped to the relevant row through this mechanism here.

The more minimal and correct thing I've now done to limit this change to apply only to data frames with a single row. Then there's no doubt that it's the right choice for the row index (it's the only reasonable choice :p).

@ajwerner
Copy link
Contributor Author

I think the failure on that CI step was some sort of infra misconfiguration or flake or something.

Copy link
Contributor

@nmarrs nmarrs left a comment

Choose a reason for hiding this comment

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

I think this is reasonable, thanks for diving deeper into this - I think this solution is "good enough" for the time being 👍

@nmarrs nmarrs enabled auto-merge (squash) January 31, 2024 22:37
@nmarrs
Copy link
Contributor

nmarrs commented Jan 31, 2024

@ajwerner we made some build changes recently so to get this merged you will need to merge this branch onto latest main

  1. Pull latest main
  2. Checkout to this branch
  3. run git merge origin main
  4. push up result

thanks!

For panels like Stat, data links which referred to fields did not end up
rendering because the rowIndex ended up being undefined. When the row
index is undefined, the data macro expansion for fields does not
trigger (see [0]).

This change allows these links to work when the query returns exactly
one row. This is not a complete fix for the problem in the general, but
a TODO with more details on a complete solution were added around the
change.

0: https://github.com/grafana/grafana/blob/878ba96a/public/app/features/templating/dataMacros.ts#L99-L101

Fixes grafana#60297
auto-merge was automatically disabled January 31, 2024 22:52

Head branch was pushed to by a user without write access

@ajwerner
Copy link
Contributor Author

@nmarrs I rebased main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add to changelog area/frontend no-backport Skip backport of PR pr/external This PR is from external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Data links in Stat panel with __data.fields not working

6 participants