Feat: Extending report interaction with static context that can be appended to all interaction events (#88927)

* Extending report interaction with static context that can be appended to all requests
pull/90195/head
Timur Olzhabayev 2 years ago committed by GitHub
parent cff9ecbd6d
commit f763f2085b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      conf/defaults.ini
  2. 3
      conf/sample.ini
  3. 1
      packages/grafana-data/src/types/config.ts
  4. 4
      packages/grafana-runtime/src/analytics/utils.ts
  5. 1
      packages/grafana-runtime/src/config.ts
  6. 1
      pkg/api/dtos/frontend_settings.go
  7. 1
      pkg/api/frontendsettings.go
  8. 10
      pkg/setting/setting.go

@ -312,6 +312,9 @@ application_insights_endpoint_url =
# Controls if the UI contains any links to user feedback forms
feedback_links_enabled = true
# Static context that is being added to analytics events
reporting_static_context =
#################################### Security ############################
[security]
# disable creation of admin user on first start of grafana

@ -309,6 +309,9 @@
# Controls if the UI contains any links to user feedback forms
;feedback_links_enabled = true
# Static context that is being added to analytics events
;reporting_static_context = grafanaInstance=12, os=linux
#################################### Security ####################################
[security]
# disable creation of admin user on first start of grafana

@ -232,6 +232,7 @@ export interface GrafanaConfig {
cloudMigrationIsTarget?: boolean;
listDashboardScopesEndpoint?: string;
listScopesEndpoint?: string;
reportingStaticContext?: Record<string, string>;
// The namespace to use for kubernetes apiserver requests
namespace: string;

@ -44,6 +44,10 @@ export const reportPageview = () => {
* @public
*/
export const reportInteraction = (interactionName: string, properties?: Record<string, unknown>) => {
// get static reporting context and append it to properties
if (config.reportingStaticContext && config.reportingStaticContext instanceof Object) {
properties = { ...properties, ...config.reportingStaticContext };
}
getEchoSrv().addEvent<InteractionEchoEvent>({
type: EchoEventType.Interaction,
payload: {

@ -177,6 +177,7 @@ export class GrafanaBootConfig implements GrafanaConfig {
rootFolderUID: string | undefined;
localFileSystemAvailable: boolean | undefined;
cloudMigrationIsTarget: boolean | undefined;
reportingStaticContext?: Record<string, string>;
/**
* Language used in Grafana's UI. This is after the user's preference (or deteceted locale) is resolved to one of

@ -231,6 +231,7 @@ type FrontendSettingsDTO struct {
SupportBundlesEnabled bool `json:"supportBundlesEnabled"`
SnapshotEnabled bool `json:"snapshotEnabled"`
SecureSocksDSProxyEnabled bool `json:"secureSocksDSProxyEnabled"`
ReportingStaticContext map[string]string `json:"reportingStaticContext"`
Azure FrontendSettingsAzureDTO `json:"azure"`

@ -226,6 +226,7 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro
SharedWithMeFolderUID: folder.SharedWithMeFolderUID,
RootFolderUID: accesscontrol.GeneralFolderUID,
LocalFileSystemAvailable: hs.Cfg.LocalFileSystemAvailable,
ReportingStaticContext: hs.Cfg.ReportingStaticContext,
BuildInfo: dtos.FrontendSettingsBuildInfoDTO{
HideVersion: hideVersion,

@ -366,6 +366,7 @@ type Cfg struct {
ApplicationInsightsConnectionString string
ApplicationInsightsEndpointUrl string
FeedbackLinksEnabled bool
ReportingStaticContext map[string]string
// Frontend analytics
GoogleAnalyticsID string
@ -1156,6 +1157,15 @@ func (cfg *Cfg) parseINIFile(iniFile *ini.File) error {
cfg.ApplicationInsightsEndpointUrl = analytics.Key("application_insights_endpoint_url").String()
cfg.FeedbackLinksEnabled = analytics.Key("feedback_links_enabled").MustBool(true)
// parse reporting static context string of key=value, key=value pairs into an object
cfg.ReportingStaticContext = make(map[string]string)
for _, pair := range strings.Split(analytics.Key("reporting_static_context").String(), ",") {
kv := strings.Split(pair, "=")
if len(kv) == 2 {
cfg.ReportingStaticContext[strings.TrimSpace("_static_context_"+kv[0])] = strings.TrimSpace(kv[1])
}
}
if err := cfg.readAlertingSettings(iniFile); err != nil {
return err
}

Loading…
Cancel
Save