Skip to content

Commit

Permalink
Merge branch 'master' into scottybollinger/fix-pd-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine committed May 13, 2021
2 parents 4094219 + 609fed3 commit 61f0b2c
Show file tree
Hide file tree
Showing 19 changed files with 126 additions and 37 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.
2 changes: 0 additions & 2 deletions src/plugins/console/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export const config = schema.object(
enabled: schema.boolean({ defaultValue: true }),
proxyFilter: schema.arrayOf(schema.string(), { defaultValue: ['.*'] }),
ssl: schema.object({ verify: schema.boolean({ defaultValue: false }) }, {}),

// This does not actually work, track this issue: https://github.com/elastic/kibana/issues/55576
proxyConfig: schema.arrayOf(
schema.object({
match: schema.object({
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export const SchemaTable: React.FC = () => {
<EuiTableHeader>
<EuiTableHeaderCell>{FIELD_NAME}</EuiTableHeaderCell>
<EuiTableHeaderCell aria-hidden />
<EuiTableHeaderCell align="right">{FIELD_TYPE}</EuiTableHeaderCell>
<EuiTableHeaderCell align="right" id="schemaFieldType">
{FIELD_TYPE}
</EuiTableHeaderCell>
</EuiTableHeader>
<EuiTableBody>
<EuiTableRow style={{ height: 56 }}>
Expand Down Expand Up @@ -74,6 +76,7 @@ export const SchemaTable: React.FC = () => {
fieldName={fieldName}
fieldType={fieldType}
updateExistingFieldType={updateSchemaFieldType}
aria-labelledby="schemaFieldType"
/>
</EuiTableRowCell>
</EuiTableRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ describe('SchemaFieldTypeSelect', () => {

expect(wrapper.find(EuiSelect).prop('disabled')).toEqual(true);
});

it('passes arbitrary props', () => {
const wrapper = shallow(<SchemaFieldTypeSelect {...props} disabled aria-label="Test label" />);

expect(wrapper.find(EuiSelect).prop('aria-label')).toEqual('Test label');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ export const SchemaFieldTypeSelect: React.FC<Props> = ({
fieldType,
updateExistingFieldType,
disabled,
...rest
}) => {
const fieldTypeOptions = Object.values(SchemaType).map((type) => ({ value: type, text: type }));
return (
<EuiSelect
{...rest}
name={fieldName}
required
value={fieldType}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const SchemaFieldsTable: React.FC = () => {
<EuiTable tableLayout="auto">
<EuiTableHeader>
<EuiTableHeaderCell>{SCHEMA_ERRORS_TABLE_FIELD_NAME_HEADER}</EuiTableHeaderCell>
<EuiTableHeaderCell align="right">
<EuiTableHeaderCell align="right" id="schemaDataType">
{SCHEMA_ERRORS_TABLE_DATA_TYPE_HEADER}
</EuiTableHeaderCell>
</EuiTableHeader>
Expand All @@ -58,6 +58,7 @@ export const SchemaFieldsTable: React.FC = () => {
fieldName={fieldName}
fieldType={filteredSchemaFields[fieldName]}
updateExistingFieldType={updateExistingFieldType}
aria-labelledby="schemaDataType"
/>
</EuiTableRowCell>
</EuiTableRow>
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 @@ -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 61f0b2c

Please sign in to comment.