Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into query-diff-algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
dplumlee committed Aug 8, 2024
2 parents bf6e356 + 6a8b950 commit e90c66e
Show file tree
Hide file tree
Showing 25 changed files with 506 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ spec:
description: Run Kibana FIPS smoke tests
spec:
env:
SLACK_NOTIFICATIONS_CHANNEL: "#kibana-fips-ftr-errors"
ELASTIC_SLACK_NOTIFICATIONS_ENABLED: "true"
SLACK_NOTIFICATIONS_CHANNEL: '#kibana-operations-alerts'
ELASTIC_SLACK_NOTIFICATIONS_ENABLED: 'true'
repository: elastic/kibana
branch_configuration: main
default_branch: main
pipeline_file: ".buildkite/pipelines/fips.yml"
pipeline_file: '.buildkite/pipelines/fips.yml'
provider_settings:
trigger_mode: none
schedules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('autocomplete', () => {
},
});

const sourceCommands = ['row', 'from', 'show'];
const sourceCommands = ['row', 'from', 'show', 'metrics'];

describe('New command', () => {
testSuggestions(
Expand Down Expand Up @@ -1278,7 +1278,7 @@ describe('autocomplete', () => {
// Source command
testSuggestions(
'F',
['FROM $0', 'ROW $0', 'SHOW $0'].map(attachTriggerCommand).map(attachAsSnippet),
['FROM $0', 'ROW $0', 'SHOW $0', 'METRICS $0'].map(attachTriggerCommand).map(attachAsSnippet),
undefined,
1
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function isComma(char: string) {
}

export function isSourceCommand({ label }: { label: string }) {
return ['FROM', 'ROW', 'SHOW'].includes(label);
return ['FROM', 'ROW', 'SHOW', 'METRICS'].includes(label);
}

let fnLookups: Map<string, FunctionDefinition> | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ describe('Version Compatibility', () => {
await expect(startServers({ customKibanaVersion: previousMinor() })).resolves.toBeUndefined();
});

// FLAKY: https://github.com/elastic/kibana/issues/171289
it.skip('should flag the incompatibility on version mismatch (ES is previous minor)', async () => {
it('should flag the incompatibility on version mismatch (ES is previous minor)', async () => {
const found$ = new Subject<void>();
consoleSpy.mockImplementation((str) => {
if (str.includes('is incompatible')) {
Expand Down
6 changes: 6 additions & 0 deletions test/functional/apps/discover/group1/_discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,14 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await kibanaServer.uiSettings.update({ 'dateFormat:tz': 'America/Phoenix' });
await PageObjects.common.navigateToApp('discover');
await PageObjects.header.awaitKibanaChrome();
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.discover.waitUntilSearchingHasFinished();
await PageObjects.timePicker.setDefaultAbsoluteRange();
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.discover.waitUntilSearchingHasFinished();
await queryBar.clearQuery();
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.discover.waitUntilSearchingHasFinished();

log.debug(
'check that the newest doc timestamp is now -7 hours from the UTC time in the first test'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const defineBulkActionCspBenchmarkRulesRoute = (router: CspRouter) =>
access: 'internal',
path: CSP_BENCHMARK_RULES_BULK_ACTION_ROUTE_PATH,
options: {
tags: ['access:cloud-security-posture-read'],
tags: ['access:cloud-security-posture-all'],
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as t from 'io-ts';
import { investigationResponseSchema } from './investigation';

const createInvestigationParamsSchema = t.type({
body: t.type({
id: t.string,
title: t.string,
parameters: t.type({
timeRange: t.type({ from: t.number, to: t.number }),
}),
}),
});

const createInvestigationResponseSchema = investigationResponseSchema;

type CreateInvestigationInput = t.OutputOf<typeof createInvestigationParamsSchema.props.body>; // Raw payload sent by the frontend
type CreateInvestigationParams = t.TypeOf<typeof createInvestigationParamsSchema.props.body>; // Parsed payload used by the backend
type CreateInvestigationResponse = t.OutputOf<typeof createInvestigationResponseSchema>; // Raw response sent to the frontend

export { createInvestigationParamsSchema, createInvestigationResponseSchema };
export type { CreateInvestigationInput, CreateInvestigationParams, CreateInvestigationResponse };
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as t from 'io-ts';
import { investigationResponseSchema } from './investigation';

const findInvestigationsParamsSchema = t.partial({
query: t.partial({
page: t.string,
perPage: t.string,
}),
});

const findInvestigationsResponseSchema = t.type({
page: t.number,
perPage: t.number,
total: t.number,
results: t.array(investigationResponseSchema),
});

type FindInvestigationsParams = t.TypeOf<typeof findInvestigationsParamsSchema.props.query>; // Parsed payload used by the backend
type FindInvestigationsResponse = t.OutputOf<typeof findInvestigationsResponseSchema>; // Raw response sent to the frontend

export { findInvestigationsParamsSchema, findInvestigationsResponseSchema };
export type { FindInvestigationsParams, FindInvestigationsResponse };
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as t from 'io-ts';
import { investigationResponseSchema } from './investigation';

const getInvestigationParamsSchema = t.type({
path: t.type({
id: t.string,
}),
});

const getInvestigationResponseSchema = investigationResponseSchema;

type GetInvestigationParams = t.TypeOf<typeof getInvestigationParamsSchema.props.path>; // Parsed payload used by the backend
type GetInvestigationResponse = t.OutputOf<typeof getInvestigationResponseSchema>; // Raw response sent to the frontend

export { getInvestigationParamsSchema, getInvestigationResponseSchema };
export type { GetInvestigationParams, GetInvestigationResponse };
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as t from 'io-ts';

const investigationResponseSchema = t.type({
id: t.string,
title: t.string,
createdAt: t.number,
createdBy: t.string,
parameters: t.type({
timeRange: t.type({ from: t.number, to: t.number }),
}),
});

type InvestigationResponse = t.OutputOf<typeof investigationResponseSchema>;

export { investigationResponseSchema };
export type { InvestigationResponse };
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import * as t from 'io-ts';

export const investigationSchema = t.type({
id: t.string,
title: t.string,
createdAt: t.number,
createdBy: t.string,
parameters: t.type({
timeRange: t.type({ from: t.number, to: t.number }),
}),
});

export type Investigation = t.TypeOf<typeof investigationSchema>;
export type StoredInvestigation = t.OutputOf<typeof investigationSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export interface Paginated<T> {
total: number;
page: number;
perPage: number;
results: T[];
}

export interface Pagination {
page: number;
perPage: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import type {
InvestigateAppSetupDependencies,
InvestigateAppStartDependencies,
} from './types';
import { investigation } from './saved_objects/investigation';
import { InvestigateAppConfig } from './config';

export class InvestigateAppPlugin
implements
Expand All @@ -28,9 +30,11 @@ export class InvestigateAppPlugin
>
{
logger: Logger;
config: InvestigateAppConfig;

constructor(context: PluginInitializerContext<ConfigSchema>) {
this.logger = context.logger.get();
this.config = context.config.get<InvestigateAppConfig>();
}
setup(
coreSetup: CoreSetup<InvestigateAppStartDependencies, InvestigateAppServerStart>,
Expand All @@ -47,13 +51,17 @@ export class InvestigateAppPlugin
};
}) as InvestigateAppRouteHandlerResources['plugins'];

registerServerRoutes({
core: coreSetup,
logger: this.logger,
dependencies: {
plugins: routeHandlerPlugins,
},
});
if (this.config.enabled === true) {
coreSetup.savedObjects.registerType(investigation);

registerServerRoutes({
core: coreSetup,
logger: this.logger,
dependencies: {
plugins: routeHandlerPlugins,
},
});
}

return {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,63 @@
* 2.0.
*/

import { findInvestigationsParamsSchema } from '../../common/schema/find';
import { createInvestigationParamsSchema } from '../../common/schema/create';
import { createInvestigation } from '../services/create_investigation';
import { investigationRepositoryFactory } from '../services/investigation_repository';
import { createInvestigateAppServerRoute } from './create_investigate_app_server_route';
import { findInvestigations } from '../services/find_investigations';
import { getInvestigationParamsSchema } from '../../common/schema/get';
import { getInvestigation } from '../services/get_investigation';

const createInvestigationRoute = createInvestigateAppServerRoute({
endpoint: 'POST /api/observability/investigations 2023-10-31',
options: {
tags: [],
},
params: createInvestigationParamsSchema,
handler: async (params) => {
const soClient = (await params.context.core).savedObjects.client;
const repository = investigationRepositoryFactory({ soClient, logger: params.logger });

return await createInvestigation(params.params.body, repository);
},
});

const findInvestigationsRoute = createInvestigateAppServerRoute({
endpoint: 'GET /api/observability/investigations 2023-10-31',
options: {
tags: [],
},
params: findInvestigationsParamsSchema,
handler: async (params) => {
const soClient = (await params.context.core).savedObjects.client;
const repository = investigationRepositoryFactory({ soClient, logger: params.logger });

return await findInvestigations(params.params?.query ?? {}, repository);
},
});

const getInvestigationRoute = createInvestigateAppServerRoute({
endpoint: 'GET /api/observability/investigations/{id} 2023-10-31',
options: {
tags: [],
},
params: getInvestigationParamsSchema,
handler: async (params) => {
const soClient = (await params.context.core).savedObjects.client;
const repository = investigationRepositoryFactory({ soClient, logger: params.logger });

return await getInvestigation(params.params.path, repository);
},
});

export function getGlobalInvestigateAppServerRouteRepository() {
return {};
return {
...createInvestigationRoute,
...findInvestigationsRoute,
...getInvestigationRoute,
};
}

export type InvestigateAppServerRouteRepository = ReturnType<
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { SavedObjectsType } from '@kbn/core-saved-objects-server';
import { SavedObject } from '@kbn/core/server';
import { StoredInvestigation } from '../models/investigation';

export const SO_INVESTIGATION_TYPE = 'investigation';

export const investigation: SavedObjectsType = {
name: SO_INVESTIGATION_TYPE,
hidden: false,
namespaceType: 'multiple-isolated',
switchToModelVersionAt: '8.10.0',
mappings: {
dynamic: false,
properties: {
id: { type: 'keyword' },
title: { type: 'text' },
},
},
management: {
displayName: 'Investigation',
importableAndExportable: false,
getTitle(savedObject: SavedObject<StoredInvestigation>) {
return `Investigation: [${savedObject.attributes.title}]`;
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { CreateInvestigationInput, CreateInvestigationResponse } from '../../common/schema/create';
import { InvestigationRepository } from './investigation_repository';

export async function createInvestigation(
params: CreateInvestigationInput,
repository: InvestigationRepository
): Promise<CreateInvestigationResponse> {
const investigation = { ...params, createdAt: Date.now(), createdBy: 'elastic' };
await repository.save(investigation);

return investigation;
}
Loading

0 comments on commit e90c66e

Please sign in to comment.