-
Notifications
You must be signed in to change notification settings - Fork 12.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provisioning: Fix unmarshaling nested jsonData values #20399
Conversation
func tranformInterface(i interface{}) interface{} { | ||
// map or slice value instead of modifying them in place and also return value without interpolation but with converted | ||
// type as a second value. | ||
func transformInterface(i interface{}) (interface{}, interface{}) { |
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.
Returning 2 values so that both raw value and value which was interpolated has the same types and there is no discrepancy. Also non string keys will be dropped (should not happen but yaml technically allows non string keys afaik) which would also create a difference in raw vs interpolated value.
@marefr Although the bug itself is old, I added this to current beta because with the derived fields feature in Loki we need a nested jsonData to make that provision-able. |
With a docker image that contains this fix, I had issues with template variables in the url field of this YAML below. The docker image SHA used is: sha256:37e71eaf4076d43a30e44c3c7b9a048c7a8086675f1c2d5b53962a97613b38b3 apiVersion: 1
datasources:
- name: Loki
type: loki
access: proxy
url: http://loki:3100
basicAuth: false
jsonData:
maxLines: 1000
derivedFields:
- matcherRegex: ".*trace_id=(.*?)\\s.*"
name: "TraceId"
url: "http://localhost:16686/trace/${__value.raw}" |
@wardbekker solution is here: https://grafana.com/docs/administration/provisioning/#using-environment-variables So you want to use apiVersion: 1
datasources:
- name: Loki
type: loki
access: proxy
url: http://loki:3100
basicAuth: false
jsonData:
maxLines: 1000
derivedFields:
- matcherRegex: ".*trace_id=(.*?)\\s.*"
name: "TraceId"
url: "http://localhost:16686/trace/$${__value.raw}" |
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.
Great 👍 LGTM
Problem was that yaml unmarshal returned nested maps as map[interface{}]interface{} which are then not marshal-able to json because of that interface{} key type. This adds explicit casting of the keys in the yaml value types to string which then makes the values marshal-able to JSON in DB. Fixes: #11537 (cherry picked from commit 3f144bd)
Problem was that yaml unmarshal returned nested maps as map[interface{}]interface{} which are then not marshal-able to json because of that interface{} key type. This adds explicit casting of the keys in the yaml value types to string which then makes the values marshal-able to JSON in DB. Fixes: #11537 (cherry picked from commit 3f144bd)
Fixes: #11537
Problem was that yaml un-marshal returned nested maps as
map[interface{}]interface{}
which are then not marshal-able to json because of thatinterface{}
key type. This adds explicit casting of the keys in the yaml value types to string which then makes the values marshal-able to JSON in DB.