Skip to content

Commit

Permalink
Merge branch 'main' into investigate-ui-2
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelemme authored Jul 22, 2024
2 parents dfc8dfa + 0c5d7b9 commit 485c695
Show file tree
Hide file tree
Showing 304 changed files with 4,666 additions and 2,140 deletions.
1 change: 1 addition & 0 deletions .buildkite/ftr_oblt_serverless_configs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
disabled:
# Base config files, only necessary to inform config finding script
- x-pack/test_serverless/functional/test_suites/observability/cypress/oblt_config.base.ts

# Cypress configs, for now these are still run manually
- x-pack/test_serverless/functional/test_suites/observability/cypress/config_headless.ts
Expand Down
7 changes: 7 additions & 0 deletions .buildkite/ftr_oblt_stateful_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ disabled:
- x-pack/plugins/observability_solution/profiling/e2e/ftr_config_runner.ts
- x-pack/plugins/observability_solution/profiling/e2e/ftr_config.ts

#FTR configs
- x-pack/plugins/observability_solution/uptime/e2e/config.ts

# Elastic Synthetics configs
- x-pack/plugins/observability_solution/uptime/e2e/uptime/synthetics_run.ts
- x-pack/plugins/observability_solution/synthetics/e2e/config.ts
Expand All @@ -27,6 +30,10 @@ 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/apm_api_integration/basic/config.ts
- x-pack/test/apm_api_integration/cloud/config.ts
- x-pack/test/apm_api_integration/rules/config.ts
- x-pack/test/apm_api_integration/trial/config.ts
- x-pack/test/dataset_quality_api_integration/basic/config.ts
- x-pack/test/functional/apps/observability_logs_explorer/config.ts
- x-pack/test/functional/apps/dataset_quality/config.ts
Expand Down
2 changes: 2 additions & 0 deletions .buildkite/ftr_platform_stateful_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ disabled:
- x-pack/test/functional_with_es_ssl/config.base.ts
- x-pack/test/api_integration/config.ts
- x-pack/test/fleet_api_integration/config.base.ts
- x-pack/test/functional_basic/apps/ml/config.base.ts
- x-pack/test/functional_basic/apps/transform/config.base.ts

# QA suites that are run out-of-band
- x-pack/test/stack_functional_integration/configs/config.stack_functional_integration_base.js
Expand Down
2 changes: 2 additions & 0 deletions .buildkite/ftr_security_serverless_configs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
disabled:
# Base config files, only necessary to inform config finding script
- x-pack/test_serverless/functional/test_suites/security/cypress/security_config.base.ts
- x-pack/test_serverless/functional/test_suites/security/cypress/cypress.config.ts
- x-pack/test/security_solution_api_integration/config/serverless/config.base.ts
- x-pack/test/security_solution_api_integration/config/serverless/config.base.essentials.ts
- x-pack/test/security_solution_api_integration/config/serverless/config.base.edr_workflows.ts
Expand Down
1 change: 1 addition & 0 deletions .buildkite/ftr_security_stateful_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ disabled:
- x-pack/test/security_solution_api_integration/config/ess/config.base.edr_workflows.trial.ts
- x-pack/test/security_solution_api_integration/config/ess/config.base.edr_workflows.ts
- x-pack/test/security_solution_api_integration/config/ess/config.base.basic.ts
- x-pack/test/security_solution_api_integration/config/ess/config.base.trial.ts
- x-pack/test/security_solution_endpoint/configs/config.base.ts
- x-pack/test/security_solution_endpoint/config.base.ts
- x-pack/test/security_solution_endpoint_api_int/config.base.ts
Expand Down
2 changes: 1 addition & 1 deletion .buildkite/pipelines/pull_request/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ steps:
preemptible: true
key: build
if: "build.env('KIBANA_BUILD_ID') == null || build.env('KIBANA_BUILD_ID') == ''"
timeout_in_minutes: 60
timeout_in_minutes: 90
retry:
automatic:
- exit_status: '-1'
Expand Down
15 changes: 5 additions & 10 deletions .buildkite/scripts/pipelines/pull_request/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
* Side Public License, v 1.
*/

import { execSync } from 'child_process';
import fs from 'fs';
import prConfigs from '../../../pull_requests.json';
import { areChangesSkippable, doAnyChangesMatch, getAgentImageConfig } from '#pipeline-utils';

const prConfig = prConfigs.jobs.find((job) => job.pipelineSlug === 'kibana-pull-request');
const emptyStep = `steps: []`;

if (!prConfig) {
console.error(`'kibana-pull-request' pipeline not found in .buildkite/pull_requests.json`);
Expand All @@ -28,21 +28,16 @@ const getPipeline = (filename: string, removeSteps = true) => {
};

(async () => {
const pipeline: string[] = [];

try {
const skippable = await areChangesSkippable(SKIPPABLE_PR_MATCHERS, REQUIRED_PATHS);

if (skippable) {
console.log('All changes in PR are skippable. Skipping CI.');

// Since we skip everything, including post-build, we need to at least make sure the commit status gets set
execSync('BUILD_SUCCESSFUL=true .buildkite/scripts/lifecycle/commit_status_complete.sh', {
stdio: 'inherit',
});
process.exit(0);
console.log(emptyStep);
return;
}

const pipeline = [];

pipeline.push(getAgentImageConfig({ returnYaml: true }));
pipeline.push(getPipeline('.buildkite/pipelines/pull_request/base.yml', false));

Expand Down
2 changes: 1 addition & 1 deletion docs/management/connectors/action-types/gemini.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Body:: A stringified JSON payload sent to the {gemini} invoke model API. Fo
body: JSON.stringify({
contents: [{
role: user,
parts: [{ text: 'Write the first line of a story about a magic backpack.' }]
parts: [{ text: 'Hello world!' }]
}],
generation_config: {
temperature: 0,
Expand Down
6 changes: 4 additions & 2 deletions oas_docs/bundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@
"description": "Kibana's operational status. A minimal response is sent for unauthorized users."
}
}
}
},
"description": "Overall status is OK and Kibana should be functioning normally."
},
"503": {
"content": {
Expand All @@ -412,7 +413,8 @@
"description": "Kibana's operational status. A minimal response is sent for unauthorized users."
}
}
}
},
"description": "Kibana or some of it's essential services are unavailable. Kibana may be degraded or unavailable."
}
},
"summary": "Get Kibana's current status",
Expand Down
6 changes: 4 additions & 2 deletions oas_docs/bundle.serverless.json
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@
"description": "Kibana's operational status. A minimal response is sent for unauthorized users."
}
}
}
},
"description": "Overall status is OK and Kibana should be functioning normally."
},
"503": {
"content": {
Expand All @@ -412,7 +413,8 @@
"description": "Kibana's operational status. A minimal response is sent for unauthorized users."
}
}
}
},
"description": "Kibana or some of it's essential services are unavailable. Kibana may be degraded or unavailable."
}
},
"summary": "Get Kibana's current status",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
* Side Public License, v 1.
*/

import { getApmConfigMock } from './http_resources_service.test.mocks';

import type { RouteConfig } from '@kbn/core-http-server';

import { mockCoreContext } from '@kbn/core-base-server-mocks';
import { httpServiceMock, httpServerMock } from '@kbn/core-http-server-mocks';
import { renderingServiceMock } from '@kbn/core-rendering-server-mocks';
Expand All @@ -29,11 +26,6 @@ describe('HttpResources service', () => {
let router: ReturnType<typeof httpServiceMock.createRouter>;
const kibanaRequest = httpServerMock.createKibanaRequest();
const context = createCoreRequestHandlerContextMock();
const apmConfig = { mockApmConfig: true };

beforeEach(() => {
getApmConfigMock.mockReturnValue(apmConfig);
});

describe('#createRegistrar', () => {
beforeEach(() => {
Expand Down Expand Up @@ -93,9 +85,6 @@ describe('HttpResources service', () => {
},
{
isAnonymousPage: false,
vars: {
apmConfig,
},
}
);
});
Expand All @@ -118,9 +107,6 @@ describe('HttpResources service', () => {
},
{
isAnonymousPage: true,
vars: {
apmConfig,
},
}
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import type {

import type { InternalHttpResourcesSetup } from './types';

import { getApmConfig } from './get_apm_config';

/**
* @internal
*/
Expand Down Expand Up @@ -112,13 +110,9 @@ export class HttpResourcesService implements CoreService<InternalHttpResourcesSe
): HttpResourcesServiceToolkit {
return {
async renderCoreApp(options: HttpResourcesRenderOptions = {}) {
const apmConfig = getApmConfig(request.url.pathname);
const { uiSettings } = await context.core;
const body = await deps.rendering.render(request, uiSettings, {
isAnonymousPage: false,
vars: {
apmConfig,
},
includeExposedConfigKeys: options.includeExposedConfigKeys,
});

Expand All @@ -128,13 +122,9 @@ export class HttpResourcesService implements CoreService<InternalHttpResourcesSe
});
},
async renderAnonymousCoreApp(options: HttpResourcesRenderOptions = {}) {
const apmConfig = getApmConfig(request.url.pathname);
const { uiSettings } = await context.core;
const body = await deps.rendering.render(request, uiSettings, {
isAnonymousPage: true,
vars: {
apmConfig,
},
includeExposedConfigKeys: options.includeExposedConfigKeys,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"**/*.ts",
],
"kbn_references": [
"@kbn/apm-config-loader",
"@kbn/logging",
"@kbn/core-http-server",
"@kbn/core-http-resources-server",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ describe('Router', () => {
isConfigSchema(
(
validationSchemas as () => RouteValidatorRequestAndResponses<unknown, unknown, unknown>
)().response![200].body()
)().response![200].body!()
)
).toBe(true);
expect(
isConfigSchema(
(
validationSchemas as () => RouteValidatorRequestAndResponses<unknown, unknown, unknown>
)().response![404].body()
)().response![404].body!()
)
).toBe(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ describe('prepareResponseValidation', () => {
404: {
body: jest.fn(() => schema.string()),
},
500: {
description: 'just a description',
body: undefined,
},
unsafe: {
body: true,
},
Expand All @@ -32,13 +36,15 @@ describe('prepareResponseValidation', () => {
expect(prepared).toEqual({
200: { body: expect.any(Function) },
404: { body: expect.any(Function) },
500: { description: 'just a description', body: undefined },
unsafe: { body: true },
});

[1, 2, 3].forEach(() => prepared[200].body());
[1, 2, 3].forEach(() => prepared[404].body());
[1, 2, 3].forEach(() => prepared[200].body!());
[1, 2, 3].forEach(() => prepared[404].body!());

expect(validation.response![200].body).toHaveBeenCalledTimes(1);
expect(validation.response![404].body).toHaveBeenCalledTimes(1);
expect(validation.response![500].body).toBeUndefined();
});
});
13 changes: 5 additions & 8 deletions packages/core/http/core-http-router-server-internal/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,22 @@
import { once } from 'lodash';
import {
isFullValidatorContainer,
type RouteValidatorFullConfigResponse,
type RouteConfig,
type RouteMethod,
type RouteValidator,
} from '@kbn/core-http-server';
import type { ObjectType, Type } from '@kbn/config-schema';
import type { ZodEsque } from '@kbn/zod';

function isStatusCode(key: string) {
return !isNaN(parseInt(key, 10));
}

interface ResponseValidation {
[statusCode: number]: { body: () => ObjectType | Type<unknown> | ZodEsque<unknown> };
}

export function prepareResponseValidation(validation: ResponseValidation): ResponseValidation {
export function prepareResponseValidation(
validation: RouteValidatorFullConfigResponse
): RouteValidatorFullConfigResponse {
const responses = Object.entries(validation).map(([key, value]) => {
if (isStatusCode(key)) {
return [key, { body: once(value.body) }];
return [key, { ...value, ...(value.body ? { body: once(value.body) } : {}) }];
}
return [key, value];
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ describe('Versioned route', () => {
] = route.handlers;

const res200 = (validate as () => VersionedRouteValidation<unknown, unknown, unknown>)()
.response![200].body;
.response![200].body!;

expect(isConfigSchema(unwrapVersionedResponseBodyValidation(res200))).toBe(true);

const res404 = (validate as () => VersionedRouteValidation<unknown, unknown, unknown>)()
.response![404].body;
.response![404].body!;

expect(isConfigSchema(unwrapVersionedResponseBodyValidation(res404))).toBe(true);

Expand Down Expand Up @@ -301,6 +301,33 @@ describe('Versioned route', () => {
expect(validateOutputFn).toHaveBeenCalledTimes(1);
});

it('handles "undefined" response schemas', async () => {
let handler: RequestHandler;

(router.post as jest.Mock).mockImplementation((opts: unknown, fn) => (handler = fn));
const versionedRouter = CoreVersionedRouter.from({ router, isDev: true });
versionedRouter.post({ path: '/test/{id}', access: 'internal' }).addVersion(
{
version: '1',
validate: { response: { 500: { description: 'jest description', body: undefined } } },
},
async (ctx, req, res) => res.custom({ statusCode: 500 })
);

await expect(
handler!(
{} as any,
createRequest({
version: '1',
body: { foo: 1 },
params: { foo: 1 },
query: { foo: 1 },
}),
responseFactory
)
).resolves.not.toThrow();
});

it('runs custom response validations', async () => {
let handler: RequestHandler;
const { fooValidation, validateBodyFn, validateOutputFn, validateParamsFn, validateQueryFn } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ export class CoreVersionedRoute implements VersionedRoute {

const response = await handler.fn(ctx, req, res);

if (this.router.isDev && validation?.response?.[response.status]) {
if (this.router.isDev && validation?.response?.[response.status]?.body) {
const { [response.status]: responseValidation, unsafe } = validation.response;
try {
validate(
{ body: response.payload },
{
body: unwrapVersionedResponseBodyValidation(responseValidation.body),
body: unwrapVersionedResponseBodyValidation(responseValidation.body!),
unsafe: { body: unsafe?.body },
}
);
Expand Down
Loading

0 comments on commit 485c695

Please sign in to comment.