Skip to content

Commit

Permalink
Merge branch 'main' into exception-import-space-agnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallmain authored Nov 12, 2024
2 parents b677f20 + 06986e4 commit 145d2b1
Show file tree
Hide file tree
Showing 107 changed files with 2,110 additions and 967 deletions.
13 changes: 8 additions & 5 deletions oas_docs/output/kibana.serverless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39976,17 +39976,20 @@ components:
type: object
properties:
unit:
enum:
- s
- m
- h
type: string
$ref: >-
#/components/schemas/Security_Detections_API_AlertSuppressionDurationUnit
value:
minimum: 1
type: integer
required:
- value
- unit
Security_Detections_API_AlertSuppressionDurationUnit:
enum:
- s
- m
- h
type: string
Security_Detections_API_AlertSuppressionGroupBy:
items:
type: string
Expand Down
13 changes: 8 additions & 5 deletions oas_docs/output/kibana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48220,17 +48220,20 @@ components:
type: object
properties:
unit:
enum:
- s
- m
- h
type: string
$ref: >-
#/components/schemas/Security_Detections_API_AlertSuppressionDurationUnit
value:
minimum: 1
type: integer
required:
- value
- unit
Security_Detections_API_AlertSuppressionDurationUnit:
enum:
- s
- m
- h
type: string
Security_Detections_API_AlertSuppressionGroupBy:
items:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export const initFindFieldsMetadataRoute = ({
.addVersion(
{
version: '1',
security: {
authz: {
enabled: false,
reason: 'This route is opted out from authorization',
},
},
validate: {
request: {
query: createValidationFunction(fieldsMetadataV1.findFieldsMetadataRequestQueryRT),
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/server/services/app_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ class AppContextService {
// soClient as kibana internal users, be careful on how you use it, security is not enabled
return appContextService.getSavedObjects().getScopedClient(fakeRequest, {
excludedExtensions: [SECURITY_EXTENSION_ID, SPACES_EXTENSION_ID],
includedHiddenTypes: [UNINSTALL_TOKENS_SAVED_OBJECT_TYPE],
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { appContextService } from '../../app_context';
import { agentPolicyService, getAgentPolicySavedObjectType } from '../../agent_policy';
import { isSpaceAwarenessEnabled } from '../../spaces/helpers';

interface UninstallTokenSOAttributes {
export interface UninstallTokenSOAttributes {
policy_id: string;
token: string;
token_plain: string;
Expand Down
28 changes: 28 additions & 0 deletions x-pack/plugins/fleet/server/services/spaces/agent_policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ describe('updateAgentPolicySpaces', () => {
jest
.mocked(appContextService.getInternalUserSOClientWithoutSpaceExtension())
.updateObjectsSpaces.mockResolvedValue({ objects: [] });

jest
.mocked(appContextService.getInternalUserSOClientWithoutSpaceExtension())
.find.mockResolvedValue({
total: 1,
page: 1,
per_page: 100,
saved_objects: [
{
id: 'token1',
attributes: {
namespaces: ['default'],
},
} as any,
],
});
});

it('does nothings if agent policy already in correct space', async () => {
Expand Down Expand Up @@ -87,6 +103,18 @@ describe('updateAgentPolicySpaces', () => {
['default'],
{ namespace: 'default', refresh: 'wait_for' }
);

expect(
jest.mocked(appContextService.getInternalUserSOClientWithoutSpaceExtension()).bulkUpdate
).toBeCalledWith([
{
id: 'token1',
type: 'fleet-uninstall-tokens',
attributes: {
namespaces: ['test'],
},
},
]);
});

it('throw when trying to change space to a policy with reusable package policies', async () => {
Expand Down
22 changes: 22 additions & 0 deletions x-pack/plugins/fleet/server/services/spaces/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
AGENTS_INDEX,
AGENT_POLICY_SAVED_OBJECT_TYPE,
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
SO_SEARCH_LIMIT,
UNINSTALL_TOKENS_SAVED_OBJECT_TYPE,
} from '../../../common/constants';

import { appContextService } from '../app_context';
Expand All @@ -22,6 +24,7 @@ import { packagePolicyService } from '../package_policy';
import { FleetError, HostedAgentPolicyRestrictionRelatedError } from '../../errors';

import { isSpaceAwarenessEnabled } from './helpers';
import type { UninstallTokenSOAttributes } from '../security/uninstall_token_service';

export async function updateAgentPolicySpaces({
agentPolicyId,
Expand Down Expand Up @@ -112,6 +115,25 @@ export async function updateAgentPolicySpaces({
}
}

// Update uninstall tokens
const uninstallTokensRes = await soClient.find<UninstallTokenSOAttributes>({
perPage: SO_SEARCH_LIMIT,
type: UNINSTALL_TOKENS_SAVED_OBJECT_TYPE,
filter: `${UNINSTALL_TOKENS_SAVED_OBJECT_TYPE}.attributes.policy_id:"${agentPolicyId}"`,
});

if (uninstallTokensRes.total > 0) {
await soClient.bulkUpdate(
uninstallTokensRes.saved_objects.map((so) => ({
id: so.id,
type: UNINSTALL_TOKENS_SAVED_OBJECT_TYPE,
attributes: {
namespaces: newSpaceIds,
},
}))
);
}

// Update fleet server index agents, enrollment api keys
await esClient.updateByQuery({
index: ENROLLMENT_API_KEYS_INDEX,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ export const uiSettings: Record<string, UiSettingsParams> = {
description: i18n.translate('xpack.infra.enableLogsStreamDescription', {
defaultMessage: 'Enables the legacy Logs Stream application and dashboard panel. ',
}),
deprecation: {
message: i18n.translate('xpack.infra.enableLogsStreamDeprecationWarning', {
defaultMessage:
'Logs Stream is deprecated, and this setting will be removed in Kibana 9.0.',
}),
docLinksKey: 'generalSettings',
},
type: 'boolean',
schema: schema.boolean(),
requiresPageReload: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,28 @@ import { EuiCallOut } from '@elastic/eui';
import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiButton } from '@elastic/eui';
import {
AllDatasetsLocatorParams,
ALL_DATASETS_LOCATOR_ID,
DatasetLocatorParams,
} from '@kbn/deeplinks-observability';
import { getRouterLinkProps } from '@kbn/router-utils';
import useLocalStorage from 'react-use/lib/useLocalStorage';

import { euiThemeVars } from '@kbn/ui-theme';
import { css } from '@emotion/css';
import { LocatorPublic } from '@kbn/share-plugin/common';
import { DISCOVER_APP_LOCATOR, DiscoverAppLocatorParams } from '@kbn/discover-plugin/common';
import { useKibanaContextForPlugin } from '../hooks/use_kibana';

const pageConfigurations = {
stream: {
dismissalStorageKey: 'log_stream_deprecation_callout_dismissed',
message: i18n.translate('xpack.infra.logsDeprecationCallout.p.theNewLogsExplorerLabel', {
message: i18n.translate('xpack.infra.logsDeprecationCallout.stream.exploreWithDiscover', {
defaultMessage:
'The new Logs Explorer makes viewing and inspecting your logs easier with more features, better performance, and more intuitive navigation. We recommend switching to Logs Explorer, as it will replace Logs Stream in a future version.',
'Logs Stream and Logs Explorer are set to be deprecated. Switch to Discover which now includes their functionality plus more features, better performance, and more intuitive navigation. ',
}),
},
settings: {
dismissalStorageKey: 'log_settings_deprecation_callout_dismissed',
message: i18n.translate(
'xpack.infra.logsSettingsDeprecationCallout.p.theNewLogsExplorerLabel',
{
defaultMessage:
'These settings only apply to the legacy Logs Stream app, and we do not recommend configuring them. Instead, use Logs Explorer which makes viewing and inspecting your logs easier with more features, better performance, and more intuitive navigation.',
}
),
message: i18n.translate('xpack.infra.logsDeprecationCallout.settings.exploreWithDiscover', {
defaultMessage:
'These settings only apply to the legacy Logs Stream app. Switch to Discover for the same functionality plus more features, better performance, and more intuitive navigation.',
}),
},
};

Expand All @@ -60,10 +52,9 @@ export const LogsDeprecationCallout = ({ page }: LogsDeprecationCalloutProps) =>

const [isDismissed, setDismissed] = useLocalStorage(dismissalStorageKey, false);

const allDatasetLocator =
share.url.locators.get<AllDatasetsLocatorParams>(ALL_DATASETS_LOCATOR_ID);
const discoverLocator = share.url.locators.get<DiscoverAppLocatorParams>(DISCOVER_APP_LOCATOR);

if (isDismissed || !(allDatasetLocator && discover?.show && fleet?.read)) {
if (isDismissed || !(discoverLocator && discover?.show && fleet?.read)) {
return null;
}

Expand All @@ -81,19 +72,19 @@ export const LogsDeprecationCallout = ({ page }: LogsDeprecationCalloutProps) =>
<p>{message}</p>
<EuiButton
fill
data-test-subj="infraLogsDeprecationCalloutTryLogsExplorerButton"
data-test-subj="infraLogsDeprecationCalloutGoToDiscoverButton"
color="warning"
{...getLogsExplorerLinkProps(allDatasetLocator)}
{...getDiscoverLinkProps(discoverLocator)}
>
{i18n.translate('xpack.infra.logsDeprecationCallout.tryLogsExplorerButtonLabel', {
defaultMessage: 'Try Logs Explorer',
{i18n.translate('xpack.infra.logsDeprecationCallout.goToDiscoverButtonLabel', {
defaultMessage: 'Go to Discover',
})}
</EuiButton>
</EuiCallOut>
);
};

const getLogsExplorerLinkProps = (locator: LocatorPublic<DatasetLocatorParams>) => {
const getDiscoverLinkProps = (locator: LocatorPublic<DiscoverAppLocatorParams>) => {
return getRouterLinkProps({
href: locator.getRedirectUrl({}),
onClick: () => locator.navigate({}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,26 @@ export const observabilityAppTitle = i18n.translate(
}
);

export const betaBadgeTitle = i18n.translate('xpack.observabilityLogsExplorer.betaBadgeTitle', {
defaultMessage: 'Beta',
});
export const deprecationBadgeTitle = i18n.translate(
'xpack.observabilityLogsExplorer.deprecationBadgeTitle',
{
defaultMessage: 'Deprecation notice',
}
);

export const deprecationBadgeDescription = i18n.translate(
'xpack.observabilityLogsExplorer.deprecationBadgeDescription',
{
defaultMessage:
'Logs Stream and Logs Explorer are set to be deprecated. Switch to Discover which now includes their functionality plus more features and better performance.',
}
);

export const betaBadgeDescription = i18n.translate(
'xpack.observabilityLogsExplorer.betaBadgeDescription',
export const deprecationBadgeGuideline = i18n.translate(
'xpack.observabilityLogsExplorer.deprecationBadgeGuideline',
{
defaultMessage: 'This application is in beta and therefore subject to change.',
defaultMessage:
'You can temporarily access Logs Stream by re-enabling it in Advanced Settings.',
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import { LogsExplorerTabs } from '@kbn/discover-plugin/public';
import React, { useEffect, useState } from 'react';
import useObservable from 'react-use/lib/useObservable';
import { filter, take } from 'rxjs';
import { betaBadgeDescription, betaBadgeTitle } from '../../common/translations';
import {
deprecationBadgeDescription,
deprecationBadgeGuideline,
deprecationBadgeTitle,
} from '../../common/translations';
import { useKibanaContextForPlugin } from '../utils/use_kibana';
import { ConnectedDiscoverLink } from './discover_link';
import { FeedbackLink } from './feedback_link';
Expand Down Expand Up @@ -59,13 +63,7 @@ const ProjectTopNav = () => {
`}
>
<EuiHeaderSectionItem>
<EuiBetaBadge
size="s"
iconType="beta"
label={betaBadgeTitle}
tooltipContent={betaBadgeDescription}
alignment="middle"
/>
<DeprecationNoticeBadge />
</EuiHeaderSectionItem>
<EuiHeaderSectionItem>
<EuiHeaderLinks gutterSize="xs">
Expand Down Expand Up @@ -115,15 +113,6 @@ const ClassicTopNav = () => {
margin-left: ${euiThemeVars.euiSizeM};
`}
>
<EuiHeaderSectionItem>
<EuiBetaBadge
size="s"
iconType="beta"
label={betaBadgeTitle}
tooltipContent={betaBadgeDescription}
alignment="middle"
/>
</EuiHeaderSectionItem>
<EuiHeaderSectionItem>
<FeedbackLink />
</EuiHeaderSectionItem>
Expand All @@ -145,6 +134,9 @@ const ClassicTopNav = () => {
<EuiHeaderSection data-test-subj="logsExplorerHeaderMenu">
<EuiHeaderSectionItem>
<EuiHeaderLinks gutterSize="xs">
<EuiHeaderSectionItem>
<DeprecationNoticeBadge />
</EuiHeaderSectionItem>
<ConnectedDiscoverLink />
<ConditionalVerticalRule Component={ConnectedDatasetQualityLink()} />
<VerticalRule />
Expand All @@ -171,3 +163,19 @@ const ConditionalVerticalRule = ({ Component }: { Component: JSX.Element | null
{Component}
</>
);

const DeprecationNoticeBadge = () => (
<EuiBetaBadge
label={deprecationBadgeTitle}
color="subdued"
tooltipContent={
<>
{deprecationBadgeDescription}
<br />
<br />
{deprecationBadgeGuideline}
</>
}
alignment="middle"
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -555,10 +555,15 @@ export const RuleExceptionList = z.object({
namespace_type: z.enum(['agnostic', 'single']),
});

export type AlertSuppressionDurationUnit = z.infer<typeof AlertSuppressionDurationUnit>;
export const AlertSuppressionDurationUnit = z.enum(['s', 'm', 'h']);
export type AlertSuppressionDurationUnitEnum = typeof AlertSuppressionDurationUnit.enum;
export const AlertSuppressionDurationUnitEnum = AlertSuppressionDurationUnit.enum;

export type AlertSuppressionDuration = z.infer<typeof AlertSuppressionDuration>;
export const AlertSuppressionDuration = z.object({
value: z.number().int().min(1),
unit: z.enum(['s', 'm', 'h']),
unit: AlertSuppressionDurationUnit,
});

/**
Expand Down
Loading

0 comments on commit 145d2b1

Please sign in to comment.