Skip to content

Commit

Permalink
Merge branch 'main' into eui-v88.4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Watson authored Sep 27, 2023
2 parents 59efe98 + 05c637f commit e1d8017
Show file tree
Hide file tree
Showing 96 changed files with 572 additions and 427 deletions.
3 changes: 3 additions & 0 deletions test/plugin_functional/test_suites/core_plugins/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.license_management.ui.enabled (boolean)',
'xpack.maps.preserveDrawingBuffer (boolean)',
'xpack.maps.showMapsInspectorAdapter (boolean)',
'xpack.ml.ad.enabled (boolean)',
'xpack.ml.dfa.enabled (boolean)',
'xpack.ml.nlp.enabled (boolean)',
'xpack.osquery.actionEnabled (boolean)',
'xpack.remote_clusters.ui.enabled (boolean)',
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ export interface FullTimeRangeSelectorProps {
* @param value - The time field range response.
*/
apiPath?: SetFullTimeRangeApiPath;
/**
* Optional flag to disable the frozen data tier choice.
*/
hideFrozenDataTierChoice?: boolean;
}

/**
Expand All @@ -96,13 +92,12 @@ export const FullTimeRangeSelector: FC<FullTimeRangeSelectorProps> = (props) =>
disabled,
callback,
apiPath,
hideFrozenDataTierChoice = false,
} = props;

const {
http,
notifications: { toasts },
isServerless,
showFrozenDataTierChoice,
} = useDatePickerContext();

// wrapper around setFullTimeRange to allow for the calling of the optional callBack prop
Expand All @@ -114,9 +109,7 @@ export const FullTimeRangeSelector: FC<FullTimeRangeSelectorProps> = (props) =>
toasts,
http,
query,
isServerless || hideFrozenDataTierChoice
? false
: frozenDataPreference === FROZEN_TIER_PREFERENCE.EXCLUDE,
showFrozenDataTierChoice ? frozenDataPreference === FROZEN_TIER_PREFERENCE.EXCLUDE : false,
apiPath
);
if (typeof callback === 'function' && fullTimeRange !== undefined) {
Expand All @@ -138,8 +131,7 @@ export const FullTimeRangeSelector: FC<FullTimeRangeSelectorProps> = (props) =>
toasts,
http,
query,
isServerless,
hideFrozenDataTierChoice,
showFrozenDataTierChoice,
frozenDataPreference,
apiPath,
callback,
Expand Down Expand Up @@ -230,7 +222,7 @@ export const FullTimeRangeSelector: FC<FullTimeRangeSelectorProps> = (props) =>
/>
</EuiButton>
</EuiToolTip>
{isServerless || hideFrozenDataTierChoice ? null : (
{showFrozenDataTierChoice ? (
<EuiFlexItem grow={false}>
<EuiPopover
id={'mlFullTimeRangeSelectorOption'}
Expand All @@ -256,7 +248,7 @@ export const FullTimeRangeSelector: FC<FullTimeRangeSelectorProps> = (props) =>
{popoverContent}
</EuiPopover>
</EuiFlexItem>
)}
) : null}
</EuiFlexGroup>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export interface DatePickerDependencies {
*/
i18n: I18nStart;
/**
* Optional flag to indicate whether kibana is running in serverless
* Optional flag to disable the frozen data tier choice.
*/
isServerless?: boolean;
showFrozenDataTierChoice?: boolean;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ export interface ChangePointDetectionAppStateProps {
/** App dependencies */
appDependencies: AiopsAppDependencies;
/** Optional flag to indicate whether kibana is running in serverless */
isServerless?: boolean;
showFrozenDataTierChoice?: boolean;
}

export const ChangePointDetectionAppState: FC<ChangePointDetectionAppStateProps> = ({
dataView,
savedSearch,
appDependencies,
isServerless = false,
showFrozenDataTierChoice = true,
}) => {
const datePickerDeps: DatePickerDependencies = {
...pick(appDependencies, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'i18n']),
uiSettingsKeys: UI_SETTINGS,
isServerless,
showFrozenDataTierChoice,
};

const warning = timeSeriesDataViewWarning(dataView, 'change_point_detection');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ export interface LogCategorizationAppStateProps {
/** App dependencies */
appDependencies: AiopsAppDependencies;
/** Optional flag to indicate whether kibana is running in serverless */
isServerless?: boolean;
showFrozenDataTierChoice?: boolean;
}

export const LogCategorizationAppState: FC<LogCategorizationAppStateProps> = ({
dataView,
savedSearch,
appDependencies,
isServerless = false,
showFrozenDataTierChoice = true,
}) => {
if (!dataView) return null;

Expand All @@ -56,7 +56,7 @@ export const LogCategorizationAppState: FC<LogCategorizationAppStateProps> = ({
const datePickerDeps: DatePickerDependencies = {
...pick(appDependencies, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'i18n']),
uiSettingsKeys: UI_SETTINGS,
isServerless,
showFrozenDataTierChoice,
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ export interface LogRateAnalysisAppStateProps {
/** Option to make main histogram sticky */
stickyHistogram?: boolean;
/** Optional flag to indicate whether kibana is running in serverless */
isServerless?: boolean;
showFrozenDataTierChoice?: boolean;
}

export const LogRateAnalysisAppState: FC<LogRateAnalysisAppStateProps> = ({
dataView,
savedSearch,
appDependencies,
stickyHistogram,
isServerless = false,
showFrozenDataTierChoice = true,
}) => {
if (!dataView) return null;

Expand All @@ -62,7 +62,7 @@ export const LogRateAnalysisAppState: FC<LogRateAnalysisAppStateProps> = ({
const datePickerDeps: DatePickerDependencies = {
...pick(appDependencies, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'i18n']),
uiSettingsKeys: UI_SETTINGS,
isServerless,
showFrozenDataTierChoice,
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface LogRateAnalysisContentWrapperProps {
*/
onAnalysisCompleted?: (d: LogRateAnalysisResultsData) => void;
/** Optional flag to indicate whether kibana is running in serverless */
isServerless?: boolean;
showFrozenDataTierChoice?: boolean;
}

export const LogRateAnalysisContentWrapper: FC<LogRateAnalysisContentWrapperProps> = ({
Expand All @@ -72,7 +72,7 @@ export const LogRateAnalysisContentWrapper: FC<LogRateAnalysisContentWrapperProp
barColorOverride,
barHighlightColorOverride,
onAnalysisCompleted,
isServerless = false,
showFrozenDataTierChoice = true,
}) => {
if (!dataView) return null;

Expand All @@ -85,6 +85,7 @@ export const LogRateAnalysisContentWrapper: FC<LogRateAnalysisContentWrapperProp
const datePickerDeps = {
...pick(appDependencies, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'i18n']),
uiSettingsKeys: UI_SETTINGS,
showFrozenDataTierChoice,
};

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export { muteAlertParamsSchema } from './schemas/latest';
export { muteAlertParamsSchema as muteAlertParamsSchemaV1 } from './schemas/v1';

export type { MuteAlertRequestParams } from './types/latest';
export type { MuteAlertRequestParams as MuteAlertRequestParamsV1 } from './types/v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export { muteAlertParamsSchema } from './v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { schema } from '@kbn/config-schema';

export const muteAlertParamsSchema = schema.object({
rule_id: schema.string(),
alert_id: schema.string(),
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@
* 2.0.
*/

import { useMlKibana } from './kibana_context';

export function useIsServerless(): boolean {
return useMlKibana().services.mlServices.isServerless;
}
export type { MuteAlertRequestParams } from './v1';
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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { TypeOf } from '@kbn/config-schema';
import { muteAlertParamsSchemaV1 } from '..';

export type MuteAlertRequestParams = TypeOf<typeof muteAlertParamsSchemaV1>;
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,37 @@
* 2.0.
*/

import { Rule } from '../../types';
import { WriteOperations, AlertingAuthorizationEntity } from '../../authorization';
import { retryIfConflicts } from '../../lib/retry_if_conflicts';
import { ruleAuditEvent, RuleAuditAction } from '../common/audit_events';
import { MuteOptions } from '../types';
import { RulesClientContext } from '../types';
import { updateMeta } from '../lib';
import Boom from '@hapi/boom';
import { updateRuleSo } from '../../../../data/rule/methods/update_rule_so';
import { muteAlertParamsSchema } from './schemas';
import type { MuteAlertParams } from './types';
import { Rule } from '../../../../types';
import { WriteOperations, AlertingAuthorizationEntity } from '../../../../authorization';
import { retryIfConflicts } from '../../../../lib/retry_if_conflicts';
import { ruleAuditEvent, RuleAuditAction } from '../../../../rules_client/common/audit_events';
import { RulesClientContext } from '../../../../rules_client/types';
import { updateMeta } from '../../../../rules_client/lib';

export async function muteInstance(
context: RulesClientContext,
{ alertId, alertInstanceId }: MuteOptions
params: MuteAlertParams
): Promise<void> {
try {
muteAlertParamsSchema.validate(params);
} catch (error) {
throw Boom.badRequest(`Failed to validate params: ${error.message}`);
}

return await retryIfConflicts(
context.logger,
`rulesClient.muteInstance('${alertId}')`,
async () => await muteInstanceWithOCC(context, { alertId, alertInstanceId })
`rulesClient.muteInstance('${params.alertId}')`,
async () => await muteInstanceWithOCC(context, params)
);
}

async function muteInstanceWithOCC(
context: RulesClientContext,
{ alertId, alertInstanceId }: MuteOptions
{ alertId, alertInstanceId }: MuteAlertParams
) {
const { attributes, version } = await context.unsecuredSavedObjectsClient.get<Rule>(
'alert',
Expand Down Expand Up @@ -68,15 +77,15 @@ async function muteInstanceWithOCC(
const mutedInstanceIds = attributes.mutedInstanceIds || [];
if (!attributes.muteAll && !mutedInstanceIds.includes(alertInstanceId)) {
mutedInstanceIds.push(alertInstanceId);
await context.unsecuredSavedObjectsClient.update(
'alert',
alertId,
updateMeta(context, {
await updateRuleSo({
savedObjectsClient: context.unsecuredSavedObjectsClient,
savedObjectsUpdateOptions: { version },
id: alertId,
updateRuleAttributes: updateMeta(context, {
mutedInstanceIds,
updatedBy: await context.getUserName(),
updatedAt: new Date().toISOString(),
}),
{ version }
);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export { muteAlertParamsSchema } from './mute_alert_params_schema';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { schema } from '@kbn/config-schema';

export const muteAlertParamsSchema = schema.object({
alertId: schema.string(),
alertInstanceId: schema.string(),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export type { MuteAlertParams } from './mute_alert_params';
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { TypeOf } from '@kbn/config-schema';
import { muteAlertParamsSchema } from '../schemas';

export type MuteAlertParams = TypeOf<typeof muteAlertParamsSchema>;
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { healthRoute } from './health';
import { resolveRuleRoute } from './resolve_rule';
import { ruleTypesRoute } from './rule_types';
import { muteAllRuleRoute } from './mute_all_rule';
import { muteAlertRoute } from './mute_alert';
import { muteAlertRoute } from './rule/apis/mute_alert/mute_alert';
import { unmuteAllRuleRoute } from './unmute_all_rule';
import { unmuteAlertRoute } from './unmute_alert';
import { updateRuleApiKeyRoute } from './update_rule_api_key';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

import { muteAlertRoute } from './mute_alert';
import { httpServiceMock } from '@kbn/core/server/mocks';
import { licenseStateMock } from '../lib/license_state.mock';
import { mockHandlerArguments } from './_mock_handler_arguments';
import { rulesClientMock } from '../rules_client.mock';
import { RuleTypeDisabledError } from '../lib/errors/rule_type_disabled';
import { licenseStateMock } from '../../../../lib/license_state.mock';
import { mockHandlerArguments } from '../../../_mock_handler_arguments';
import { rulesClientMock } from '../../../../rules_client.mock';
import { RuleTypeDisabledError } from '../../../../lib';

const rulesClient = rulesClientMock.create();
jest.mock('../lib/license_api_access', () => ({
jest.mock('../../../../lib/license_api_access', () => ({
verifyApiAccess: jest.fn(),
}));

Expand Down
Loading

0 comments on commit e1d8017

Please sign in to comment.