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

Query Params unable to have duplicate keys #230

Closed
mikequentel opened this issue Feb 28, 2023 Discussed in #229 · 1 comment
Closed

Query Params unable to have duplicate keys #230

mikequentel opened this issue Feb 28, 2023 Discussed in #229 · 1 comment

Comments

@mikequentel
Copy link

mikequentel commented Feb 28, 2023

Problem

Unable to use duplicate keys in the Query Params user interface.

Expected behaviour

User can have duplicate (even multiple duplicate) keys, so the URL params will be like this:
myparam=valueA&myparam=valueB&myparam=valueC so that a variable represented by myparam []string can be populated.

Observed behaviour

Grafana only passes one of the duplicate keys, like this: myparam=valueC, ignoring the other myparam keys.

Work-around solution

Enable the use of a comma-delimited string for the value; then check for this:

	issueLinkTypeNameExcludes, issueLinkTypeNameExcludesParamExists := c.GetQuery("issueLinkTypeNameExcludes")
	if issueLinkTypeNameExcludesParamExists == true {
		if strings.Contains(issueLinkTypeNameExcludes, ",") {
			qry.IssueLinkTypeNameExcludes = strings.Split(issueLinkTypeNameExcludes, ",")
		}
	}
	issueLinkStatusExcludes, issueLinkStatusExcludesParamExists := c.GetQuery("issueLinkStatusExcludes")
	if issueLinkStatusExcludesParamExists == true {
		if strings.Contains(issueLinkStatusExcludes, ",") {
			qry.IssueLinkStatusExcludes = strings.Split(issueLinkStatusExcludes, ",")
		}
	}

Discussed in #229

Originally posted by mikequentel February 27, 2023
query_params_redacted_results
Is it possible to make the Query Params user interface of Grafana/grafana-csv-datasource accept duplicate keys?

The reason I would like to do this is because I have a web service implemented in Go using Gin that can accept URL parameters that become a list, to populate a struct named Query, where issueLinkTypeNames (for example) can take a list, but this list is typically resolved from URL parameters that are repeated (this appears to be a normal way to do this). This web service successfully returns the CSV when these parameters are passed like this example:

&issueLinkTypeNameExcludes=Relates&issueLinkTypeNameExcludes=Affects

The struct Query that gets populated has some []string fields like this:

package model

type Query struct {
...
	IssueLinkTypeNameExcludes   []string `form:"issueLinkTypeNameExcludes"`
	IssueLinkStatusExcludes     []string `form:"issueLinkStatusExcludes"`
	IssueLinkKeyExcludes        []string `form:"issueLinkKeyExcludes"`
...
}

But the records in Grafana (from grafana-csv-datasource) do not show the expected results because only one of the values of issueLinkTypeNameExcludes is being sent to the web service. This behaviour is definitely happening only through Grafana.

@mikequentel
Copy link
Author

Work-around solution of enabling the Query Param to accept a comma-delimited list is satisfactory. Closing this ticket.

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

No branches or pull requests

1 participant