Skip to content

Commit

Permalink
Merge branch 'master' into use-faster-wait
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankHassanabad committed Jul 20, 2020
2 parents 52e38d1 + 3ccdd79 commit 8641cf0
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 72 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"@elastic/apm-rum": "^5.2.0",
"@elastic/charts": "19.8.1",
"@elastic/datemath": "5.0.3",
"@elastic/elasticsearch": "7.9.0-rc.1",
"@elastic/elasticsearch": "7.9.0-rc.2",
"@elastic/ems-client": "7.9.3",
"@elastic/eui": "26.3.1",
"@elastic/filesaver": "1.1.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const setupEnvironment = () => {
);

mockHttpClient.interceptors.response.use(({ data }) => data);
// This expects HttpSetup but we're giving it AxiosInstance.
// @ts-ignore
initHttp(mockHttpClient);
const { server, httpRequestsMockHelpers } = initHttpRequests();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import { METRIC_TYPE } from '@kbn/analytics';
import { trackUiMetric } from './ui_metric';

import {
UIM_POLICY_DELETE,
Expand All @@ -15,8 +14,13 @@ import {
UIM_INDEX_RETRY_STEP,
} from '../constants';

import { trackUiMetric } from './ui_metric';
import { sendGet, sendPost, sendDelete, useRequest } from './http';

interface GenericObject {
[key: string]: any;
}

export async function loadNodes() {
return await sendGet(`nodes/list`);
}
Expand All @@ -33,7 +37,7 @@ export async function loadPolicies(withIndices: boolean) {
return await sendGet('policies', { withIndices });
}

export async function savePolicy(policy: any) {
export async function savePolicy(policy: GenericObject) {
return await sendPost(`policies`, policy);
}

Expand All @@ -58,14 +62,14 @@ export const removeLifecycleForIndex = async (indexNames: string[]) => {
return response;
};

export const addLifecyclePolicyToIndex = async (body: any) => {
export const addLifecyclePolicyToIndex = async (body: GenericObject) => {
const response = await sendPost(`index/add`, body);
// Only track successful actions.
trackUiMetric(METRIC_TYPE.COUNT, UIM_POLICY_ATTACH_INDEX);
return response;
};

export const addLifecyclePolicyToTemplate = async (body: any) => {
export const addLifecyclePolicyToTemplate = async (body: GenericObject) => {
const response = await sendPost(`template`, body);
// Only track successful actions.
trackUiMetric(METRIC_TYPE.COUNT, UIM_POLICY_ATTACH_INDEX_TEMPLATE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { IHttpFetchError } from 'src/core/public';
import { fatalErrors, toasts } from './notification';

function createToastConfig(error, errorTitle) {
function createToastConfig(error: IHttpFetchError, errorTitle: string) {
if (error && error.body) {
// Error body shape is defined by the API.
const { error: errorString, statusCode, message } = error.body;

return {
Expand All @@ -17,7 +19,7 @@ function createToastConfig(error, errorTitle) {
}
}

export function showApiWarning(error, errorTitle) {
export function showApiWarning(error: IHttpFetchError, errorTitle: string) {
const toastConfig = createToastConfig(error, errorTitle);

if (toastConfig) {
Expand All @@ -26,10 +28,10 @@ export function showApiWarning(error, errorTitle) {

// This error isn't an HTTP error, so let the fatal error screen tell the user something
// unexpected happened.
return fatalErrors(error, errorTitle);
return fatalErrors.add(error, errorTitle);
}

export function showApiError(error, errorTitle) {
export function showApiError(error: IHttpFetchError, errorTitle: string) {
const toastConfig = createToastConfig(error, errorTitle);

if (toastConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { HttpSetup } from 'src/core/public';
import {
UseRequestConfig,
useRequest as _useRequest,
Error,
} from '../../../../../../src/plugins/es_ui_shared/public';

let _httpClient: any;
interface GenericObject {
[key: string]: any;
}

let _httpClient: HttpSetup;

export function init(httpClient: any): void {
export function init(httpClient: HttpSetup): void {
_httpClient = httpClient;
}

Expand All @@ -26,15 +31,15 @@ function getFullPath(path: string): string {
return apiPrefix;
}

export function sendPost(path: string, payload: any): any {
export function sendPost(path: string, payload: GenericObject) {
return _httpClient.post(getFullPath(path), { body: JSON.stringify(payload) });
}

export function sendGet(path: string, query?: any): any {
export function sendGet(path: string, query?: GenericObject): any {
return _httpClient.get(getFullPath(path), { query });
}

export function sendDelete(path: string): any {
export function sendDelete(path: string) {
return _httpClient.delete(getFullPath(path));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ import { removeLifecycleForIndex } from '../../application/services/api';
import { showApiError } from '../../application/services/api_errors';
import { toasts } from '../../application/services/notification';

export class RemoveLifecyclePolicyConfirmModal extends Component {
constructor(props) {
super(props);
this.state = {
policies: [],
selectedPolicyName: null,
selectedAlias: null,
};
}
interface Props {
indexNames: string[];
closeModal: () => void;
reloadIndices: () => void;
}

export class RemoveLifecyclePolicyConfirmModal extends Component<Props> {
removePolicy = async () => {
const { indexNames, closeModal, reloadIndices } = this.props;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ import {
EuiFlexGroup,
EuiFlexItem,
EuiCallOut,
EuiOverlayMask,
EuiModal,
EuiModalHeader,
EuiModalHeaderTitle,
EuiModalBody,
EuiAccordion,
EuiCodeBlock,
EuiLink,
EuiText,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
Expand Down Expand Up @@ -61,9 +57,6 @@ export const AlertPreview: React.FC<Props> = (props) => {
const [previewResult, setPreviewResult] = useState<
(AlertPreviewSuccessResponsePayload & Record<string, any>) | null
>(null);
const [isErrorModalVisible, setIsErrorModalVisible] = useState<boolean>(false);
const onOpenModal = useCallback(() => setIsErrorModalVisible(true), [setIsErrorModalVisible]);
const onCloseModal = useCallback(() => setIsErrorModalVisible(false), [setIsErrorModalVisible]);

const onSelectPreviewLookbackInterval = useCallback((e) => {
setPreviewLookbackInterval(e.target.value);
Expand Down Expand Up @@ -271,33 +264,32 @@ export const AlertPreview: React.FC<Props> = (props) => {
iconType="alert"
>
{previewError.body && (
<FormattedMessage
id="xpack.infra.metrics.alertFlyout.alertPreviewErrorDesc"
defaultMessage="Try again later, or {viewTheError}."
values={{
viewTheError: <EuiLink onClick={onOpenModal}>view the error</EuiLink>,
}}
/>
<>
<FormattedMessage
id="xpack.infra.metrics.alertFlyout.alertPreviewErrorDesc"
defaultMessage="Please try again later or see details for more information."
/>
<EuiSpacer size={'s'} />
<EuiAccordion
id="alertErrorDetailsAccordion"
buttonContent={
<>
<EuiText size="s">
<FormattedMessage
id="xpack.infra.metrics.alertFlyout.errorDetails"
defaultMessage="Details"
/>
</EuiText>
</>
}
>
<EuiSpacer size={'s'} />
<EuiCodeBlock>{previewError.body.message}</EuiCodeBlock>
</EuiAccordion>
</>
)}
</EuiCallOut>
)}
{isErrorModalVisible && (
<EuiOverlayMask>
<EuiModal onClose={onCloseModal}>
<EuiModalHeader>
<EuiModalHeaderTitle>
<FormattedMessage
id="xpack.infra.metrics.alertFlyout.alertPreviewErrorModalTitle"
defaultMessage="Alert preview error"
/>
</EuiModalHeaderTitle>
</EuiModalHeader>
<EuiModalBody>
<EuiCodeBlock>{previewError.body.message}</EuiCodeBlock>
</EuiModalBody>
</EuiModal>
</EuiOverlayMask>
)}
</>
)}
</>
Expand Down
10 changes: 6 additions & 4 deletions x-pack/plugins/rollup/public/crud_app/services/api_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { IHttpFetchError } from 'src/core/public';
import { getNotifications, getFatalErrors } from '../../kibana_services';

function createToastConfig(error: any, errorTitle: string) {
// Expect an error in the shape provided by http service.
function createToastConfig(error: IHttpFetchError, errorTitle: string) {
if (error && error.body) {
// Error body shape is defined by the API.
const { error: errorString, statusCode, message } = error.body;

return {
title: errorTitle,
text: `${statusCode}: ${errorString}. ${message}`,
};
}
}

export function showApiWarning(error: any, errorTitle: string) {
export function showApiWarning(error: IHttpFetchError, errorTitle: string) {
const toastConfig = createToastConfig(error, errorTitle);

if (toastConfig) {
Expand All @@ -29,7 +31,7 @@ export function showApiWarning(error: any, errorTitle: string) {
return getFatalErrors().add(error, errorTitle);
}

export function showApiError(error: any, errorTitle: string) {
export function showApiError(error: IHttpFetchError, errorTitle: string) {
const toastConfig = createToastConfig(error, errorTitle);

if (toastConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ async function indexAlerts(
},
[]
);
await client.bulk({ body, refresh: 'true' });
await client.bulk({ body, refresh: true });
}
}
2 changes: 1 addition & 1 deletion x-pack/test/api_integration/apis/fleet/agents/acks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function (providerContext: FtrProviderContext) {
await esClient.update({
index: '.kibana',
id: 'fleet-agents:agent1',
refresh: 'true',
refresh: true,
body: {
doc: agentDoc,
},
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/api_integration/apis/fleet/agents/checkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function (providerContext: FtrProviderContext) {
await esClient.update({
index: '.kibana',
id: 'fleet-agents:agent1',
refresh: 'true',
refresh: true,
body: {
doc: agentDoc,
},
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/api_integration/apis/fleet/agents/enroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function (providerContext: FtrProviderContext) {
await esClient.update({
index: '.kibana',
id: 'fleet-enrollment-api-keys:ed22ca17-e178-4cfe-8b02-54ea29fbd6d0',
refresh: 'true',
refresh: true,
body: {
doc: enrollmentApiKeyDoc,
},
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/api_integration/apis/fleet/unenroll_agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function (providerContext: FtrProviderContext) {
await esClient.update({
index: '.kibana',
id: 'fleet-agents:agent1',
refresh: 'true',
refresh: true,
body: {
doc: agentDoc,
},
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/api_integration/services/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function ResolverGeneratorProvider({ getService }: FtrProviderContext) {
return array;
}, []);
// force a refresh here otherwise the documents might not be available when the tests search for them
await client.bulk({ body, refresh: 'true' });
await client.bulk({ body, refresh: true });
allTrees.push(tree);
}
return { trees: allTrees, eventsIndex, alertsIndex };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import {
deleteAllAlerts,
deleteAllTimelines,
deleteSignalsIndex,
waitFor,
} from '../../utils';

// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext): void => {
const supertest = getService('supertest');
const es = getService('es');

// FLAKY: https://github.com/elastic/kibana/issues/71867
describe.skip('add_prepackaged_rules', () => {
describe('add_prepackaged_rules', () => {
describe('validation errors', () => {
it('should give an error that the index must exist first if it does not exist before adding prepackaged rules', async () => {
const { body } = await supertest
Expand Down Expand Up @@ -91,6 +91,16 @@ export default ({ getService }: FtrProviderContext): void => {
.send()
.expect(200);

// NOTE: I call the GET call until eventually it becomes consistent and that the number of rules to install are zero.
// This is to reduce flakiness where it can for a short period of time try to install the same rule twice.
await waitFor(async () => {
const { body } = await supertest
.get(`${DETECTION_ENGINE_PREPACKAGED_URL}/_status`)
.set('kbn-xsrf', 'true')
.expect(200);
return body.rules_not_installed === 0;
});

const { body } = await supertest
.put(DETECTION_ENGINE_PREPACKAGED_URL)
.set('kbn-xsrf', 'true')
Expand Down
Loading

0 comments on commit 8641cf0

Please sign in to comment.