Skip to content
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

Cannot unmarshal object into Go struct #130

Open
mpostument opened this issue Mar 5, 2021 · 10 comments · Fixed by #151
Open

Cannot unmarshal object into Go struct #130

mpostument opened this issue Mar 5, 2021 · 10 comments · Fixed by #151

Comments

@mpostument
Copy link

mpostument commented Mar 5, 2021

Hello, have an issue on GetDashboardByUID method. On some dashboards getting errors such as

2021/03/05 13:27:41 unmarshal board: json: cannot unmarshal object into Go struct field TemplateVar.templating.list.query of type string for db/kubernetes-compute-resources-workload
2021/03/05 13:27:42 unmarshal board: json: cannot unmarshal number into Go struct field Board.panels of type string for db/kubernetes-networking-namespace-pods
2021/03/05 13:27:42 unmarshal board: json: cannot unmarshal number into Go struct field Board.panels of type string for db/kubernetes-networking-pod
2021/03/05 13:27:43 unmarshal board: json: cannot unmarshal object into Go struct field TemplateVar.templating.list.query of type string for db/loki-quick-search

And this

2021/03/05 15:48:17 unmarshal board: json: cannot unmarshal number into Go struct field Board.panels of type string for db/auth
2021/03/05 15:48:20 unmarshal board: json: cannot unmarshal object into Go struct field Board.panels of type []struct { Type string "json:\"type,omitempty\""; Params []string "json:\"params,omitempty\"" } for db/aws-cluster
2021/03/05 15:48:30 unmarshal board: json: cannot unmarshal number into Go struct field Board.panels of type string for db/production

Additional details here

@GiedriusS
Copy link
Collaborator

Thanks for your report! Will try looking into it by using your gist. In the mean time help is welcome 🤗

@lukehunter-cs
Copy link

For at least the TemplateVar.templating.list.query issue, I have fixed this in a private fork -- the problem is that prometheus based queries have a different schema, and afaict there is no way to tell what the schema is unless you know the type of the datasource (which you could only do by querying grafana during unmarshalling). I ended up writing something like the following:

func (tv *TemplateVar) UnmarshalJSON(b []byte) (err error) {
	var def TemplateVarDefault
	var prom TemplateVarPrometheus

	if err = json.Unmarshal(b, &def); err == nil {
		tv.TemplateVarDefault = &def
	} else if err = json.Unmarshal(b, &prom); err == nil {
		tv.TemplateVarPrometheus = &prom
	} else {
		return fmt.Errorf("unhandled schema")
	}
	return
}

Unfortunately there are a lot of places in the grafana json that require this type of approach, e.g. the Target struct which changes form in incompatible ways depending on the type of query. I'd be happy to help with some PRs, but the problem is fixes like above are breaking changes to the sdk, so I would want to get agreement on the general approach.

@Noksa
Copy link

Noksa commented Mar 13, 2021

Hello.
Any updates? This issue blocks us.

@mpostument
Copy link
Author

@GiedriusS this issue is still present after #151.

2021/08/11 08:36:27 unmarshal board: json: cannot unmarshal object into Go struct field TemplateVar.templating.list.query of type string for db/kubernetes-networking-workload
2021/08/11 08:36:27 unmarshal board: json: cannot unmarshal object into Go struct field TemplateVar.templating.list.query of type string for db/kubernetes-persistent-volumes
2021/08/11 08:36:27 unmarshal board: json: cannot unmarshal object into Go struct field TemplateVar.templating.list.query of type string for db/kubernetes-pods
2021/08/11 08:36:27 unmarshal board: json: cannot unmarshal object into Go struct field TemplateVar.templating.list.query of type string for db/kubernetes-statefulsets
2021/08/11 08:36:27 unmarshal board: json: cannot unmarshal object into Go struct field TemplateVar.templating.list.query of type string for db/loki-quick-search

Can it be reopened?

@GiedriusS GiedriusS reopened this Sep 21, 2021
@GiedriusS
Copy link
Collaborator

GiedriusS commented Sep 21, 2021

of type string for db/loki-quick-search

Isn't it interface{} now? @mpostument are you using the newest version? Could you please help me out with a test case for this?

@mpostument
Copy link
Author

Last tried on version v0.0.0-20210621184808-90d328319afc
Example of the dashboard where it failing, also save this error on few other providers, I think on elastic search data source

@chenlujjj
Copy link

Same issue, hard to debug

@telmich
Copy link

telmich commented Feb 5, 2022

Hey everyone! I was wondering what the state on this one is, as it blocks to sync dashboards easily.

@dekimsey
Copy link

dekimsey commented Feb 14, 2022

Looks like the cloudwatch datasource also triggers this behavior.

2022/02/14 16:22:25 unmarshal board: json: cannot unmarshal object into Go struct field Board.panels of type []struct { Type string "json:\"type,omitempty\""; Params []string "json:\"params,omitempty\"" } for db/aws-billing
2022/02/14 16:22:25 unmarshal board: json: cannot unmarshal object into Go struct field Board.panels of type []struct { Type string "json:\"type,omitempty\""; Params []string "json:\"params,omitempty\"" } for db/aws-cloudwatch-browser
2022/02/14 16:22:25 unmarshal board: json: cannot unmarshal object into Go struct field Board.panels of type []struct { Type string "json:\"type,omitempty\""; Params []string "json:\"params,omitempty\"" } for db/aws-ebs
2022/02/14 16:22:26 unmarshal board: json: cannot unmarshal object into Go struct field Board.panels of type string for db/aws-elasticsearch
2022/02/14 16:22:26 unmarshal board: json: cannot unmarshal object into Go struct field Board.panels of type []struct { Type string "json:\"type,omitempty\""; Params []string "json:\"params,omitempty\"" } for db/aws-rds
2022/02/14 16:22:26 unmarshal board: json: cannot unmarshal object into Go struct field Board.panels of type []struct { Type string "json:\"type,omitempty\""; Params []string "json:\"params,omitempty\"" } for db/aws-route-53
2022/02/14 16:22:27 unmarshal board: json: cannot unmarshal object into Go struct field Board.panels of type []struct { Type string "json:\"type,omitempty\""; Params []string "json:\"params,omitempty\"" } for db/aws-s3
2022/02/14 16:22:27 unmarshal board: json: cannot unmarshal object into Go struct field Row.rows.panels of type []struct { Type string "json:\"type,omitempty\""; Params []string "json:\"params,omitempty\"" } for db/aws-vpn

Looks like it's a different root cause. This issue is tracking the datasource can be a string or a map in the JSON exports. My report seems to be a different element on the Panels, unfortunately it's not as obvious as I'd like

@titaneric
Copy link

Same here, even try the latest commit 2ff95a7

json: cannot unmarshal object into Go struct field Board.panels of type string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants