Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Generate jsonnet from json #3

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

malcolmholmes
Copy link
Collaborator

This is a first pass at generating Jsonnet from a dashboard JSON. It proves the theory. Now it is just a question of working through the remaining issues.

Noted issues include:

  • Dashboard alerts not in the spec
  • targets in spec are prometheus specific, needs fixing
  • axes (xaxis, yaxis, yaxes) need implementing
  • timepicker needs implementing
  • templating needs implementing
  • annotations need to be wrapped in a list element.

@malcolmholmes
Copy link
Collaborator Author

To use this, download a dashboard JSON to sample.json then:

$ make bundle
$ go build .
$ ./dashboard-spec instance 7.0 jsonnet sample.json

@malcolmholmes
Copy link
Collaborator Author

Once the above issues are resolved, a useful test would be to automatically pull a load of dashboards from an active Grafana instance, convert them to Jsonnet, execute the Jsonnet, then diff the original and generated JSON. The differences should only be expected ones.

@malcolmholmes malcolmholmes marked this pull request as draft September 7, 2020 13:21
Copy link
Member

@trotttrotttrott trotttrotttrott left a comment

Choose a reason for hiding this comment

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

Took a first pass.

specs/7.0/Dashboard.yml Show resolved Hide resolved
$ref: '_threshold.yml#/threshold'
$ref: '_thresholds.yml#/thresholds'
Copy link
Member

Choose a reason for hiding this comment

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

Appropriate change, but again could you please move this to a separate pull request?

@@ -49,6 +52,78 @@ func (s Schema) DefaultJSON() string {
return string(b)
}

// IsDefault checks if the value matches the schema's default value
func (s Schema) IsDefault(value interface{}, name string) (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we should get rid of this. Seems to me we can simplify a lot by explicitly setting the value regardless if it's the default or not. We could then do away with TopLevelSimpleNonDefaultProperties and drop the added argument on the filter function.

@@ -108,31 +211,56 @@ func (s Schema) TopLevelObjectProperties() map[string]*Schema {
return p
}

// Returns all nested properties except arrays of objects. It's anticipated
// TopLevelArrayProperties returns all top-level array properties.
func (s Schema) TopLevelArrayProperties() map[string]*Schema {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this?

Comment on lines +226 to 228
//NestedSimpleProperties Returns all nested properties except arrays of objects. It's anticipated
// that the parent schema object is a top-level object property and that the
// properties returned here will be arguments in the parent's setter method.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
//NestedSimpleProperties Returns all nested properties except arrays of objects. It's anticipated
// that the parent schema object is a top-level object property and that the
// properties returned here will be arguments in the parent's setter method.
// NestedSimpleProperties returns all nested properties except arrays of
// objects. It's anticipated that the parent schema object is a top-level
// object property and that the properties returned here will be arguments in
// the parent's setter method.

textwidth=80

return err
}

outFile := strings.ReplaceAll(instanceFile, ".json", "") + ".libsonnet"
Copy link
Member

Choose a reason for hiding this comment

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

Would like to keep the Go code language agnostic.

Comment on lines +74 to +79
"toKey": func(s string) string {
return inflect.CamelizeDownFirst(s)
},
"toCamel": func(s string) string {
return inflect.Camelize(s)
},
Copy link
Member

Choose a reason for hiding this comment

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

Can't we use objectInflection where this might be used?

@CLAassistant
Copy link

CLAassistant commented Jun 15, 2022

CLA assistant check
All committers have signed the CLA.

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.

None yet

3 participants