Skip to content

Commit

Permalink
Merge branch 'main' into feature/defend-insight-langgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
joeypoon authored Mar 4, 2025
2 parents 42a6855 + 02b9f8f commit 6b7aac1
Show file tree
Hide file tree
Showing 250 changed files with 2,877 additions and 1,426 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {
ControlGroupRendererApi,
type ControlStateTransform,
} from '@kbn/controls-plugin/public';
import { ViewMode } from '@kbn/embeddable-plugin/public';

const INPUT_KEY = 'kbnControls:saveExample:input';

Expand Down Expand Up @@ -210,7 +209,7 @@ export const EditExample = () => {
},
};
}}
viewMode={ViewMode.EDIT}
viewMode={'edit'}
/>
</EuiPanel>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ import { CONTROL_GROUP_TYPE } from '@kbn/controls-plugin/common';
import { ControlGroupApi } from '@kbn/controls-plugin/public';
import { CoreStart } from '@kbn/core/public';
import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import { ReactEmbeddableRenderer, ViewMode } from '@kbn/embeddable-plugin/public';
import { ReactEmbeddableRenderer } from '@kbn/embeddable-plugin/public';
import { AggregateQuery, Filter, Query, TimeRange } from '@kbn/es-query';
import { combineCompatibleChildrenApis } from '@kbn/presentation-containers';
import {
apiPublishesDataLoading,
HasUniqueId,
PublishesDataLoading,
useBatchedPublishingSubjects,
ViewMode as ViewModeType,
ViewMode,
} from '@kbn/presentation-publishing';
import { toMountPoint } from '@kbn/react-kibana-mount';

Expand All @@ -55,12 +55,12 @@ import {
const toggleViewButtons = [
{
id: `viewModeToggle_edit`,
value: ViewMode.EDIT,
value: 'edit',
label: 'Edit mode',
},
{
id: `viewModeToggle_view`,
value: ViewMode.VIEW,
value: 'view',
label: 'View mode',
},
];
Expand Down Expand Up @@ -95,7 +95,7 @@ export const ReactControlExample = ({
return new BehaviorSubject<[number, number] | undefined>(undefined);
}, []);
const viewMode$ = useMemo(() => {
return new BehaviorSubject<ViewModeType>(ViewMode.EDIT as ViewModeType);
return new BehaviorSubject<ViewMode>('edit');
}, []);
const saveNotification$ = useMemo(() => {
return new Subject<void>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import React, { useEffect, useState } from 'react';

import { ViewMode } from '@kbn/embeddable-plugin/public';
import type { DataView } from '@kbn/data-views-plugin/public';
import { EuiPanel, EuiSpacer, EuiText, EuiTitle } from '@elastic/eui';
import { controlGroupStateBuilder } from '@kbn/controls-plugin/public';
Expand Down Expand Up @@ -70,7 +69,7 @@ export const DashboardWithControlsExample = ({ dataView }: { dataView: DataView
return {
getInitialInput: () => ({
timeRange: { from: 'now-30d', to: 'now' },
viewMode: ViewMode.VIEW,
viewMode: 'view',
controlGroupState,
}),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
EuiTitle,
} from '@elastic/eui';
import { DashboardApi, DashboardRenderer } from '@kbn/dashboard-plugin/public';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import { useStateFromPublishingSubject } from '@kbn/presentation-publishing';

export const DualDashboardsExample = () => {
Expand All @@ -34,14 +33,14 @@ export const DualDashboardsExample = () => {
legend="View mode"
options={[
{
id: ViewMode.VIEW,
id: 'view',
label: 'View mode',
value: ViewMode.VIEW,
value: 'view',
},
{
id: ViewMode.EDIT,
id: 'edit',
label: 'Edit mode',
value: ViewMode.EDIT,
value: 'edit',
},
]}
idSelected={viewMode}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { buildPhraseFilter, Filter } from '@kbn/es-query';
import type { DataView } from '@kbn/data-views-plugin/public';
import { DashboardRenderer, DashboardCreationOptions } from '@kbn/dashboard-plugin/public';
import { EuiCode, EuiPanel, EuiSpacer, EuiText, EuiTitle } from '@elastic/eui';
import { ViewMode } from '@kbn/embeddable-plugin/public';

export const StaticByReferenceExample = ({
dashboardId,
Expand Down Expand Up @@ -51,7 +50,7 @@ export const StaticByReferenceExample = ({
const field = dataView.getFieldByName('machine.os.keyword');
let filter: Filter;
let creationOptions: DashboardCreationOptions = {
getInitialInput: () => ({ viewMode: ViewMode.VIEW }),
getInitialInput: () => ({ viewMode: 'view' }),
};
if (field) {
filter = buildPhraseFilter(field, 'win xp', dataView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import React from 'react';

import { ViewMode } from '@kbn/embeddable-plugin/public';
import { EuiPanel, EuiSpacer, EuiText, EuiTitle } from '@elastic/eui';
import type { DashboardPanelMap } from '@kbn/dashboard-plugin/common';
import { DashboardRenderer } from '@kbn/dashboard-plugin/public';
Expand All @@ -32,7 +31,7 @@ export const StaticByValueExample = () => {
return {
getInitialInput: () => ({
timeRange: { from: 'now-30d', to: 'now' },
viewMode: ViewMode.VIEW,
viewMode: 'view',
panels: panelsJson as DashboardPanelMap,
}),
};
Expand Down
19 changes: 0 additions & 19 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -3670,25 +3670,6 @@
"minimumReleaseAge": "7 days",
"enabled": true
},
{
"groupName": "react-syntax-highlighter",
"matchDepNames": [
"react-syntax-highlighter",
"@types/react-syntax-highlighter"
],
"reviewers": [
"team:obs-ux-infra_services-team"
],
"matchBaseBranches": [
"main"
],
"labels": [
"release_note:skip",
"backport:all-open"
],
"minimumReleaseAge": "7 days",
"enabled": true
},
{
"groupName": "native-hdr-histogram",
"matchDepNames": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,81 @@ describe('trackPerformanceMeasureEntries', () => {
expect(analyticsClientMock.reportEvent).toHaveBeenCalledWith('performance_metric', {
duration: 1000,
eventName: 'kibana:plugin_render_time',
meta: { query_range_secs: 86400, query_offset_secs: 0 },
meta: {
query_range_secs: 86400,
query_offset_secs: 0,
},
});
});

test('reports an analytics event with description metadata', () => {
setupMockPerformanceObserver([
{
name: '/',
entryType: 'measure',
startTime: 100,
duration: 1000,
detail: {
eventName: 'kibana:plugin_render_time',
type: 'kibana:performance',
meta: {
isInitialLoad: false,
description:
'[ttfmp_dependencies] onPageReady is called when the most important content is rendered',
},
},
},
]);
trackPerformanceMeasureEntries(analyticsClientMock, true);

expect(analyticsClientMock.reportEvent).toHaveBeenCalledTimes(1);
expect(analyticsClientMock.reportEvent).toHaveBeenCalledWith('performance_metric', {
duration: 1000,
eventName: 'kibana:plugin_render_time',
meta: {
is_initial_load: false,
query_range_secs: undefined,
query_offset_secs: undefined,
description:
'[ttfmp_dependencies] onPageReady is called when the most important content is rendered',
},
});
});

test('reports an analytics event with truncated description metadata', () => {
setupMockPerformanceObserver([
{
name: '/',
entryType: 'measure',
startTime: 100,
duration: 1000,
detail: {
eventName: 'kibana:plugin_render_time',
type: 'kibana:performance',
meta: {
isInitialLoad: false,
description:
'[ttfmp_dependencies] This is a very long long long long long long long long description. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque non risus in nunc tincidunt tincidunt. Proin vehicula, nunc at feugiat cursus, justo nulla fermentum lorem, non ultricies metus libero nec purus. Sed ut perspiciatis unde omnis iste natus.',
},
},
},
]);
trackPerformanceMeasureEntries(analyticsClientMock, true);
const truncatedDescription =
'[ttfmp_dependencies] This is a very long long long long long long long long description. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque non risus in nunc tincidunt tincidunt. Proin vehicula, nunc at feugiat cursus, justo nulla fermentum l';

expect(analyticsClientMock.reportEvent).toHaveBeenCalledTimes(1);
expect(analyticsClientMock.reportEvent).toHaveBeenCalledWith('performance_metric', {
duration: 1000,
eventName: 'kibana:plugin_render_time',
meta: {
is_initial_load: false,
query_range_secs: undefined,
query_offset_secs: undefined,
description: truncatedDescription,
},
});

expect(truncatedDescription.length).toBe(256);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { AnalyticsClient } from '@elastic/ebt/client';
import { reportPerformanceMetricEvent } from '@kbn/ebt-tools';

const MAX_CUSTOM_METRICS = 9;
const MAX_DESCRIPTION_LENGTH = 256;
// The keys and values for the custom metrics are limited to 9 pairs
const ALLOWED_CUSTOM_METRICS_KEYS_VALUES = Array.from({ length: MAX_CUSTOM_METRICS }, (_, i) => [
`key${i + 1}`,
Expand All @@ -28,6 +29,8 @@ export function trackPerformanceMeasureEntries(analytics: AnalyticsClient, isDev
const target = entry?.name;
const duration = entry.duration;
const meta = entry.detail?.meta;
const description = meta?.description;

const customMetrics = Object.keys(entry.detail?.customMetrics ?? {}).reduce(
(acc, metric) => {
if (ALLOWED_CUSTOM_METRICS_KEYS_VALUES.includes(metric)) {
Expand Down Expand Up @@ -55,6 +58,13 @@ export function trackPerformanceMeasureEntries(analytics: AnalyticsClient, isDev
);
}

if (description?.length > MAX_DESCRIPTION_LENGTH) {
// eslint-disable-next-line no-console
console.warn(
`The description for the measure: ${target} is too long. The maximum length is ${MAX_DESCRIPTION_LENGTH}. Strings longer than ${MAX_DESCRIPTION_LENGTH} will not be indexed or stored`
);
}

// eslint-disable-next-line no-console
console.log(`The measure ${target} completed in ${duration / 1000}s`);
}
Expand All @@ -74,6 +84,7 @@ export function trackPerformanceMeasureEntries(analytics: AnalyticsClient, isDev
meta: {
query_range_secs: meta?.queryRangeSecs,
query_offset_secs: meta?.queryOffsetSecs,
description: description?.slice(0, MAX_DESCRIPTION_LENGTH),
is_initial_load: meta?.isInitialLoad,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
PublishesSavedSearch,
HasTimeRange,
} from '@kbn/discover-plugin/public';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import { LicensingPluginStart } from '@kbn/licensing-plugin/public';
import {
apiCanAccessViewMode,
Expand Down Expand Up @@ -148,7 +147,7 @@ export class ReportingCsvPanelAction implements ActionDefinition<EmbeddableApiCo
return false;
}

return getInheritedViewMode(embeddable) !== ViewMode.EDIT;
return getInheritedViewMode(embeddable) !== 'edit';
};

private executeGenerate = async (params: ExecutionParams) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"@kbn/discover-utils",
"@kbn/saved-search-plugin",
"@kbn/discover-plugin",
"@kbn/embeddable-plugin",
"@kbn/ui-actions-plugin",
"@kbn/react-kibana-mount",
"@kbn/reporting-public",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { ViewMode } from '@kbn/embeddable-plugin/common';
import { ViewMode } from '@kbn/presentation-publishing';
import { useCallback, useEffect, useState } from 'react';

interface UseViewEditModeArgs {
initialMode?: ViewMode;
}

export const useViewEditMode = ({ initialMode = ViewMode.VIEW }: UseViewEditModeArgs) => {
export const useViewEditMode = ({ initialMode = 'view' }: UseViewEditModeArgs) => {
const [filterGroupMode, setFilterGroupMode] = useState(initialMode);

const [hasPendingChanges, setHasPendingChanges] = useState(false);
Expand All @@ -33,15 +33,15 @@ export const useViewEditMode = ({ initialMode = ViewMode.VIEW }: UseViewEditMode
}, [hasPendingChanges]);

const switchToEditMode = useCallback(() => {
setFilterGroupMode(ViewMode.EDIT);
setFilterGroupMode('edit');
}, []);

const switchToViewMode = useCallback(() => {
setHasPendingChanges(false);
setFilterGroupMode(ViewMode.VIEW);
setFilterGroupMode('view');
}, []);

const isViewMode = filterGroupMode === ViewMode.VIEW;
const isViewMode = filterGroupMode === 'view';

return {
filterGroupMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type RuleTypeWithDescription = RuleType<string, string> & { description?:
export type RuleTypeIndexWithDescriptions = Map<string, RuleTypeWithDescription>;

export type RuleTypeParams = Record<string, unknown>;
export type RuleTypeMetaData = Record<string, unknown>;

export interface RuleFormBaseErrors {
name?: string[];
Expand Down Expand Up @@ -104,7 +105,7 @@ export interface RuleTypeParamsExpressionProps<
metadata?: MetaData;
charts: ChartsPluginSetup;
data: DataPublicPluginStart;
dataViews: DataViewsPublicPluginStart;
dataViews?: DataViewsPublicPluginStart;
unifiedSearch: UnifiedSearchPublicPluginStart;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"@kbn/unified-search-plugin",
"@kbn/es-query",
"@kbn/controls-plugin",
"@kbn/embeddable-plugin",
"@kbn/core-http-browser",
"@kbn/core-notifications-browser",
"@kbn/kibana-utils-plugin",
Expand All @@ -34,5 +33,6 @@
"@kbn/core-http-browser-mocks",
"@kbn/core-notifications-browser-mocks",
"@kbn/shared-ux-table-persist",
"@kbn/presentation-publishing",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
// Storybook react doesn't declare this in its typings, but it's there.
declare module '@storybook/react/standalone';

// Storybook references this module. It's @ts-ignored in the codebase but when
// built into its dist it strips that out. Add it here to avoid a type checking
// error.
//
// See https://github.com/storybookjs/storybook/issues/11684
declare module 'react-syntax-highlighter/dist/cjs/create-element';
declare module 'react-syntax-highlighter/dist/cjs/prism-light';

// Storybook uses this module and its types are defined in the source but not in the type output
declare module 'file-system-cache' {
interface Options {
Expand Down
Loading

0 comments on commit 6b7aac1

Please sign in to comment.