Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pkg/plugin/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ import (
"golang.org/x/net/proxy"
)

const (
headerDashboardTitle = "X-Dashboard-Title"
headerPanelTitle = "X-Panel-Title"
headerReferer = "Referer"
)

// Clickhouse defines how to connect to a Clickhouse datasource
type Clickhouse struct{}

Expand Down Expand Up @@ -439,6 +445,7 @@ func extractForwardedHeadersFromMessage(message json.RawMessage) (map[string]str
return nil, errors.New("Couldn't parse message as args")
}

var dashboard, panel string
httpHeaders := make(map[string]string)
if grafanaHttpHeaders, ok := messageArgs[sqlds.HeaderKey]; ok {
fwdHeaders, ok := grafanaHttpHeaders.(map[string]interface{})
Expand All @@ -458,9 +465,23 @@ func extractForwardedHeadersFromMessage(message json.RawMessage) (map[string]str
}

httpHeaders[k] = strings.Join(strHeadersArr, ",")

if k == headerDashboardTitle {
dashboard = httpHeaders[k]
}

if k == headerPanelTitle {
panel = httpHeaders[k]
}
}
}

if dashboard != "" || panel != "" {
httpHeaders[headerReferer] = fmt.Sprintf("Dashboard title: %q, panel title: %q", dashboard, panel)
} else {
httpHeaders[headerReferer] = "Explorer"
Copy link
Contributor

Choose a reason for hiding this comment

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

This is technically untrue; the query could also come from alerting. You should be able to validate this by checking the uname from the plugin context for grafana_scheduler.

}

return httpHeaders, nil
}

Expand Down