Skip to content

Commit

Permalink
Merge branch 'main' into 183220-add-ecs-groups-to-metric-threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
maryam-saeidi authored Jul 24, 2024
2 parents 35a7a89 + d8ef2c9 commit 97d73de
Show file tree
Hide file tree
Showing 253 changed files with 4,200 additions and 9,810 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.

7 changes: 7 additions & 0 deletions packages/kbn-search-api-panels/components/code_box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ export const CodeBox: React.FC<CodeBoxProps> = ({
<EuiContextMenuItem
key={language.id}
icon={`${assetBasePath}/${language.iconType}`}
aria-label={i18n.translate(
'searchApiPanels.welcomeBanner.codeBox.selectChangeAriaLabel',
{
defaultMessage: 'Change language to {languageName} for every instance on this page',
values: { languageName: language.name },
}
)}
onClick={() => {
if (setSelectedLanguage) {
setSelectedLanguage(language);
Expand Down
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
Loading

0 comments on commit 97d73de

Please sign in to comment.