Tool for generating grafanalib dashboards from JSON
jml opened this issue · 9 comments
For people getting started with grafanalib, it would be helpful to have a way of converting JSON dashboards into grafanalib ones.
Since grafanalib doesn't yet support everything grafana does, when the tool encounters an unsupported feature, it should fail with a friendly message encouraging the user to file a bug.
I've tried some brute force in here (needs proper error handling, especially when an unknown feature is encountered) works for a simple dashboard. Would this be a completely wrong approach?
Thanks!
I think this is a great start. Some thoughts:
- The
handleFoo
functions could instead be classmethods (from_json_data
?parse_json_data
?) on the respectiveFoo
classes - Now that we've got a JSON generator and a JSON parser, we absolutely should have tests that use hypothesis
- I'm not 100% sure, but I think that rather than having one big if/else to guess the type, we could instead exploit our knowledge of the structure of dashboards, e.g.
Dashboard.from_json_data
knows that the way to parse the value of therows
key is to useRow.from_json_data
—does this make sense? - To fully close off this ticket, we would also need methods that output the Python definitions of the objects. That ought to be done as a separate change, since it's independent of parsing from JSON.
Let me know if you have any questions. Thanks again for contributing!
Absolutely should move to classmethods (staticmethods) parse_json_data
(actually started there but moved into one file for convenience)
I was thinking of going the other route too.I think my reasoning was to get called only for objects
(dicts) and that I don't have to loop trough keys and values. Then I discovered later I need to parse other things too (eg. RGB
, px
etc) so no way to avoid going trough keys and values (to detect unknown features, for known it's easy as I now what type of object is under which key). I can try and see how it compares (it should actually be simpler)
It looks a bit better. It's more verbose but there is no magic. Still needs work, especially tests.
Thanks! I just got back from vacation. Will take a look at this soon.
Is anyone involved in the development of this feature now?
Not that I am aware of, but it is defiantly a feature we would like to add to the library.
Is it something you would like to contribute to?
I really need this feature, but I don’t have time to develop this feature at the moment. If I have time later, I'll consider it.