andymchugh / andrewbmchugh-flow-panel

Apache License 2.0
34 stars 2 forks source link

Feature request: updating label text #60

Closed jstaffans-relex closed 4 months ago

jstaffans-relex commented 4 months ago

Thanks for developing this plugin!

Would it be possible to enable updates of label texts in addition to colouring? I am thinking of an equivalent to the Grafana "Stat" panel type which can be configured to render the time series "name" instead of its value. The name is equivalent to whatever the query result legend is configured to be. The time series value will only be used for the panel colour.

Screenshot 2024-05-28 at 11 08 31

andymchugh commented 4 months ago

There's two similar ways you can achieve this with todays version:

Just wanted to confirm you'd thought of both of these and if so, what you see as the problem with either of these alternatives?

jstaffans-relex commented 4 months ago

Just wanted to confirm you'd thought of both of these and if so, what you see as the problem with either of these alternatives?

Yeah, I considered those alternatives. In most cases I think they are enough, but in this case the label I want to display is dynamic. For example, I might have have a set of time series counting number of messages to external endpoints:

messages_out_total{endpoint="foo.com"} 123.0
messages_out_total{endpoint="bar.com"} 345.0
...

For each of these, I could render an SVG diagram with a box indicating the messaging endpoint displaying both the throughput figure (the value) and the endpoint URL displayed.

andymchugh commented 4 months ago

As of 1.12 string data can be applied to labels. So if your term is dynamic (changing with query refresh and time) having a text time-series would be the way to go.

I'm still trying to understand what about the legend would be dynamic because time-series in this space are essentially named off of the legend. I'm not yet seeing how that could change from refresh to refresh and still map to a cell.

I'm missing something. Could you explain why a text time-series isn't what you are after?

jstaffans-relex commented 4 months ago

I work with Prometheus time series, and all time series are "value" time series. I'm interested in displaying both the value, and some combination of labels.

The labels are not as dynamic as the values, they won't change from refresh to refresh. But to be able to construct a generic dashboard with support for any label values I need to be able to extract them from the query results.

Imagine I have several endpoints I am sending messages to. I receive Prometheus time series showing the number of messages sent to each endpoint:

messages_out_total{endpoint="foo.com"} 123.0
messages_out_total{endpoint="bar.com"} 345.0

Just for illustration purposes, imagine I have a dashboard template variable called $endpoint. I want to have a repeating row based on the $endpoint variable. In each row, the throughput for one particular endpoint is shown, and I'd like to render the endpoint URL in the diagram:

example-label-values

I can construct a Prometheus query that uses the repeated template variable so that I only get a single time series for each row:

messages_out_total{endpoint="$endpoint"}

I can then instruct Grafana to construct the legend using the endpoint label: {{ endpoint }}. It would be great if this label value could be rendered into an SVG box, in addition to the time series value.

andymchugh commented 4 months ago

Thanks. I transform the received data to a dataFrame form and then use the grafana function getFieldDisplayName() as the dataRef string. I guess you are saying that is constant across all your rows but that there's some other string that gets used by legends and you want that displayable.

I don't know how to do what you're asking but I can have a hunt around and ask on the forums. Can you attach a screenshot of what your data query response looks like as that will help me look for the right stuff?

jstaffans-relex commented 4 months ago

Another option that would also work for my use case would be if it'd be possible to use a dashboard template variable to set the label text. That is probably easier to implement as well.

jstaffans-relex commented 4 months ago

Can you attach a screenshot of what your data query response looks like as that will help me look for the right stuff?

Attaching the query result JSON response for this query:

Screenshot 2024-05-28 at 23 05 01

query.json

in this example I might want to render for example the instance label in the SVG box.

andymchugh commented 4 months ago

the panel uses grafana dataFrames to bring the myriad of different data sources into a common format and then uses getFieldDisplayName to decide the name of a series that then gets offered up to our yaml dataRef. See https://grafana.com/developers/plugin-tools/create-a-plugin/develop-a-plugin/work-with-data-frames

When I look at your query result, my gut reaction is that getFieldDisplayName would be returning up_result as the dataRef name.

I can understand why you'd like other parameters from your query to be available but nothing is jumping out as a way to do this. Certainly looking at random bits of the results query isn't going to happen because it would be a maintenance nightmare.

Dashboard template variables also doesn't sound 'central' to what this panel is about. At some point we've got to draw a line between what's possible and what's maintainable.

This really feels like you want some kind of table plugin to display the rows of data you have. I'll leave this open for a bit to let you come back but at the moment I'm thinking there's no way to offer what you're asking for.

jstaffans-relex commented 4 months ago

Yeah, I think that if getFieldDisplayName is used to map query results to yaml dataRefs it's probably not going to be possible to implement. There would need to be some other way to map the results, so that getFieldDisplayName could be instead used to fetch the text to display as the label.

Still I think that allowing dataRefs like $endpoint which would reference a variable rather than a query result does have valid use cases. For example, if the SVG panel is repeated, you probably want to render some text to provide a unique identifier for each repetition.

In my case I would like to create a kind of "data lineage" dashboard with 4-5 boxes indicating various storages and queues. I'd like to show hostnames or similar in each box. I can also display this in a table separate from the flow, but it would be much nicer to display it inline in the SVG panel.

Also it would be nice to be able to reference variables in links, so that if I click an SVG element for e.g. a database instance, I am sent to a dashboard for that particular database instance. This would be similar to Grafana's data links.

EDIT: I see the label links already support Grafana variables 👍

andymchugh commented 4 months ago

Thanks for all the explanations; appreciate the time you've spent detailing it. In summary then:

I think that change, when published closes this out as changing the mapping from data-to-cell away from getFieldDisplayName isn't on the cards today. Does that meet give you enough to push ahead?

jstaffans-relex commented 4 months ago

Does that meet give you enough to push ahead?

Yes, that would be great! 👍

andymchugh commented 4 months ago

This is now published in version 1.13.0.

The valueMappings demonstration dashboard has been updated to demonstrate it.