|
|
|
@ -2,16 +2,14 @@ import userEvent from '@testing-library/user-event'; |
|
|
|
|
import { render } from 'test/test-utils'; |
|
|
|
|
import { byTestId } from 'testing-library-selector'; |
|
|
|
|
|
|
|
|
|
import { DataSourceApi } from '@grafana/data'; |
|
|
|
|
import { PromOptions, PrometheusDatasource } from '@grafana/prometheus'; |
|
|
|
|
import { config, locationService, setDataSourceSrv, setPluginLinksHook } from '@grafana/runtime'; |
|
|
|
|
import { PromOptions } from '@grafana/prometheus'; |
|
|
|
|
import { config, locationService, setPluginLinksHook } from '@grafana/runtime'; |
|
|
|
|
import { backendSrv } from 'app/core/services/backend_srv'; |
|
|
|
|
import * as ruler from 'app/features/alerting/unified/api/ruler'; |
|
|
|
|
import * as ruleActionButtons from 'app/features/alerting/unified/components/rules/RuleActionsButtons'; |
|
|
|
|
import * as alertingAbilities from 'app/features/alerting/unified/hooks/useAbilities'; |
|
|
|
|
import { mockAlertRuleApi, setupMswServer } from 'app/features/alerting/unified/mockApi'; |
|
|
|
|
import { |
|
|
|
|
MockDataSourceSrv, |
|
|
|
|
grantUserPermissions, |
|
|
|
|
mockDataSource, |
|
|
|
|
mockFolder, |
|
|
|
@ -20,13 +18,12 @@ import { |
|
|
|
|
mockRulerAlertingRule, |
|
|
|
|
mockRulerRuleGroup, |
|
|
|
|
} from 'app/features/alerting/unified/mocks'; |
|
|
|
|
import { setupDataSources } from 'app/features/alerting/unified/testSetup/datasources'; |
|
|
|
|
import { RuleFormValues } from 'app/features/alerting/unified/types/rule-form'; |
|
|
|
|
import * as configDS from 'app/features/alerting/unified/utils/config'; |
|
|
|
|
import { Annotation } from 'app/features/alerting/unified/utils/constants'; |
|
|
|
|
import { DataSourceType, GRAFANA_RULES_SOURCE_NAME } from 'app/features/alerting/unified/utils/datasource'; |
|
|
|
|
import { DashboardModel } from 'app/features/dashboard/state/DashboardModel'; |
|
|
|
|
import { PanelModel } from 'app/features/dashboard/state/PanelModel'; |
|
|
|
|
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; |
|
|
|
|
import { configureStore } from 'app/store/configureStore'; |
|
|
|
|
import { AccessControlAction, DashboardDataDTO } from 'app/types'; |
|
|
|
|
import { AlertQuery, PromRulesResponse } from 'app/types/unified-alerting-dto'; |
|
|
|
@ -44,7 +41,6 @@ import { PanelDataAlertingTab, PanelDataAlertingTabRendered } from './PanelDataA |
|
|
|
|
jest.mock('app/features/alerting/unified/api/prometheus'); |
|
|
|
|
jest.mock('app/features/alerting/unified/api/ruler'); |
|
|
|
|
|
|
|
|
|
jest.spyOn(configDS, 'getAllDataSources'); |
|
|
|
|
jest.spyOn(ruleActionButtons, 'matchesWidth').mockReturnValue(false); |
|
|
|
|
jest.spyOn(ruler, 'rulerUrlBuilder'); |
|
|
|
|
jest.spyOn(alertingAbilities, 'useAlertRuleAbility'); |
|
|
|
@ -55,22 +51,34 @@ setPluginLinksHook(() => ({ |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
const dataSources = { |
|
|
|
|
prometheus: mockDataSource<PromOptions>({ |
|
|
|
|
name: 'Prometheus', |
|
|
|
|
type: DataSourceType.Prometheus, |
|
|
|
|
isDefault: false, |
|
|
|
|
}), |
|
|
|
|
default: mockDataSource<PromOptions>({ |
|
|
|
|
name: 'Default', |
|
|
|
|
type: DataSourceType.Prometheus, |
|
|
|
|
isDefault: true, |
|
|
|
|
}), |
|
|
|
|
prometheus: mockDataSource<PromOptions>( |
|
|
|
|
{ |
|
|
|
|
name: 'Prometheus', |
|
|
|
|
type: DataSourceType.Prometheus, |
|
|
|
|
isDefault: false, |
|
|
|
|
}, |
|
|
|
|
{ alerting: true, module: 'core:plugin/prometheus' } |
|
|
|
|
), |
|
|
|
|
default: mockDataSource<PromOptions>( |
|
|
|
|
{ |
|
|
|
|
name: 'Default', |
|
|
|
|
type: DataSourceType.Prometheus, |
|
|
|
|
isDefault: true, |
|
|
|
|
}, |
|
|
|
|
{ alerting: true, module: 'core:plugin/prometheus' } |
|
|
|
|
), |
|
|
|
|
prometheusMinInterval: mockDataSource<PromOptions>( |
|
|
|
|
{ |
|
|
|
|
name: 'Prometheus Min Interval', |
|
|
|
|
type: DataSourceType.Prometheus, |
|
|
|
|
isDefault: false, |
|
|
|
|
jsonData: { manageAlerts: true, timeInterval: '7m' }, |
|
|
|
|
}, |
|
|
|
|
{ alerting: true, module: 'core:plugin/prometheus' } |
|
|
|
|
), |
|
|
|
|
}; |
|
|
|
|
dataSources.prometheus.meta.alerting = true; |
|
|
|
|
dataSources.default.meta.alerting = true; |
|
|
|
|
|
|
|
|
|
const mocks = { |
|
|
|
|
getAllDataSources: jest.mocked(configDS.getAllDataSources), |
|
|
|
|
useAlertRuleAbilityMock: jest.mocked(alertingAbilities.useAlertRuleAbility), |
|
|
|
|
rulerBuilderMock: jest.mocked(ruler.rulerUrlBuilder), |
|
|
|
|
}; |
|
|
|
@ -182,14 +190,8 @@ describe('PanelAlertTabContent', () => { |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
jest.spyOn(backendSrv, 'getFolderByUid').mockResolvedValue(mockFolder()); |
|
|
|
|
setupDataSources(...Object.values(dataSources)); |
|
|
|
|
|
|
|
|
|
mocks.getAllDataSources.mockReturnValue(Object.values(dataSources)); |
|
|
|
|
const dsService = new MockDataSourceSrv(dataSources); |
|
|
|
|
dsService.datasources[dataSources.prometheus.uid] = new PrometheusDatasource( |
|
|
|
|
dataSources.prometheus |
|
|
|
|
) as DataSourceApi; |
|
|
|
|
dsService.datasources[dataSources.default.uid] = new PrometheusDatasource(dataSources.default) as DataSourceApi; |
|
|
|
|
setDataSourceSrv(dsService); |
|
|
|
|
mocks.rulerBuilderMock.mockReturnValue({ |
|
|
|
|
rules: () => ({ path: `api/ruler/${GRAFANA_RULES_SOURCE_NAME}/api/v1/rules` }), |
|
|
|
|
namespace: () => ({ path: 'ruler' }), |
|
|
|
@ -281,11 +283,13 @@ describe('PanelAlertTabContent', () => { |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('Will take into account datasource minInterval', async () => { |
|
|
|
|
(getDatasourceSrv() as unknown as MockDataSourceSrv).datasources[dataSources.prometheus.uid].interval = '7m'; |
|
|
|
|
|
|
|
|
|
dashboard.panels = [ |
|
|
|
|
new PanelModel({ |
|
|
|
|
...panel, |
|
|
|
|
datasource: { |
|
|
|
|
type: 'prometheus', |
|
|
|
|
uid: dataSources.prometheusMinInterval.uid, |
|
|
|
|
}, |
|
|
|
|
maxDataPoints: 100, |
|
|
|
|
}), |
|
|
|
|
]; |
|
|
|
@ -298,7 +302,7 @@ describe('PanelAlertTabContent', () => { |
|
|
|
|
refId: 'A', |
|
|
|
|
datasource: { |
|
|
|
|
type: 'prometheus', |
|
|
|
|
uid: 'mock-ds-2', |
|
|
|
|
uid: 'mock-ds-4', |
|
|
|
|
}, |
|
|
|
|
interval: '', |
|
|
|
|
intervalMs: 420000, |
|
|
|
|