Skip to content

Commit

Permalink
Merge branch 'main' into version-enable-rule-api
Browse files Browse the repository at this point in the history
  • Loading branch information
adcoelho authored Jul 24, 2024
2 parents 4bd3fca + f918fdc commit 2582b59
Show file tree
Hide file tree
Showing 195 changed files with 756 additions and 9,525 deletions.
2 changes: 1 addition & 1 deletion .buildkite/ftr_oblt_stateful_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enabled:
- x-pack/test/api_integration/apis/synthetics/config.ts
- x-pack/test/api_integration/apis/slos/config.ts
- x-pack/test/api_integration/apis/uptime/config.ts
- x-pack/test/api_integration/apis/entity_manager/config.ts
- x-pack/test/apm_api_integration/basic/config.ts
- x-pack/test/apm_api_integration/cloud/config.ts
- x-pack/test/apm_api_integration/rules/config.ts
Expand All @@ -48,4 +49,3 @@ enabled:
- x-pack/test/observability_ai_assistant_functional/enterprise/config.ts
- x-pack/test/profiling_api_integration/cloud/config.ts
- x-pack/test/functional/apps/apm/config.ts

2 changes: 1 addition & 1 deletion docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ The plugin exposes the static DefaultEditorController class to consume.
|{kib-repo}blob/{branch}/x-pack/plugins/cloud/README.md[cloud]
|The cloud plugin adds Cloud-specific features to Kibana.
|The cloud plugin exposes Cloud-specific metadata to Kibana.
|{kib-repo}blob/{branch}/x-pack/plugins/cloud_integrations/cloud_chat/README.md[cloudChat]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class HapiResponseAdapter {
return response;
}

private toError(kibanaResponse: KibanaResponse<ResponseError | Buffer | stream.Readable>) {
private toError(kibanaResponse: KibanaResponse<ResponseError>) {
const { payload } = kibanaResponse;

// Special case for when we are proxying requests and want to enable streaming back error responses opaquely.
Expand Down Expand Up @@ -153,7 +153,12 @@ function getErrorMessage(payload?: ResponseError): string {
if (!payload) {
throw new Error('expected error message to be provided');
}
if (typeof payload === 'string') return payload;
if (typeof payload === 'string') {
return payload;
}
if (isStreamOrBuffer(payload)) {
throw new Error(`can't resolve error message from stream or buffer`);
}
// for ES response errors include nested error reason message. it doesn't contain sensitive data.
if (isElasticsearchResponseError(payload)) {
return `[${payload.message}]: ${
Expand All @@ -164,6 +169,10 @@ function getErrorMessage(payload?: ResponseError): string {
return getErrorMessage(payload.message);
}

function isStreamOrBuffer(payload: ResponseError): payload is stream.Stream | Buffer {
return Buffer.isBuffer(payload) || stream.isReadable(payload as stream.Readable);
}

function getErrorAttributes(payload?: ResponseError): ResponseErrorAttributes | undefined {
return typeof payload === 'object' && 'attributes' in payload ? payload.attributes : undefined;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/http/core-http-server/src/router/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export type ResponseErrorAttributes = Record<string, any>;
*/
export type ResponseError =
| string
| Buffer
| Stream
| Error
| {
message: string | Error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Side Public License, v 1.
*/

import type { Stream } from 'stream';
import type {
CustomHttpResponseOptions,
HttpResponseOptions,
Expand Down Expand Up @@ -139,7 +138,7 @@ export interface KibanaErrorResponseFactory {
* Creates an error response with defined status code and payload.
* @param options - {@link CustomHttpResponseOptions} configures HTTP response headers, error message and other error details to pass to the client
*/
customError(options: CustomHttpResponseOptions<ResponseError | Buffer | Stream>): IKibanaResponse;
customError(options: CustomHttpResponseOptions<ResponseError>): IKibanaResponse;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions packages/kbn-analytics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# `@kbn/analytics`

> [!NOTE]
> The term _analytics_ here refers to _Usage Analytics_, and should not be confused with the Kibana (Data) Analytics tools.
> [!IMPORTANT]
> This package is exclusively used by the plugin `usage_collection` and it's not expected to be used elsewhere.
> If you are still here for _Usage Analytics_, you might be looking for [core-analytics](../core/analytics), the [EBT packages](../analytics).
This package implements the report that batches updates from Application Usage, UI Counters, and User Agent.
It defines the contract of the report, and the strategy to ship it to the server.

27 changes: 27 additions & 0 deletions test/plugin_functional/plugins/core_http/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

import { Readable } from 'stream';
import type { Plugin, CoreSetup } from '@kbn/core/server';

export class CoreHttpPlugin implements Plugin {
Expand Down Expand Up @@ -87,6 +88,32 @@ export class CoreHttpPlugin implements Plugin {
},
});
});

router.get(
{
path: '/api/core_http/error_stream',
validate: false,
},
async (ctx, req, res) => {
return res.customError({
body: Readable.from(['error stream'], { objectMode: false }),
statusCode: 501,
});
}
);

router.get(
{
path: '/api/core_http/error_buffer',
validate: false,
},
async (ctx, req, res) => {
return res.customError({
body: Buffer.from('error buffer', 'utf8'),
statusCode: 501,
});
}
);
}

public start() {}
Expand Down
38 changes: 38 additions & 0 deletions test/plugin_functional/test_suites/core_plugins/error_response.ts
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 expect from '@kbn/expect';
import '@kbn/core-provider-plugin/types';
import { PluginFunctionalProviderContext } from '../../services';

export default function ({ getService }: PluginFunctionalProviderContext) {
const supertest = getService('supertest');

// routes defined in the `core_http` test plugin
describe('Custom errors', () => {
it('can serve an error response from stream', async () => {
await supertest
.get('/api/core_http/error_stream')
.expect(501)
.then((response) => {
const res = response.body.toString();
expect(res).to.eql('error stream');
});
});

it('can serve an error response from buffer', async () => {
await supertest
.get('/api/core_http/error_buffer')
.expect(501)
.then((response) => {
const res = response.body.toString();
expect(res).to.eql('error buffer');
});
});
});
}
1 change: 1 addition & 0 deletions test/plugin_functional/test_suites/core_plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export default function ({ loadTestFile }: PluginFunctionalProviderContext) {
loadTestFile(require.resolve('./http'));
loadTestFile(require.resolve('./http_versioned'));
loadTestFile(require.resolve('./dynamic_contract_resolving'));
loadTestFile(require.resolve('./error_response'));
});
}
2 changes: 2 additions & 0 deletions test/plugin_functional/test_suites/core_plugins/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.cloud_integrations.full_story.eventTypesAllowlist (array)',
'xpack.cloud_integrations.full_story.pageVarsDebounceTime (duration)',
'xpack.cloud.id (string)',
'xpack.cloud.organization_id (string)',
'xpack.cloud.organization_url (string)',
'xpack.cloud.billing_url (string)',
'xpack.cloud.profile_url (string)',
Expand All @@ -256,6 +257,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.cloud.serverless.project_id (string)',
'xpack.cloud.serverless.project_name (string)',
'xpack.cloud.serverless.project_type (string)',
'xpack.cloud.serverless.orchestrator_target (string)',
'xpack.cloud.onboarding.default_solution (string)',
'xpack.discoverEnhanced.actions.exploreDataInChart.enabled (boolean)',
'xpack.discoverEnhanced.actions.exploreDataInContextMenu.enabled (boolean)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,11 @@
* 2.0.
*/

type EmptyObject = Record<string | number, never>;

export enum FlowTargetSourceDest {
destination = 'destination',
source = 'source',
}

export type ExpandedEventType =
| {
panelView?: 'eventDetail';
params?: {
eventId: string;
indexName: string;
refetch?: () => void;
};
}
| EmptyObject;

export type ExpandedDetailType = ExpandedEventType;

export enum TimelineTabs {
query = 'query',
graph = 'graph',
Expand All @@ -33,9 +18,3 @@ export enum TimelineTabs {
eql = 'eql',
session = 'session',
}

export type ExpandedDetailTimeline = {
[tab in TimelineTabs]?: ExpandedDetailType;
};

export type ExpandedDetail = Partial<Record<string, ExpandedDetailType>>;
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const mockGlobalState = {
defaultColumns: defaultHeaders,
dataViewId: 'security-solution-default',
deletedEventIds: [],
expandedDetail: {},
filters: [],
indexNames: ['.alerts-security.alerts-default'],
isSelectAllChecked: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import actionCreatorFactory from 'typescript-fsa';
import { TimelineNonEcsData } from '@kbn/timelines-plugin/common';
import type { ExpandedDetailType } from '../../common/types/detail_panel';
import type {
ColumnHeaderOptions,
SessionViewConfig,
Expand Down Expand Up @@ -43,13 +42,6 @@ export const updateColumnWidth = actionCreator<{
width: number;
}>('UPDATE_COLUMN_WIDTH');

export type TableToggleDetailPanel = ExpandedDetailType & {
tabType?: string;
id: string;
};

export const toggleDetailPanel = actionCreator<TableToggleDetailPanel>('TOGGLE_DETAIL_PANEL');

export const removeColumn = actionCreator<{
id: string;
columnId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export const tableDefaults: SubsetDataTableModel = {
defaultColumns: defaultHeaders,
dataViewId: null,
deletedEventIds: [],
expandedDetail: {},
filters: [],
indexNames: [],
isSelectAllChecked: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ import { omit, union } from 'lodash/fp';

import { isEmpty } from 'lodash';
import type { EuiDataGridColumn } from '@elastic/eui';
import type { ExpandedDetail, ExpandedDetailType } from '../../common/types/detail_panel';
import type { ColumnHeaderOptions, SessionViewConfig, SortColumnTable } from '../../common/types';
import type { TableToggleDetailPanel } from './actions';
import type { DataTablePersistInput, TableById } from './types';
import type { DataTableModelSettings } from './model';

import { getDataTableManageDefaults, tableDefaults } from './defaults';
import { DEFAULT_TABLE_COLUMN_MIN_WIDTH } from '../../components/data_table/constants';

export const isNotNull = <T>(value: T | null): value is T => value !== null;
export type Maybe<T> = T | null;

/** The minimum width of a resized column */
Expand Down Expand Up @@ -438,22 +435,6 @@ export const setSelectedTableEvents = ({
};
};

export const updateTableDetailsPanel = (action: TableToggleDetailPanel): ExpandedDetail => {
const { tabType, id, ...expandedDetails } = action;

const panelViewOptions = new Set(['eventDetail', 'hostDetail', 'networkDetail', 'userDetail']);
const expandedTabType = tabType ?? 'query';
const newExpandDetails = {
params: expandedDetails.params ? { ...expandedDetails.params } : {},
panelView: expandedDetails.panelView,
} as ExpandedDetailType;
return {
[expandedTabType]: panelViewOptions.has(expandedDetails.panelView ?? '')
? newExpandDetails
: {},
};
};

export const updateTableGraphEventId = ({
id,
graphEventId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import type { EuiDataGridColumn } from '@elastic/eui';
import type { Filter } from '@kbn/es-query';
import { TimelineNonEcsData } from '@kbn/timelines-plugin/common';
import { ExpandedDetail } from '../../common/types/detail_panel';
import type {
ColumnHeaderOptions,
SessionViewConfig,
Expand Down Expand Up @@ -44,8 +43,6 @@ export interface DataTableModel extends DataTableModelSettings {
dataViewId: string | null; // null if legacy pre-8.0 data table
/** Events to not be rendered **/
deletedEventIds: string[];
/** This holds the view information for the flyout when viewing data in a consuming view (i.e. hosts page) or the side panel in the primary data view */
expandedDetail: ExpandedDetail;
filters?: Filter[];
/** When non-empty, display a graph view for this event */
graphEventId?: string;
Expand Down Expand Up @@ -82,7 +79,6 @@ export type SubsetDataTableModel = Readonly<
| 'defaultColumns'
| 'dataViewId'
| 'deletedEventIds'
| 'expandedDetail'
| 'filters'
| 'indexNames'
| 'isLoading'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
setEventsLoading,
setDataTableSelectAll,
setSelected,
toggleDetailPanel,
updateColumnOrder,
updateColumns,
updateColumnWidth,
Expand Down Expand Up @@ -52,7 +51,6 @@ import {
updateTablePerPageOptions,
updateTableSort,
upsertTableColumn,
updateTableDetailsPanel,
updateTableGraphEventId,
updateTableSessionViewConfig,
} from './helpers';
Expand Down Expand Up @@ -87,21 +85,6 @@ export const dataTableReducer = reducerWithInitialState(initialDataTableState)
dataTableSettingsProps,
}),
}))
.case(toggleDetailPanel, (state, action) => {
return {
...state,
tableById: {
...state.tableById,
[action.id]: {
...state.tableById[action.id],
expandedDetail: {
...state.tableById[action.id]?.expandedDetail,
...updateTableDetailsPanel(action),
},
},
},
};
})
.case(applyDeltaToColumnWidth, (state, { id, columnId, delta }) => ({
...state,
tableById: applyDeltaToTableColumnWidth({
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/cases/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ Arguments:
| timelineIntegration?.editor_plugins.uiPlugin? | `EuiMarkdownEditorUiPlugin` |
| timelineIntegration?.hooks.useInsertTimeline | `(value: string, onChange: (newValue: string) => void): UseInsertTimelineReturn` |
| timelineIntegration?.ui?.renderInvestigateInTimelineActionComponent? | `(alertIds: string[]) => JSX.Element;` space to render `InvestigateInTimelineActionComponent` |
| timelineIntegration?.ui?renderTimelineDetailsPanel? | `() => JSX.Element;` space to render `TimelineDetailsPanel` |
#### `getCases`
UI component:
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/cases/public/components/__mock__/timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ export const timelineIntegrationMock = {
hooks: {
useInsertTimeline: jest.fn(),
},
ui: {
renderTimelineDetailsPanel: () => mockTimelineComponent('timeline-details-panel'),
},
};

export const useTimelineContextMock = useTimelineContext as jest.Mock;
Loading

0 comments on commit 2582b59

Please sign in to comment.