Skip to content

Commit

Permalink
Merge branch 'main' into fix_timeslice_chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Jul 29, 2024
2 parents 377a700 + f24e0cd commit ee6d51e
Show file tree
Hide file tree
Showing 320 changed files with 2,170 additions and 973 deletions.
30 changes: 15 additions & 15 deletions .buildkite/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .buildkite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"chai": "^4.3.10",
"mocha": "^10.3.0",
"nock": "^12.0.2",
"ts-node": "^10.7.0",
"typescript": "^4.6.4"
"ts-node": "^10.9.2",
"typescript": "^5.1.6"
},
"imports": {
"#pipeline-utils": "./pipeline-utils/index.ts",
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
"**/react-intl/**/@types/react": "^17.0.45",
"**/remark-parse/trim": "1.0.1",
"**/sharp": "0.32.6",
"**/typescript": "4.9.5",
"**/typescript": "5.1.6",
"@storybook/react-docgen-typescript-plugin": "1.0.6--canary.9.cd77847.0",
"globby/fast-glob": "^3.2.11"
},
"dependencies": {
Expand Down Expand Up @@ -1439,7 +1440,6 @@
"@storybook/node-logger": "^6.5.16",
"@storybook/preview-web": "^6.5.16",
"@storybook/react": "^6.5.16",
"@storybook/react-docgen-typescript-plugin": "^1.0.1",
"@storybook/testing-react": "^1.3.0",
"@storybook/theming": "^6.5.16",
"@testing-library/jest-dom": "^5.16.5",
Expand Down Expand Up @@ -1756,8 +1756,8 @@
"tough-cookie": "^4.1.4",
"tree-kill": "^1.2.2",
"ts-morph": "^15.1.0",
"tsd": "^0.20.0",
"typescript": "4.9.5",
"tsd": "^0.31.1",
"typescript": "5.1.6",
"url-loader": "^2.2.0",
"val-loader": "^1.1.1",
"vinyl-fs": "^4.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class CoreVersionedRoute implements VersionedRoute {
{
path: this.path,
validate: passThroughValidation,
// @ts-expect-error upgrade typescript v5.1.6
options: this.getRouteConfigOptions(),
},
this.requestHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface State {

const convertToEui = (toast: ToastWithRichTitle): EuiToast => ({
...toast,
// @ts-expect-error upgrade typescript v5.1.6
title: toast.title instanceof Function ? <MountWrapper mount={toast.title} /> : toast.title,
text: toast.text instanceof Function ? <MountWrapper mount={toast.text} /> : toast.text,
});
Expand Down
29 changes: 29 additions & 0 deletions packages/kbn-alerting-types/alert_fields_type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { SerializedFieldFormat } from '@kbn/field-formats-plugin/common';
import type { IFieldSubType } from '@kbn/es-query';
import type { RuntimeField } from '@kbn/data-views-plugin/common';

export interface BrowserField {
aggregatable: boolean;
category: string;
description?: string | null;
example?: string | number | null;
fields: Readonly<Record<string, Partial<BrowserField>>>;
format?: SerializedFieldFormat;
indexes: string[];
name: string;
searchable: boolean;
type: string;
subType?: IFieldSubType;
readFromDocValues: boolean;
runtimeField?: RuntimeField;
}

export type BrowserFields = Record<string, Partial<BrowserField>>;
3 changes: 2 additions & 1 deletion packages/kbn-alerting-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

export * from './action_group_types';
export * from './action_variable';
export * from './alert_fields_type';
export * from './alert_type';
export * from './alerting_framework_health_types';
export * from './builtin_action_groups_types';
export * from './circuit_breaker_message_header';
export * from './r_rule_types';
export * from './rule_notify_when_type';
export * from './search_strategy_types';
export * from './rule_type_types';
export * from './rule_types';
export * from './search_strategy_types';
2 changes: 2 additions & 0 deletions packages/kbn-alerting-types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"@kbn/rrule",
"@kbn/core",
"@kbn/es-query",
"@kbn/field-formats-plugin",
"@kbn/data-views-plugin",
"@kbn/search-types"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { httpServiceMock } from '@kbn/core/public/mocks';
import { fetchAlertsFields } from '.';
import { AlertConsumers } from '@kbn/rule-data-utils';

describe('fetchAlertsFields', () => {
const http = httpServiceMock.createStartContract();
test('should call the browser_fields API with the correct parameters', async () => {
const featureIds = [AlertConsumers.STACK_ALERTS];
http.get.mockResolvedValueOnce({
browserFields: { fakeCategory: {} },
fields: [
{
name: 'fakeCategory',
},
],
});
const result = await fetchAlertsFields({ http, featureIds });
expect(result).toEqual({
browserFields: { fakeCategory: {} },
fields: [
{
name: 'fakeCategory',
},
],
});
expect(http.get).toHaveBeenLastCalledWith('/internal/rac/alerts/browser_fields', {
query: { featureIds },
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { FieldDescriptor } from '@kbn/data-views-plugin/server';
import type { BrowserFields } from '@kbn/alerting-types';
import type { FetchAlertsFieldsParams } from './types';
import { BASE_RAC_ALERTS_API_PATH } from '../../constants';

export const fetchAlertsFields = ({ http, featureIds }: FetchAlertsFieldsParams) =>
http.get<{ browserFields: BrowserFields; fields: FieldDescriptor[] }>(
`${BASE_RAC_ALERTS_API_PATH}/browser_fields`,
{
query: { featureIds },
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export * from './fetch_alerts_fields';
export * from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,16 @@
* Side Public License, v 1.
*/

import { HttpSetup } from '@kbn/core-http-browser';
import { ValidFeatureId } from '@kbn/rule-data-utils';
import { HttpSetup } from '@kbn/core/public';
import { FieldSpec } from '@kbn/data-views-plugin/common';
import { BASE_RAC_ALERTS_API_PATH } from '../constants';

export async function fetchAlertFields({
http,
featureIds,
}: {
export interface FetchAlertsFieldsParams {
// Dependencies
http: HttpSetup;

// Params
/**
* Array of feature ids used for authorization and area-based filtering
*/
featureIds: ValidFeatureId[];
}): Promise<FieldSpec[]> {
const { fields: alertFields = [] } = await http.get<{ fields: FieldSpec[] }>(
`${BASE_RAC_ALERTS_API_PATH}/browser_fields`,
{
query: { featureIds },
}
);
return alertFields;
}
13 changes: 7 additions & 6 deletions packages/kbn-alerts-ui-shared/src/common/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
* Side Public License, v 1.
*/

export * from './fetch_ui_health_status';
export * from './fetch_alerting_framework_health';
export * from './fetch_ui_config';
export * from './create_rule';
export * from './update_rule';
export * from './resolve_rule';
export * from './fetch_connectors';
export * from './fetch_alerting_framework_health';
export * from './fetch_alerts_fields';
export * from './fetch_connector_types';
export * from './fetch_connectors';
export * from './fetch_rule_type_aad_template_fields';
export * from './fetch_ui_config';
export * from './fetch_ui_health_status';
export * from './resolve_rule';
export * from './update_rule';
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { AlertConsumers, ValidFeatureId } from '@kbn/rule-data-utils';
import type { ToastsStart, HttpStart } from '@kbn/core/public';

import { useQuery } from '@tanstack/react-query';
import { useFetchAlertsFieldsQuery } from './use_fetch_alerts_fields_query';
import { fetchAlertIndexNames } from '../apis/fetch_alert_index_names';
import { fetchAlertFields } from '../apis/fetch_alert_fields';

export interface UseAlertDataViewResult {
dataViews?: DataView[];
Expand Down Expand Up @@ -45,10 +45,6 @@ export function useAlertDataView(props: UseAlertDataViewProps): UseAlertDataView
return fetchAlertIndexNames({ http, features });
};

const queryAlertFieldsFn = () => {
return fetchAlertFields({ http, featureIds });
};

const onErrorFn = () => {
toasts.addDanger(
i18n.translate('alertsUIShared.hooks.useAlertDataView.useAlertDataMessage', {
Expand All @@ -72,18 +68,19 @@ export function useAlertDataView(props: UseAlertDataViewProps): UseAlertDataView
});

const {
data: alertFields,
data: { fields: alertFields },
isSuccess: isAlertFieldsSuccess,
isInitialLoading: isAlertFieldsInitialLoading,
isLoading: isAlertFieldsLoading,
} = useQuery({
queryKey: ['loadAlertFields', features],
queryFn: queryAlertFieldsFn,
onError: onErrorFn,
refetchOnWindowFocus: false,
staleTime: 60 * 1000,
enabled: hasNoSecuritySolution,
});
} = useFetchAlertsFieldsQuery(
{ http, featureIds },
{
onError: onErrorFn,
refetchOnWindowFocus: false,
staleTime: 60 * 1000,
enabled: hasNoSecuritySolution,
}
);

useEffect(() => {
return () => {
Expand Down
Loading

0 comments on commit ee6d51e

Please sign in to comment.