Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/elastic/kibana into alert…
Browse files Browse the repository at this point in the history
…ing/pass-all-rule-params
  • Loading branch information
ymao1 committed May 13, 2021
2 parents 2d64089 + bb7057c commit ad4674e
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 40 deletions.
Binary file modified docs/user/alerting/images/rule-details-alerts-inactive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion test/plugin_functional/test_suites/doc_views/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { PluginFunctionalProviderContext } from '../../services';
export default function ({ getService, loadTestFile }: PluginFunctionalProviderContext) {
const esArchiver = getService('esArchiver');

describe('doc views', function () {
// SKIPPED: https://github.com/elastic/kibana/issues/100060
describe.skip('doc views', function () {
before(async () => {
await esArchiver.loadIfNeeded('../functional/fixtures/es_archiver/discover');
});
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/alerting/server/alerts_client/alerts_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,11 @@ export class AlertsClient {
...this.apiKeyAsAlertAttributes(createdAPIKey, username),
updatedBy: username,
updatedAt: new Date().toISOString(),
executionStatus: {
status: 'pending',
lastExecutionDate: new Date().toISOString(),
error: null,
},
});
try {
await this.unsecuredSavedObjectsClient.update('alert', id, updateAttributes, { version });
Expand Down
10 changes: 10 additions & 0 deletions x-pack/plugins/alerting/server/alerts_client/tests/enable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ describe('enable()', () => {
},
},
],
executionStatus: {
status: 'pending',
lastExecutionDate: '2019-02-12T21:01:22.479Z',
error: null,
},
},
{
version: '123',
Expand Down Expand Up @@ -352,6 +357,11 @@ describe('enable()', () => {
},
},
],
executionStatus: {
status: 'pending',
lastExecutionDate: '2019-02-12T21:01:22.479Z',
error: null,
},
},
{
version: '123',
Expand Down
9 changes: 0 additions & 9 deletions x-pack/plugins/fleet/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,13 @@ export interface FleetConfigType {
registryProxyUrl?: string;
agents: {
enabled: boolean;
tlsCheckDisabled: boolean;
pollingRequestTimeout: number;
maxConcurrentConnections: number;
kibana: {
host?: string[] | string;
ca_sha256?: string;
};
elasticsearch: {
host?: string;
ca_sha256?: string;
};
fleet_server?: {
hosts?: string[];
};
agentPolicyRolloutRateLimitIntervalMs: number;
agentPolicyRolloutRateLimitRequestPerInterval: number;
};
agentPolicies?: PreconfiguredAgentPolicy[];
packages?: PreconfiguredPackage[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,10 @@ export const createConfigurationMock = (): FleetConfigType => {
registryProxyUrl: '',
agents: {
enabled: true,
tlsCheckDisabled: true,
pollingRequestTimeout: 1000,
maxConcurrentConnections: 100,
kibana: {
host: '',
ca_sha256: '',
},
elasticsearch: {
host: '',
ca_sha256: '',
},
agentPolicyRolloutRateLimitIntervalMs: 100,
agentPolicyRolloutRateLimitRequestPerInterval: 1000,
},
};
};
4 changes: 4 additions & 0 deletions x-pack/plugins/fleet/server/mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export const createAppContextStartContractMock = (): FleetAppContext => {
security: securityMock.createStart(),
logger: loggingSystemMock.create().get(),
isProductionMode: true,
configInitialValue: {
agents: { enabled: true, elasticsearch: {} },
enabled: true,
},
kibanaVersion: '8.0.0',
kibanaBranch: 'master',
};
Expand Down
14 changes: 8 additions & 6 deletions x-pack/plugins/fleet/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import type { Observable } from 'rxjs';
import { first } from 'rxjs/operators';
import type {
CoreSetup,
CoreStart,
Expand Down Expand Up @@ -110,6 +109,7 @@ export interface FleetAppContext {
encryptedSavedObjectsSetup?: EncryptedSavedObjectsPluginSetup;
security?: SecurityPluginStart;
config$?: Observable<FleetConfigType>;
configInitialValue: FleetConfigType;
savedObjects: SavedObjectsServiceStart;
isProductionMode: PluginInitializerContext['env']['mode']['prod'];
kibanaVersion: PluginInitializerContext['env']['packageInfo']['version'];
Expand Down Expand Up @@ -189,6 +189,7 @@ export class FleetPlugin
implements AsyncPlugin<FleetSetupContract, FleetStartContract, FleetSetupDeps, FleetStartDeps> {
private licensing$!: Observable<ILicense>;
private config$: Observable<FleetConfigType>;
private configInitialValue: FleetConfigType;
private cloud: CloudSetup | undefined;
private logger: Logger | undefined;

Expand All @@ -204,15 +205,15 @@ export class FleetPlugin
this.kibanaVersion = this.initializerContext.env.packageInfo.version;
this.kibanaBranch = this.initializerContext.env.packageInfo.branch;
this.logger = this.initializerContext.logger.get();
this.configInitialValue = this.initializerContext.config.get();
}

public async setup(core: CoreSetup, deps: FleetSetupDeps) {
public setup(core: CoreSetup, deps: FleetSetupDeps) {
this.httpSetup = core.http;
this.licensing$ = deps.licensing.license$;
this.encryptedSavedObjectsSetup = deps.encryptedSavedObjects;
this.cloud = deps.cloud;

const config = await this.config$.pipe(first()).toPromise();
const config = this.configInitialValue;

registerSavedObjects(core.savedObjects, deps.encryptedSavedObjects);
registerEncryptedSavedObjects(deps.encryptedSavedObjects);
Expand Down Expand Up @@ -279,13 +280,14 @@ export class FleetPlugin
}
}

public async start(core: CoreStart, plugins: FleetStartDeps): Promise<FleetStartContract> {
await appContextService.start({
public start(core: CoreStart, plugins: FleetStartDeps): FleetStartContract {
appContextService.start({
elasticsearch: core.elasticsearch,
data: plugins.data,
encryptedSavedObjectsStart: plugins.encryptedSavedObjects,
encryptedSavedObjectsSetup: this.encryptedSavedObjectsSetup,
security: plugins.security,
configInitialValue: this.configInitialValue,
config$: this.config$,
savedObjects: core.savedObjects,
isProductionMode: this.isProductionMode,
Expand Down
5 changes: 2 additions & 3 deletions x-pack/plugins/fleet/server/services/app_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import type { Observable } from 'rxjs';
import { BehaviorSubject } from 'rxjs';
import { first } from 'rxjs/operators';
import { kibanaPackageJson } from '@kbn/utils';
import type { KibanaRequest } from 'src/core/server';
import type {
Expand Down Expand Up @@ -44,7 +43,7 @@ class AppContextService {
private httpSetup?: HttpServiceSetup;
private externalCallbacks: ExternalCallbacksStorage = new Map();

public async start(appContext: FleetAppContext) {
public start(appContext: FleetAppContext) {
this.data = appContext.data;
this.esClient = appContext.elasticsearch.client.asInternalUser;
this.encryptedSavedObjects = appContext.encryptedSavedObjectsStart?.getClient();
Expand All @@ -60,7 +59,7 @@ class AppContextService {

if (appContext.config$) {
this.config$ = appContext.config$;
const initialValue = await this.config$.pipe(first()).toPromise();
const initialValue = appContext.configInitialValue;
this.configSubject$ = new BehaviorSubject(initialValue);
this.config$.subscribe(this.configSubject$);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ describe('SearchBar', () => {
};

const simulateTypeChar = async (text: string) => {
await waitFor(() =>
getSearchProps(component).onKeyUpCapture({ currentTarget: { value: text } })
);
await waitFor(() => getSearchProps(component).onInput({ currentTarget: { value: text } }));
};

const getDisplayedOptionsTitle = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,7 @@ export function SearchBar({
</EuiHeaderSectionItemButton>
}
searchProps={{
onKeyUpCapture: (e: React.KeyboardEvent<HTMLInputElement>) =>
setSearchValue(e.currentTarget.value),
onInput: (e: React.UIEvent<HTMLInputElement>) => setSearchValue(e.currentTarget.value),
'data-test-subj': 'nav-search-input',
inputRef: setSearchRef,
compressed: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ function getProps({
rolesAPIClient.getRole.mockResolvedValue(role);

const indexPatterns = dataPluginMock.createStartContract().indexPatterns;
indexPatterns.getTitles = jest.fn().mockResolvedValue(['foo*', 'bar*']);
// `undefined` titles can technically happen via import/export or other manual manipulation
indexPatterns.getTitles = jest.fn().mockResolvedValue(['foo*', 'bar*', undefined]);

const indicesAPIClient = indicesAPIClientMock.create();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function useIndexPatternsTitles(
fatalErrors.add(err);
throw err;
})
.then(setIndexPatternsTitles);
.then((titles) => setIndexPatternsTitles(titles.filter(Boolean)));
}, [fatalErrors, indexPatterns, notifications]);

return indexPatternsTitles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import * as React from 'react';
import uuid from 'uuid';
import { shallow } from 'enzyme';
import { mountWithIntl, nextTick } from '@kbn/test/jest';
import { act } from '@testing-library/react';
import { AlertDetails } from './alert_details';
import { Alert, ActionType, AlertTypeModel, AlertType } from '../../../../types';
import { EuiTitle, EuiBadge, EuiFlexItem, EuiSwitch, EuiButtonEmpty, EuiText } from '@elastic/eui';
Expand Down Expand Up @@ -463,6 +465,74 @@ describe('disable button', () => {
handler!({} as React.FormEvent);
expect(enableAlert).toHaveBeenCalledTimes(1);
});

it('should reset error banner dismissal after re-enabling the alert', async () => {
const alert = mockAlert({
enabled: true,
executionStatus: {
status: 'error',
lastExecutionDate: new Date('2020-08-20T19:23:38Z'),
error: {
reason: AlertExecutionStatusErrorReasons.Execute,
message: 'Fail',
},
},
});

const alertType: AlertType = {
id: '.noop',
name: 'No Op',
actionGroups: [{ id: 'default', name: 'Default' }],
recoveryActionGroup,
actionVariables: { context: [], state: [], params: [] },
defaultActionGroupId: 'default',
producer: ALERTS_FEATURE_ID,
authorizedConsumers,
minimumLicenseRequired: 'basic',
enabledInLicense: true,
};

const disableAlert = jest.fn();
const enableAlert = jest.fn();
const wrapper = mountWithIntl(
<AlertDetails
alert={alert}
alertType={alertType}
actionTypes={[]}
{...mockAlertApis}
disableAlert={disableAlert}
enableAlert={enableAlert}
/>
);

await act(async () => {
await nextTick();
wrapper.update();
});

// Dismiss the error banner
await act(async () => {
wrapper.find('[data-test-subj="dismiss-execution-error"]').first().simulate('click');
await nextTick();
});

// Disable the alert
await act(async () => {
wrapper.find('[data-test-subj="disableSwitch"] .euiSwitch__button').first().simulate('click');
await nextTick();
});
expect(disableAlert).toHaveBeenCalled();

// Enable the alert
await act(async () => {
wrapper.find('[data-test-subj="disableSwitch"] .euiSwitch__button').first().simulate('click');
await nextTick();
});
expect(enableAlert).toHaveBeenCalled();

// Ensure error banner is back
expect(wrapper.find('[data-test-subj="dismiss-execution-error"]').length).toBeGreaterThan(0);
});
});

describe('mute button', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ export const AlertDetails: React.FunctionComponent<AlertDetailsProps> = ({
if (isEnabled) {
setIsEnabled(false);
await disableAlert(alert);
// Reset dismiss if previously clicked
setDissmissAlertErrors(false);
} else {
setIsEnabled(true);
await enableAlert(alert);
Expand Down Expand Up @@ -277,7 +279,7 @@ export const AlertDetails: React.FunctionComponent<AlertDetailsProps> = ({
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
{!dissmissAlertErrors && alert.executionStatus.status === 'error' ? (
{alert.enabled && !dissmissAlertErrors && alert.executionStatus.status === 'error' ? (
<EuiFlexGroup>
<EuiFlexItem>
<EuiCallOut
Expand All @@ -293,7 +295,11 @@ export const AlertDetails: React.FunctionComponent<AlertDetailsProps> = ({
<EuiSpacer size="s" />
<EuiFlexGroup gutterSize="s" wrap={true}>
<EuiFlexItem grow={false}>
<EuiButton color="danger" onClick={() => setDissmissAlertErrors(true)}>
<EuiButton
data-test-subj="dismiss-execution-error"
color="danger"
onClick={() => setDissmissAlertErrors(true)}
>
<FormattedMessage
id="xpack.triggersActionsUI.sections.alertDetails.dismissButtonTitle"
defaultMessage="Dismiss"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ describe('alertInstanceToListItem', () => {
};
expect(alertInstanceToListItem(fakeNow.getTime(), alertType, 'id', instance)).toEqual({
instance: 'id',
status: { label: 'OK', healthColor: 'subdued' },
status: { label: 'Recovered', healthColor: 'subdued' },
start: undefined,
duration: 0,
sortPriority: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ const ACTIVE_LABEL = i18n.translate(

const INACTIVE_LABEL = i18n.translate(
'xpack.triggersActionsUI.sections.alertDetails.alertInstancesList.status.inactive',
{ defaultMessage: 'OK' }
{ defaultMessage: 'Recovered' }
);

function getActionGroupName(alertType: AlertType, actionGroupId?: string): string | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
).to.eql([
{
instance: 'eu/east',
status: 'OK',
status: 'Recovered',
start: '',
duration: '',
},
Expand Down

0 comments on commit ad4674e

Please sign in to comment.