Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Pass additional json data #104

Closed
wants to merge 4 commits into from

Conversation

simPod
Copy link
Contributor

@simPod simPod commented Jul 22, 2018

Built on top of #103

Adds another field to targets setup, that allows to pass additional json data with target

@andig
Copy link
Contributor

andig commented Jul 23, 2018

@simPod I couldn't find out immediately- where can I find the additional json option? Per Panel??

@simPod
Copy link
Contributor Author

simPod commented Jul 23, 2018

@andig
Copy link
Contributor

andig commented Jul 23, 2018

This one?

screen shot 2018-07-23 at 22 56 22

Should I enter a json object here? Its not entirely obvious ;)

Alternatively- might it make sense to allow selecting tags/values? Must admit that I haven't found where Grafana actually uses the tag keys/values api :/

@simPod
Copy link
Contributor Author

simPod commented Jul 23, 2018

Yup, that one is for entering your json you want to add to the request.

Not sure how tags/values are related here. Can you be more specific please? I made this column to pass additional data to the request.

For example, my use case is that I control Grafana via API, that means I specify all dashboards and panels via objects and then just run the sync command to synchronize the schema. The panels definition is therefore shared through dashboards but for different dashboards, I want the panels to make slightly different requests and that is achieved by configuring this field per dashboard if needed.

@andig
Copy link
Contributor

andig commented Jul 30, 2018

I've meanwhile tested and its working like a charm. The thing I don't like so much is the UI- a very small, non-obvious text field. I had two ideas:

  • use the tags/values (that a datasource can provide or that you can define manually per dashboard) and allow passing tags+tag values per query (would look cleaner, I'd be happy to share a screenshot)
  • modify the data field into something like a button (maybe {json}) and a larger popup for enterying (plus syntax check if you want)

I can understand if that doesn't sound attractive given zero feedback :(

@simPod
Copy link
Contributor Author

simPod commented Aug 2, 2018

Yup, the UI sucks but I didn't want to pimp it without any feedback from repo maintainers.

I can't imagine the tags/values, can you share the screenshot? Larger field was something I rather had on my mind.

@andig
Copy link
Contributor

andig commented Aug 3, 2018

I can't imagine the tags/values, can you share the screenshot

Sorry for the delay.

Here are the tags- manual definition (if not supplied by the json data source)- UI.

screen shot 2018-08-03 at 16 32 47

Selection UI on dashboard level:

screen shot 2018-08-03 at 16 32 22

That UI might be something that could be done per panel in the settings to override dashboard-wide tags or define additional ones?

Here's how the json looks, it becomes part of the target:

{
  "timezone": "browser",
  "panelId": 6,
  "dashboardId": 1,

  "targets": [
    {
      "target": "19f2ef70-d39e-11e7-b2e8-f552c3dac8a7",
      "data": {
        "mode": "consumption",
        "group": "hour"
      },
      "refId": "A",
      "type": "timeseries"
    },
    {
      "target": "0f746430-d39e-11e7-9f92-2f38b410ecdc",
      "data": {
        "mode": "consumption",
        "group": "hour"
      },
      "refId": "B",
      "type": "timeseries"
    }
  ],
  "maxDataPoints": 1152,

  "adhocFilters": []
}

@simPod
Copy link
Contributor Author

simPod commented Aug 6, 2018

Personally, I didn't want to lock it to dashboard-defined variables only, I wanted the full flexibility so for me the second option is viable

modify the data field into something like a button (maybe {json}) and a larger popup for enterying (plus syntax check if you want)

But since no one still cares I'll wait ;)

@andig
Copy link
Contributor

andig commented Aug 6, 2018

But since no one still cares I'll wait ;)

Yeah :( I've been wondering if you might consider a "hard" fork and publish grafana-json on your own? It's MIT license and I'd appreciate a working version more than months-old PRs :)

Btw., I have another use case for a JSON plugin: extract definable parts from arbitrary JSON sources. That is- instead of talking to a grafana-conforming json source- talk to any JSON endpoint and define patterns for extracting metrics, annotations and data. The forecast.io API might be a good candicate for that. WDYT?

@andig
Copy link
Contributor

andig commented Aug 6, 2018

Personally, I didn't want to lock it to dashboard-defined variables only, I wanted the full flexibility so for me the second option is viable

And I forgot to mention that tags/values (=dashboard variables) are retrievable using the JSON datasource through the tags-keys|values api.

@simPod
Copy link
Contributor Author

simPod commented Aug 6, 2018

@andig maybe having both options would work as well 🤔

@daniellee @DanCech @bergquist Hi, trying a one more ping so we know the repository is abandonded by Grafana Labs or not. Thanks!

@andig andig mentioned this pull request Aug 9, 2018
@andig
Copy link
Contributor

andig commented Aug 9, 2018

@simPod found a small issue with your current implementation. If additional data is defined and the cleared again, its still being sent to the datasource, apparently as empty string instead of being omitted. Would be nicer to drop entirely instead when trimmed json is empty string.

@andig
Copy link
Contributor

andig commented Aug 10, 2018

@simPod I finally discovered a JSON/SQL editor control but couldn't get it working immediately- maybe you'd want to take another look: https://github.com/grafana/grafana/blob/master/public/app/partials/edit_json.html#L14

@simPod
Copy link
Contributor Author

simPod commented Aug 10, 2018

I'll try to take a look @ it asap

@andig
Copy link
Contributor

andig commented Aug 12, 2018

Here are the component's docs. I still think it would be nice if we could also expose tags and values as dropdown options per panal for transfer in data.tags.

@andig
Copy link
Contributor

andig commented Aug 13, 2018

@simPod finally got it working- you could use this gist:

screen shot 2018-08-13 at 13 38 46

Still need to ensure though that data is not null:

    this.target.data = this.target.data || "";

Would be great to omit data from the query if it's json amounts to an empty string.

@andig
Copy link
Contributor

andig commented Sep 30, 2018

This PR has been migrated to https://github.com/simPod/grafana-json-datasource and can be closed.

@daniellee
Copy link
Contributor

@andig @simPod I am also not really sure if we want this PR in SimpleJson so maybe it is best if you focus on your datasource. Once you get to the stage where you need an extra json field then it usually gets specific to what you are building and in my experience is time to fork this into a new plugin. I will double check with my team on what they think about this.

We can publish https://github.com/simPod/grafana-json-datasource on Grafana.com if you want.

@andig
Copy link
Contributor

andig commented Sep 30, 2018

I am also not really sure if we want this PR in SimpleJson so maybe it is best if you focus on your datasource.

I think thats fine as we've made good progress with the new JSON datasource I've linked.

Once you get to the stage where you need an extra json field then it usually gets specific to what you are building and in my experience is time to fork this into a new plugin. I will double check with my team on what they think about this.

Sort of. The ability to pass additional JSON does actually prevent me from needing to develop a specific plugin. The use case looks like:

  • backend (with rest api)
  • backend json adapter (which speaks "simple json" but needs additional steering information)
  • simple json data source plus additional json payload

The effort of adding a little payload is very minor compared to writing a whole new plugin that needs to be maintained.

@simPod
Copy link
Contributor Author

simPod commented Sep 30, 2018

Yup, for me as well. I control Grafana via it's API, I define dashboard and panel models in PHP and don't even use any Edit interface within Grafana.

Additional JSON field allows me to parametrize Panels data per dashboard, sometimes it comes very handy.

@torkelo
Copy link
Member

torkelo commented Nov 7, 2018

This looks like a useful addition but it's built ontop of a breaking change (#103) which makes it tricky to merge

@andig
Copy link
Contributor

andig commented Nov 7, 2018

This can be closed, we have forked now.

@rfogel
Copy link

rfogel commented Jan 24, 2019

Hello. I´m in need to pass addidition json data using variables. Is that possible? Something like this:

{"fieldName":$variable}

@simPod
Copy link
Contributor Author

simPod commented Jan 24, 2019

Forked version https://grafana.com/plugins/simpod-json-datasource has this feature

@rfogel
Copy link

rfogel commented Jan 24, 2019

I'm already using this version. How can I achieve that? This code i shown gives json format error

@simPod
Copy link
Contributor Author

simPod commented Jan 24, 2019

Oh I see. "using variables" We're not parsing variables there yet unfortunately.

There's an issue already opened for that simPod/GrafanaJsonDatasource#11

@rfogel
Copy link

rfogel commented Jan 24, 2019

Ok, thanks for the information.

@mankoffs
Copy link

mankoffs commented Feb 6, 2019

@simPod Hello. Is there any update about issue with parsing variables? It's very necessary feature.

@simPod
Copy link
Contributor Author

simPod commented Feb 7, 2019

Hi @mankoffs, I intend to have such feature here. However, I'm currently busy with my work and finishing other OSS. I'll be able to look into it when I have a task concerning Grafana in my work. You can send PR, I will do review ASAP.

@simPod
Copy link
Contributor Author

simPod commented Feb 12, 2019

@mankoffs resolved in simPod/GrafanaJsonDatasource#26

@simPod simPod closed this Feb 12, 2019
@simPod simPod deleted the pass-additional-json-data branch February 12, 2019 22:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants