mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Datasources: Add toggle to control default behaviour of 'Manage alerts via Alerts UI' toggle (#98441)
* Datasources: Add toggle to control default behaviour of 'Manage alerts via Alerts UI' toggle * Update documentation with suggestions Co-authored-by: Larissa Wandzura <126723338+lwandz13@users.noreply.github.com>
This commit is contained in:
@@ -462,6 +462,9 @@ datasource_limit = 5000
|
|||||||
# Check datasource documentations for enabling concurrency.
|
# Check datasource documentations for enabling concurrency.
|
||||||
concurrent_query_count = 10
|
concurrent_query_count = 10
|
||||||
|
|
||||||
|
# Default behavior for the "Manage alerts via Alerting UI" toggle when configuring a data source.
|
||||||
|
# It only works if the data source's `jsonData.manageAlerts` prop does not contain a previously configured value.
|
||||||
|
default_manage_alerts_ui_toggle = true
|
||||||
|
|
||||||
################################### SQL Data Sources #####################
|
################################### SQL Data Sources #####################
|
||||||
[sql_datasources]
|
[sql_datasources]
|
||||||
|
|||||||
@@ -466,6 +466,10 @@
|
|||||||
# Check datasource documentations for enabling concurrency.
|
# Check datasource documentations for enabling concurrency.
|
||||||
;concurrent_query_count = 10
|
;concurrent_query_count = 10
|
||||||
|
|
||||||
|
# Default behavior for the "Manage alerts via Alerting UI" toggle when configuring a data source.
|
||||||
|
# It only works if the data source's `jsonData.manageAlerts` prop does not contain a previously configured value.
|
||||||
|
;default_manage_alerts_ui_toggle = true
|
||||||
|
|
||||||
################################### SQL Data Sources #####################
|
################################### SQL Data Sources #####################
|
||||||
[sql_datasources]
|
[sql_datasources]
|
||||||
# Default maximum number of open connections maintained in the connection pool
|
# Default maximum number of open connections maintained in the connection pool
|
||||||
|
|||||||
@@ -117,9 +117,15 @@ Following are additional configuration options.
|
|||||||
|
|
||||||
- **Manage alerts via Alerting UI** - Toggle to enable `Alertmanager` integration for this data source.
|
- **Manage alerts via Alerting UI** - Toggle to enable `Alertmanager` integration for this data source.
|
||||||
|
|
||||||
|
{{% admonition type="note" %}}
|
||||||
|
|
||||||
|
The **Manage alerts via Alerting UI** toggle is enabled by default. You can change this behavior by setting the [default_manage_alerts_ui_toggle]({{< relref "../../setup-grafana/configure-grafana/#default_manage_alerts_ui_toggle" >}}) option in the Grafana configuration file.
|
||||||
|
|
||||||
|
{{% /admonition %}}
|
||||||
|
|
||||||
### Interval behavior
|
### Interval behavior
|
||||||
|
|
||||||
- **Scrape interval** - Set this to the typical scrape and evaluation interval configured in Prometheus. The default is `15s`.
|
- **Scrape interval** - Set to the typical scrape and evaluation interval configured in Prometheus. The default is `15s`.
|
||||||
|
|
||||||
- **Query timeout** - The default is `60s`.
|
- **Query timeout** - The default is `60s`.
|
||||||
|
|
||||||
|
|||||||
@@ -782,6 +782,12 @@ On Linux, Grafana uses `/usr/share/grafana/public/dashboards/home.json` as the d
|
|||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
|
## [datasources]
|
||||||
|
|
||||||
|
### default_manage_alerts_ui_toggle
|
||||||
|
|
||||||
|
Default behavior for the "Manage alerts via Alerting UI" toggle when configuring a data source. It only works if the data source's `jsonData.manageAlerts` prop does not contain a previously configured value.
|
||||||
|
|
||||||
## [sql_datasources]
|
## [sql_datasources]
|
||||||
|
|
||||||
### max_open_conns_default
|
### max_open_conns_default
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import { render } from '@testing-library/react';
|
||||||
|
|
||||||
|
import { config } from '@grafana/runtime';
|
||||||
|
|
||||||
|
import { createDefaultConfigOptions } from '../test/__mocks__/datasource';
|
||||||
|
|
||||||
|
import { AlertingSettingsOverhaul } from './AlertingSettingsOverhaul';
|
||||||
|
|
||||||
|
describe(AlertingSettingsOverhaul.name, () => {
|
||||||
|
describe('Switch checked behavior', () => {
|
||||||
|
describe('when options.jsonData.manageAlerts is unset', () => {
|
||||||
|
it('uses the config default `true`', () => {
|
||||||
|
const options = createDefaultConfigOptions();
|
||||||
|
options.jsonData.manageAlerts = undefined;
|
||||||
|
|
||||||
|
config.defaultDatasourceManageAlertsUiToggle = true;
|
||||||
|
|
||||||
|
const { getByRole } = render(<AlertingSettingsOverhaul onOptionsChange={() => {}} options={options} />);
|
||||||
|
|
||||||
|
expect(getByRole('switch')).toBeChecked();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses the config default `false`', () => {
|
||||||
|
const options = createDefaultConfigOptions();
|
||||||
|
options.jsonData.manageAlerts = undefined;
|
||||||
|
|
||||||
|
config.defaultDatasourceManageAlertsUiToggle = false;
|
||||||
|
|
||||||
|
const { getByRole } = render(<AlertingSettingsOverhaul onOptionsChange={() => {}} options={options} />);
|
||||||
|
|
||||||
|
expect(getByRole('switch')).not.toBeChecked();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when options.jsonData.manageAlerts is set', () => {
|
||||||
|
it.each([true, false])('uses the manageAlerts value even when the config default is %s', (configDefault) => {
|
||||||
|
const options = createDefaultConfigOptions();
|
||||||
|
options.jsonData.manageAlerts = true;
|
||||||
|
|
||||||
|
config.defaultDatasourceManageAlertsUiToggle = configDefault;
|
||||||
|
|
||||||
|
const { getByRole } = render(<AlertingSettingsOverhaul onOptionsChange={() => {}} options={options} />);
|
||||||
|
|
||||||
|
expect(getByRole('switch')).toBeChecked();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -4,6 +4,7 @@ import { cx } from '@emotion/css';
|
|||||||
import { DataSourceJsonData, DataSourcePluginOptionsEditorProps } from '@grafana/data';
|
import { DataSourceJsonData, DataSourcePluginOptionsEditorProps } from '@grafana/data';
|
||||||
import { selectors } from '@grafana/e2e-selectors';
|
import { selectors } from '@grafana/e2e-selectors';
|
||||||
import { ConfigSubSection } from '@grafana/experimental';
|
import { ConfigSubSection } from '@grafana/experimental';
|
||||||
|
import { config } from '@grafana/runtime';
|
||||||
import { InlineField, Switch, useTheme2 } from '@grafana/ui';
|
import { InlineField, Switch, useTheme2 } from '@grafana/ui';
|
||||||
|
|
||||||
import { docsTip, overhaulStyles } from './ConfigEditor';
|
import { docsTip, overhaulStyles } from './ConfigEditor';
|
||||||
@@ -43,7 +44,7 @@ export function AlertingSettingsOverhaul<T extends AlertingConfig>({
|
|||||||
className={styles.switchField}
|
className={styles.switchField}
|
||||||
>
|
>
|
||||||
<Switch
|
<Switch
|
||||||
value={options.jsonData.manageAlerts !== false}
|
value={options.jsonData.manageAlerts ?? config.defaultDatasourceManageAlertsUiToggle}
|
||||||
onChange={(event) =>
|
onChange={(event) =>
|
||||||
onOptionsChange({
|
onOptionsChange({
|
||||||
...options,
|
...options,
|
||||||
|
|||||||
@@ -188,6 +188,7 @@ export class GrafanaBootConfig implements GrafanaConfig {
|
|||||||
maxIdleConns: 100,
|
maxIdleConns: 100,
|
||||||
connMaxLifetime: 14400,
|
connMaxLifetime: 14400,
|
||||||
};
|
};
|
||||||
|
defaultDatasourceManageAlertsUiToggle = true;
|
||||||
|
|
||||||
tokenExpirationDayLimit: undefined;
|
tokenExpirationDayLimit: undefined;
|
||||||
enableFrontendSandboxForPlugins: string[] = [];
|
enableFrontendSandboxForPlugins: string[] = [];
|
||||||
|
|||||||
@@ -242,6 +242,8 @@ type FrontendSettingsDTO struct {
|
|||||||
|
|
||||||
Azure FrontendSettingsAzureDTO `json:"azure"`
|
Azure FrontendSettingsAzureDTO `json:"azure"`
|
||||||
|
|
||||||
|
DefaultDatasourceManageAlertsUIToggle bool `json:"defaultDatasourceManageAlertsUiToggle"`
|
||||||
|
|
||||||
Caching FrontendSettingsCachingDTO `json:"caching"`
|
Caching FrontendSettingsCachingDTO `json:"caching"`
|
||||||
RecordedQueries FrontendSettingsRecordedQueriesDTO `json:"recordedQueries"`
|
RecordedQueries FrontendSettingsRecordedQueriesDTO `json:"recordedQueries"`
|
||||||
Reporting FrontendSettingsReportingDTO `json:"reporting"`
|
Reporting FrontendSettingsReportingDTO `json:"reporting"`
|
||||||
|
|||||||
@@ -245,6 +245,8 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro
|
|||||||
ReportingStaticContext: hs.Cfg.ReportingStaticContext,
|
ReportingStaticContext: hs.Cfg.ReportingStaticContext,
|
||||||
ExploreDefaultTimeOffset: hs.Cfg.ExploreDefaultTimeOffset,
|
ExploreDefaultTimeOffset: hs.Cfg.ExploreDefaultTimeOffset,
|
||||||
|
|
||||||
|
DefaultDatasourceManageAlertsUIToggle: hs.Cfg.DefaultDatasourceManageAlertsUIToggle,
|
||||||
|
|
||||||
BuildInfo: dtos.FrontendSettingsBuildInfoDTO{
|
BuildInfo: dtos.FrontendSettingsBuildInfoDTO{
|
||||||
HideVersion: hideVersion,
|
HideVersion: hideVersion,
|
||||||
Version: version,
|
Version: version,
|
||||||
|
|||||||
@@ -330,6 +330,9 @@ type Cfg struct {
|
|||||||
DataSourceLimit int
|
DataSourceLimit int
|
||||||
// Number of queries to be executed concurrently. Only for the datasource supports concurrency.
|
// Number of queries to be executed concurrently. Only for the datasource supports concurrency.
|
||||||
ConcurrentQueryCount int
|
ConcurrentQueryCount int
|
||||||
|
// Default behavior for the "Manage alerts via Alerting UI" toggle when configuring a data source.
|
||||||
|
// It only works if the data source's `jsonData.manageAlerts` prop does not contain a previously configured value.
|
||||||
|
DefaultDatasourceManageAlertsUIToggle bool
|
||||||
|
|
||||||
// IP range access control
|
// IP range access control
|
||||||
IPRangeACEnabled bool
|
IPRangeACEnabled bool
|
||||||
@@ -1914,6 +1917,7 @@ func (cfg *Cfg) readDataSourcesSettings() {
|
|||||||
datasources := cfg.Raw.Section("datasources")
|
datasources := cfg.Raw.Section("datasources")
|
||||||
cfg.DataSourceLimit = datasources.Key("datasource_limit").MustInt(5000)
|
cfg.DataSourceLimit = datasources.Key("datasource_limit").MustInt(5000)
|
||||||
cfg.ConcurrentQueryCount = datasources.Key("concurrent_query_count").MustInt(10)
|
cfg.ConcurrentQueryCount = datasources.Key("concurrent_query_count").MustInt(10)
|
||||||
|
cfg.DefaultDatasourceManageAlertsUIToggle = datasources.Key("default_manage_alerts_ui_toggle").MustBool(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *Cfg) readDataSourceSecuritySettings() {
|
func (cfg *Cfg) readDataSourceSecuritySettings() {
|
||||||
|
|||||||
Reference in New Issue
Block a user