Giter Site home page Giter Site logo

Comments (8)

marcusolsson avatar marcusolsson commented on September 3, 2024 2

Yes, it's a very common pattern. Fortunately, in recent Grafana versions, renaming fields is now built into Grafana itself. Try adding a "Organize field" transformation to your query.

Would this support your use case?

from grafana-json-datasource.

fpanwaskar avatar fpanwaskar commented on September 3, 2024

Hi there how would I use the "Organise Fields" to apply series overrides?

In the example my response will look like:
{
"data":[
{
"@timestamp":"2020-11-30T08:36:24.110Z",
"price":2575.5,
"timestamp":1606725384110,
"orderType":"1""name":"orderAdd"
},
{
"@timestamp":"2020-11-30T08:36:13.755Z",
"price":45.91,
"timestamp":1606725384110,
"orderType":"1",
"name":"orderAdd"
}, ...
]
}

In my query I isolate the following paths:

$.data[].timestamp
$.data[
].prices
$.data[*].name

I want to match on the value of name attribute to apply series overrides/ Although I set the regex to /orderAdd/ I get no match.

Could you provide some guidance on what might the issue?

This works with the associated pull request as I am able to provide an alias of orderAdd which is then mapped to the name.

from grafana-json-datasource.

marcusolsson avatar marcusolsson commented on September 3, 2024

By default, the field name is set to the name of the property referenced by your JSON Path.

In your example, you'd end up with a query result like this:

timestamp name price
1606725384110 orderAdd 2575.5
1606725384110 orderAdd 45.91

With the Organize fields transform, you can for example rename the name field to action. Either way you can use it to specify the field to apply your override to.

Screen Shot 2021-01-04 at 14 38 31

Screen Shot 2021-01-04 at 14 38 43

The reason why you're not getting a match for /orderAdd/ is because orderAdd is a value in the name/action field rather than the name of it.

It sounds like you'd like a query response that looks something like this:

timestamp orderAdd
1606725384110 2575.5
1606725384110 45.91

If this is what you're looking for, this is not supported at the moment (and wouldn't be solved with aliases). You can read more about wide and long data frames here: https://grafana.com/docs/grafana/latest/developers/plugins/data-frames/#data-frames-as-time-series.

Let me know if I've misunderstood your use case!

from grafana-json-datasource.

fpanwaskar avatar fpanwaskar commented on September 3, 2024

Thanks for the explanation. I can modify the response to look like that, but that does not feel right for an api implementation.

I was looking at the conversion to a DataFrame and in MutableDataFrame when the field is added any supplied config is added.

I think field.config.displayName is supported, could a possible solution be to give the user the ability to set an optional displayName on the query field?

from grafana-json-datasource.

marcusolsson avatar marcusolsson commented on September 3, 2024

Yeah, I agree it's not ideal for an API response.

Could you maybe create multiple data source queries add filter the items in the JSON Path and override the display name for each?

Screen Shot 2021-01-05 at 11 25 58

from grafana-json-datasource.

fpanwaskar avatar fpanwaskar commented on September 3, 2024

Yes I could create multiple data source queries in fact that is what I am doing now. How would I override the display name, as this is not currently supported?

I was thinking that as part of the query entry an optional displayName could be supplied. Is there another way?

from grafana-json-datasource.

fpanwaskar avatar fpanwaskar commented on September 3, 2024

Hi @marcusolsson,

Overriding the displayName would work. Are you happy with as a solution? It could be an optional query parameter.

The override displayName placeholder could be the current displayName.

from grafana-json-datasource.

marcusolsson avatar marcusolsson commented on September 3, 2024

I feel like we're discussing two different issues.

As I was trying to show with my last screenshot, Grafana already lets you override the display name of a field using field overrides. However, that will only change the name of the field. In the screenshot above, I override the price field to orderAdd and orderRemove for each data source query.

The problem you seem to be having is that you'd like to turn the following response:

timestamp name price
1606725384110 orderAdd 2575.5
1606725384110 orderAdd 45.91
1606725384110 orderRemove 12.23

into

timestamp orderAdd orderRemove
1606725384110 2575.5
1606725384110 45.91
1606725384110 12.23

It seems to me that the root of your problem is that you want to convert between Wide and narrow data, which is a more complicated problem than simply changing the display name. Since this is a transformation that you'd want to do for a range of different panels, I'm reluctant to implementing this in this (or any) plugin.

If by "overriding display name", you mean that you want to select another field to use as the field name—essentially rotating part of the table—it's a simplification of the problem I outline above.

I want to emphasize that while I agree that this is a very useful feature, I think it's out of scope for this (any) plugin. I think it more be more suitable to implement this in Grafana itself, and offer the feature to all data sources. Please let me know if I've misunderstood your problem in any way.

from grafana-json-datasource.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.