2021-04-21 08:38:00 +01:00
|
|
|
import { merge } from 'lodash';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2020-04-20 07:37:38 +02:00
|
|
|
import {
|
2022-09-15 18:06:09 +02:00
|
|
|
AuthSettings,
|
2022-03-30 10:48:58 +01:00
|
|
|
BootData,
|
2020-06-04 13:44:48 +02:00
|
|
|
BuildInfo,
|
2020-04-20 07:37:38 +02:00
|
|
|
DataSourceInstanceSettings,
|
2020-06-04 13:44:48 +02:00
|
|
|
FeatureToggles,
|
|
|
|
|
GrafanaConfig,
|
2020-04-20 07:37:38 +02:00
|
|
|
GrafanaTheme,
|
2021-05-03 09:45:54 +02:00
|
|
|
GrafanaTheme2,
|
2020-04-20 07:37:38 +02:00
|
|
|
LicenseInfo,
|
2021-07-21 10:20:30 -07:00
|
|
|
MapLayerOptions,
|
2022-02-11 13:54:24 +00:00
|
|
|
OAuthSettings,
|
2020-06-04 13:44:48 +02:00
|
|
|
PanelPluginMeta,
|
2020-09-07 16:19:33 +02:00
|
|
|
systemDateFormats,
|
|
|
|
|
SystemDateFormatSettings,
|
2023-05-10 15:37:04 +02:00
|
|
|
getThemeById,
|
2023-11-10 11:44:54 +01:00
|
|
|
AngularMeta,
|
2020-04-20 07:37:38 +02:00
|
|
|
} from '@grafana/data';
|
2019-06-19 11:31:47 -07:00
|
|
|
|
2021-05-12 07:23:37 -07:00
|
|
|
export interface AzureSettings {
|
|
|
|
|
cloud?: string;
|
|
|
|
|
managedIdentityEnabled: boolean;
|
2023-09-28 04:05:16 -07:00
|
|
|
workloadIdentityEnabled: boolean;
|
2023-05-15 10:00:54 -07:00
|
|
|
userIdentityEnabled: boolean;
|
2021-05-12 07:23:37 -07:00
|
|
|
}
|
|
|
|
|
|
2023-02-07 17:20:05 +01:00
|
|
|
export type AppPluginConfig = {
|
|
|
|
|
id: string;
|
|
|
|
|
path: string;
|
|
|
|
|
version: string;
|
|
|
|
|
preload: boolean;
|
2023-11-10 11:44:54 +01:00
|
|
|
angular: AngularMeta;
|
2023-02-07 17:20:05 +01:00
|
|
|
};
|
|
|
|
|
|
2020-04-20 07:37:38 +02:00
|
|
|
export class GrafanaBootConfig implements GrafanaConfig {
|
2023-08-25 20:56:02 +02:00
|
|
|
publicDashboardAccessToken?: string;
|
2023-12-19 11:43:54 +01:00
|
|
|
publicDashboardsEnabled = true;
|
2023-01-26 10:28:11 -03:00
|
|
|
snapshotEnabled = true;
|
2019-06-19 11:31:47 -07:00
|
|
|
datasources: { [str: string]: DataSourceInstanceSettings } = {};
|
|
|
|
|
panels: { [key: string]: PanelPluginMeta } = {};
|
2023-02-07 17:20:05 +01:00
|
|
|
apps: Record<string, AppPluginConfig> = {};
|
2022-09-15 18:06:09 +02:00
|
|
|
auth: AuthSettings = {};
|
2020-02-28 14:32:01 +01:00
|
|
|
minRefreshInterval = '';
|
2020-06-16 16:33:44 +03:00
|
|
|
appUrl = '';
|
2019-06-19 11:31:47 -07:00
|
|
|
appSubUrl = '';
|
2023-11-13 20:34:09 -08:00
|
|
|
namespace = 'default';
|
2019-06-19 11:31:47 -07:00
|
|
|
windowTitlePrefix = '';
|
2022-03-30 10:48:58 +01:00
|
|
|
buildInfo: BuildInfo;
|
2019-06-19 11:31:47 -07:00
|
|
|
newPanelTitle = '';
|
2022-03-30 10:48:58 +01:00
|
|
|
bootData: BootData;
|
2019-06-19 11:31:47 -07:00
|
|
|
externalUserMngLinkUrl = '';
|
|
|
|
|
externalUserMngLinkName = '';
|
|
|
|
|
externalUserMngInfo = '';
|
|
|
|
|
allowOrgCreate = false;
|
2022-04-14 15:18:03 +02:00
|
|
|
feedbackLinksEnabled = true;
|
2019-06-19 11:31:47 -07:00
|
|
|
disableLoginForm = false;
|
2021-10-29 10:57:24 -07:00
|
|
|
defaultDatasource = ''; // UID
|
2019-06-19 11:31:47 -07:00
|
|
|
alertingEnabled = false;
|
|
|
|
|
alertingErrorOrTimeout = '';
|
|
|
|
|
alertingNoDataOrNullValues = '';
|
2020-01-14 11:13:34 +02:00
|
|
|
alertingMinInterval = 1;
|
2022-02-16 17:14:33 +01:00
|
|
|
angularSupportEnabled = false;
|
2019-06-19 11:31:47 -07:00
|
|
|
authProxyEnabled = false;
|
|
|
|
|
exploreEnabled = false;
|
2022-04-26 11:15:08 +02:00
|
|
|
queryHistoryEnabled = false;
|
2022-03-29 10:27:53 -05:00
|
|
|
helpEnabled = false;
|
|
|
|
|
profileEnabled = false;
|
2023-06-01 14:35:05 +02:00
|
|
|
newsFeedEnabled = true;
|
2019-06-19 11:31:47 -07:00
|
|
|
ldapEnabled = false;
|
2022-07-27 14:10:47 +00:00
|
|
|
jwtHeaderName = '';
|
|
|
|
|
jwtUrlLogin = false;
|
2020-10-08 10:03:20 +02:00
|
|
|
sigV4AuthEnabled = false;
|
2022-08-11 16:12:57 +02:00
|
|
|
azureAuthEnabled = false;
|
2023-04-18 12:11:23 -05:00
|
|
|
secureSocksDSProxyEnabled = false;
|
2019-07-05 15:24:52 +02:00
|
|
|
samlEnabled = false;
|
2021-10-04 09:58:16 -03:00
|
|
|
samlName = '';
|
2020-02-17 11:13:13 +01:00
|
|
|
autoAssignOrg = true;
|
|
|
|
|
verifyEmailEnabled = false;
|
2022-02-11 13:54:24 +00:00
|
|
|
oauth: OAuthSettings = {};
|
2022-05-16 03:45:41 -07:00
|
|
|
rbacEnabled = true;
|
2019-06-19 11:31:47 -07:00
|
|
|
disableUserSignUp = false;
|
2022-03-30 10:48:58 +01:00
|
|
|
loginHint = '';
|
|
|
|
|
passwordHint = '';
|
2023-07-25 10:57:45 +01:00
|
|
|
loginError: string | undefined = undefined;
|
2019-06-19 11:31:47 -07:00
|
|
|
viewersCanEdit = false;
|
|
|
|
|
editorsCanAdmin = false;
|
|
|
|
|
disableSanitizeHtml = false;
|
2023-04-27 18:20:37 +02:00
|
|
|
trustedTypesDefaultPolicyEnabled = false;
|
|
|
|
|
cspReportOnlyEnabled = false;
|
2021-05-27 22:03:18 +03:00
|
|
|
liveEnabled = true;
|
2022-08-08 16:37:06 +01:00
|
|
|
/** @deprecated Use `theme2` instead. */
|
2019-06-19 11:31:47 -07:00
|
|
|
theme: GrafanaTheme;
|
2021-05-03 09:45:54 +02:00
|
|
|
theme2: GrafanaTheme2;
|
2022-01-11 16:18:54 -08:00
|
|
|
featureToggles: FeatureToggles = {};
|
2023-03-09 16:42:45 +00:00
|
|
|
anonymousEnabled = false;
|
2023-12-18 09:32:57 +01:00
|
|
|
anonymousDeviceLimit: number | undefined = undefined;
|
2020-01-17 15:44:12 +01:00
|
|
|
licenseInfo: LicenseInfo = {} as LicenseInfo;
|
2020-04-15 22:17:41 +02:00
|
|
|
rendererAvailable = false;
|
2021-06-04 13:33:49 +02:00
|
|
|
rendererVersion = '';
|
2024-02-26 17:57:34 +05:30
|
|
|
rendererDefaultImageWidth = 1000;
|
|
|
|
|
rendererDefaultImageHeight = 500;
|
|
|
|
|
rendererDefaultImageScale = 1;
|
2022-06-29 08:48:23 -04:00
|
|
|
secretsManagerPluginEnabled = false;
|
2023-01-23 16:23:20 +00:00
|
|
|
supportBundlesEnabled = false;
|
2020-08-20 02:32:10 -07:00
|
|
|
http2Enabled = false;
|
2020-09-07 16:19:33 +02:00
|
|
|
dateFormats?: SystemDateFormatSettings;
|
2022-06-28 09:25:30 +02:00
|
|
|
grafanaJavascriptAgent = {
|
|
|
|
|
enabled: false,
|
|
|
|
|
customEndpoint: '',
|
|
|
|
|
apiKey: '',
|
|
|
|
|
errorInstrumentalizationEnabled: true,
|
|
|
|
|
consoleInstrumentalizationEnabled: false,
|
|
|
|
|
webVitalsInstrumentalizationEnabled: false,
|
|
|
|
|
};
|
2021-05-20 01:42:26 -07:00
|
|
|
pluginCatalogURL = 'https://grafana.com/grafana/plugins/';
|
2021-09-30 08:34:03 +02:00
|
|
|
pluginAdminEnabled = true;
|
2021-05-27 12:45:06 +02:00
|
|
|
pluginAdminExternalManageEnabled = false;
|
2021-11-15 15:51:16 +01:00
|
|
|
pluginCatalogHiddenPlugins: string[] = [];
|
2023-01-27 15:08:17 +01:00
|
|
|
pluginsCDNBaseURL = '';
|
2021-01-22 19:27:33 +02:00
|
|
|
expressionsEnabled = false;
|
2022-09-15 18:06:09 +02:00
|
|
|
customTheme?: undefined;
|
2021-02-25 09:56:42 +01:00
|
|
|
awsAllowedAuthProviders: string[] = [];
|
|
|
|
|
awsAssumeRoleEnabled = false;
|
2021-05-12 07:23:37 -07:00
|
|
|
azure: AzureSettings = {
|
|
|
|
|
managedIdentityEnabled: false,
|
2023-09-28 04:05:16 -07:00
|
|
|
workloadIdentityEnabled: false,
|
2023-05-15 10:00:54 -07:00
|
|
|
userIdentityEnabled: false,
|
2021-05-12 07:23:37 -07:00
|
|
|
};
|
2021-05-26 12:27:28 -05:00
|
|
|
caching = {
|
|
|
|
|
enabled: false,
|
|
|
|
|
};
|
2021-07-21 13:48:20 -07:00
|
|
|
geomapDefaultBaseLayerConfig?: MapLayerOptions;
|
2021-07-21 10:20:30 -07:00
|
|
|
geomapDisableCustomBaseLayer?: boolean;
|
2021-09-29 17:16:40 +03:00
|
|
|
unifiedAlertingEnabled = false;
|
2023-05-25 15:09:44 +02:00
|
|
|
unifiedAlerting = {
|
|
|
|
|
minInterval: '',
|
|
|
|
|
alertStateHistoryBackend: undefined,
|
|
|
|
|
alertStateHistoryPrimary: undefined,
|
|
|
|
|
};
|
2021-09-15 13:00:38 +02:00
|
|
|
applicationInsightsConnectionString?: string;
|
|
|
|
|
applicationInsightsEndpointUrl?: string;
|
2021-11-15 14:04:45 -07:00
|
|
|
recordedQueries = {
|
2022-01-27 11:09:39 -05:00
|
|
|
enabled: true,
|
2021-11-15 14:04:45 -07:00
|
|
|
};
|
2022-01-12 15:37:16 +01:00
|
|
|
featureHighlights = {
|
|
|
|
|
enabled: false,
|
|
|
|
|
};
|
2022-03-22 14:30:45 -06:00
|
|
|
reporting = {
|
|
|
|
|
enabled: true,
|
|
|
|
|
};
|
2023-11-09 11:53:20 +01:00
|
|
|
analytics = {
|
|
|
|
|
enabled: true,
|
|
|
|
|
};
|
2022-06-22 09:27:55 +01:00
|
|
|
googleAnalyticsId: undefined;
|
2022-09-20 11:13:14 +01:00
|
|
|
googleAnalytics4Id: undefined;
|
2022-11-09 15:09:19 +01:00
|
|
|
googleAnalytics4SendManualPageViews = false;
|
2022-06-22 09:27:55 +01:00
|
|
|
rudderstackWriteKey: undefined;
|
|
|
|
|
rudderstackDataPlaneUrl: undefined;
|
|
|
|
|
rudderstackSdkUrl: undefined;
|
|
|
|
|
rudderstackConfigUrl: undefined;
|
2023-10-23 08:43:33 -04:00
|
|
|
rudderstackIntegrationsUrl: undefined;
|
2023-04-28 13:23:08 +07:00
|
|
|
sqlConnectionLimits = {
|
|
|
|
|
maxOpenConns: 100,
|
|
|
|
|
maxIdleConns: 100,
|
|
|
|
|
connMaxLifetime: 14400,
|
|
|
|
|
};
|
2019-06-19 11:31:47 -07:00
|
|
|
|
2022-11-22 10:08:40 +01:00
|
|
|
tokenExpirationDayLimit: undefined;
|
2023-07-05 11:16:56 +02:00
|
|
|
disableFrontendSandboxForPlugins: string[] = [];
|
2024-01-15 10:56:31 +00:00
|
|
|
sharedWithMeFolderUID: string | undefined;
|
2024-02-15 16:13:14 +00:00
|
|
|
rootFolderUID: string | undefined;
|
2024-03-01 10:39:50 +01:00
|
|
|
localFileSystemAvailable: boolean | undefined;
|
2022-11-22 10:08:40 +01:00
|
|
|
|
2019-06-19 11:31:47 -07:00
|
|
|
constructor(options: GrafanaBootConfig) {
|
2022-03-30 10:48:58 +01:00
|
|
|
this.bootData = options.bootData;
|
2019-06-19 11:31:47 -07:00
|
|
|
|
|
|
|
|
const defaults = {
|
|
|
|
|
datasources: {},
|
|
|
|
|
windowTitlePrefix: 'Grafana - ',
|
|
|
|
|
panels: {},
|
|
|
|
|
newPanelTitle: 'Panel Title',
|
|
|
|
|
playlist_timespan: '1m',
|
|
|
|
|
unsaved_changes_warning: true,
|
2020-06-16 16:33:44 +03:00
|
|
|
appUrl: '',
|
2019-06-19 11:31:47 -07:00
|
|
|
appSubUrl: '',
|
|
|
|
|
buildInfo: {
|
2022-04-07 16:17:37 +02:00
|
|
|
version: '1.0',
|
2019-06-19 11:31:47 -07:00
|
|
|
commit: '1',
|
|
|
|
|
env: 'production',
|
|
|
|
|
},
|
|
|
|
|
viewersCanEdit: false,
|
|
|
|
|
editorsCanAdmin: false,
|
|
|
|
|
disableSanitizeHtml: false,
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-15 10:54:52 +02:00
|
|
|
merge(this, defaults, options);
|
2020-09-07 16:19:33 +02:00
|
|
|
|
2022-04-07 16:17:37 +02:00
|
|
|
this.buildInfo = options.buildInfo || defaults.buildInfo;
|
|
|
|
|
|
2020-09-07 16:19:33 +02:00
|
|
|
if (this.dateFormats) {
|
|
|
|
|
systemDateFormats.update(this.dateFormats);
|
|
|
|
|
}
|
2022-06-09 02:42:38 -07:00
|
|
|
|
2023-06-28 14:39:23 +02:00
|
|
|
if (this.buildInfo.env === 'development') {
|
|
|
|
|
overrideFeatureTogglesFromUrl(this);
|
|
|
|
|
}
|
2022-07-14 20:34:00 +02:00
|
|
|
|
2023-07-18 09:25:52 +02:00
|
|
|
overrideFeatureTogglesFromLocalStorage(this);
|
|
|
|
|
|
2023-03-23 08:43:45 -07:00
|
|
|
if (this.featureToggles.disableAngular) {
|
|
|
|
|
this.angularSupportEnabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-01 11:59:37 +00:00
|
|
|
// Creating theme after applying feature toggle overrides in case we need to toggle anything
|
2023-05-10 15:37:04 +02:00
|
|
|
this.theme2 = getThemeById(this.bootData.user.theme);
|
|
|
|
|
this.bootData.user.lightTheme = this.theme2.isLight;
|
2022-10-15 16:22:33 +02:00
|
|
|
this.theme = this.theme2.v1;
|
2022-06-09 02:42:38 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-18 09:25:52 +02:00
|
|
|
// localstorage key: grafana.featureToggles
|
|
|
|
|
// example value: panelEditor=1,panelInspector=1
|
|
|
|
|
function overrideFeatureTogglesFromLocalStorage(config: GrafanaBootConfig) {
|
|
|
|
|
const featureToggles = config.featureToggles;
|
|
|
|
|
const localStorageKey = 'grafana.featureToggles';
|
|
|
|
|
const localStorageValue = window.localStorage.getItem(localStorageKey);
|
|
|
|
|
if (localStorageValue) {
|
|
|
|
|
const features = localStorageValue.split(',');
|
|
|
|
|
for (const feature of features) {
|
|
|
|
|
const [featureName, featureValue] = feature.split('=');
|
|
|
|
|
const toggleState = featureValue === 'true' || featureValue === '1';
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
|
|
|
featureToggles[featureName as keyof FeatureToggles] = toggleState;
|
|
|
|
|
console.log(`Setting feature toggle ${featureName} = ${toggleState} via localstorage`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-09 02:42:38 -07:00
|
|
|
function overrideFeatureTogglesFromUrl(config: GrafanaBootConfig) {
|
|
|
|
|
if (window.location.href.indexOf('__feature') === -1) {
|
|
|
|
|
return;
|
2019-06-19 11:31:47 -07:00
|
|
|
}
|
2022-06-09 02:42:38 -07:00
|
|
|
|
|
|
|
|
const params = new URLSearchParams(window.location.search);
|
|
|
|
|
params.forEach((value, key) => {
|
|
|
|
|
if (key.startsWith('__feature.')) {
|
2023-03-14 10:47:32 -07:00
|
|
|
const featureToggles = config.featureToggles as Record<string, boolean>;
|
2022-06-09 02:42:38 -07:00
|
|
|
const featureName = key.substring(10);
|
2023-04-26 21:28:58 -05:00
|
|
|
const toggleState = value === 'true' || value === ''; // browser rewrites true as ''
|
2023-03-14 10:47:32 -07:00
|
|
|
if (toggleState !== featureToggles[key]) {
|
|
|
|
|
featureToggles[featureName] = toggleState;
|
2023-07-18 09:25:52 +02:00
|
|
|
console.log(`Setting feature toggle ${featureName} = ${toggleState} via url`);
|
2022-06-09 02:42:38 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-06-19 11:31:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bootData = (window as any).grafanaBootData || {
|
|
|
|
|
settings: {},
|
|
|
|
|
user: {},
|
2020-02-13 16:06:45 +01:00
|
|
|
navTree: [],
|
2019-06-19 11:31:47 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const options = bootData.settings;
|
|
|
|
|
options.bootData = bootData;
|
|
|
|
|
|
2020-04-15 10:46:51 +02:00
|
|
|
/**
|
|
|
|
|
* Use this to access the {@link GrafanaBootConfig} for the current running Grafana instance.
|
|
|
|
|
*
|
|
|
|
|
* @public
|
|
|
|
|
*/
|
2019-06-19 11:31:47 -07:00
|
|
|
export const config = new GrafanaBootConfig(options);
|