-
Notifications
You must be signed in to change notification settings - Fork 17
Generate jsonnet from json #3
base: master
Are you sure you want to change the base?
Conversation
To use this, download a dashboard JSON to
|
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. |
There was a problem hiding this 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.
$ref: '_threshold.yml#/threshold' | ||
$ref: '_thresholds.yml#/thresholds' |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
//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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//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" |
There was a problem hiding this comment.
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.
"toKey": func(s string) string { | ||
return inflect.CamelizeDownFirst(s) | ||
}, | ||
"toCamel": func(s string) string { | ||
return inflect.Camelize(s) | ||
}, |
There was a problem hiding this comment.
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?
595fe9b
to
9f97df7
Compare
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:
list
element.