Skip to content

Commit

Permalink
Merge branch 'migrate-mobile-api-tests' of github.com:kpatticha/kiban…
Browse files Browse the repository at this point in the history
…a into migrate-mobile-api-tests
  • Loading branch information
kpatticha committed Nov 8, 2024
2 parents 06403c2 + 2633eab commit 3878972
Show file tree
Hide file tree
Showing 36 changed files with 499 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ const DEFAULTS_SETTINGS = {
root: {
level: 'off',
},
loggers: [
{
name: 'root',
level: 'error',
appenders: ['console'],
},
{
name: 'elasticsearch.deprecation',
level: 'all',
appenders: ['deprecation'],
},
],
appenders: {
deprecation: { type: 'console', layout: { type: 'json' } },
console: { type: 'console', layout: { type: 'pattern' } },
},
},
plugins: {},
migrations: { skip: false },
Expand Down
84 changes: 84 additions & 0 deletions packages/kbn-esql-ast/src/parser/__tests__/function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import { parse } from '..';
import { EsqlQuery } from '../../query';
import { Walker } from '../../walker';

describe('function AST nodes', () => {
Expand Down Expand Up @@ -323,3 +324,86 @@ describe('function AST nodes', () => {
});
});
});

describe('location', () => {
const getFunctionTexts = (src: string) => {
const query = EsqlQuery.fromSrc(src);
const functions = Walker.matchAll(query.ast, { type: 'function' });
const texts: string[] = functions.map((fn) => {
return [...src].slice(fn.location.min, fn.location.max + 1).join('');
});

return texts;
};

it('correctly cuts out function source texts', () => {
const texts = getFunctionTexts(
'FROM index | LIMIT 1 | STATS agg() | LIMIT 2 | STATS max(a, b, c), max2(d.e)'
);

expect(texts).toEqual(['agg()', 'max(a, b, c)', 'max2(d.e)']);
});

it('functions in binary expressions', () => {
const texts = getFunctionTexts('FROM index | STATS foo = agg(f1) + agg(f2), a.b = agg(f3)');

expect(texts).toEqual([
'foo = agg(f1) + agg(f2)',
'agg(f1) + agg(f2)',
'agg(f1)',
'agg(f2)',
'a.b = agg(f3)',
'agg(f3)',
]);
});

it('with the simplest comment after function name identifier', () => {
const texts1 = getFunctionTexts('FROM index | STATS agg/* */(1)');
expect(texts1).toEqual(['agg/* */(1)']);

const texts2 = getFunctionTexts('FROM index | STATS agg/* A */(a)');
expect(texts2).toEqual(['agg/* A */(a)']);

const texts3 = getFunctionTexts('FROM index | STATS agg /* A */ (*)');
expect(texts3).toEqual(['agg /* A */ (*)']);
});

it('with the simplest emoji comment after function name identifier', () => {
const texts = getFunctionTexts('FROM index | STATS agg/* 😎 */(*)');
expect(texts).toEqual(['agg/* 😎 */(*)']);
});

it('with the simplest emoji comment after function name identifier, followed by another arg', () => {
const texts = getFunctionTexts('FROM index | STATS agg/* 😎 */(*), abc');
expect(texts).toEqual(['agg/* 😎 */(*)']);
});

it('simple emoji comment twice', () => {
const texts = getFunctionTexts('FROM index | STATS agg/* 😎 */(*), max/* 😎 */(*)');
expect(texts).toEqual(['agg/* 😎 */(*)', 'max/* 😎 */(*)']);
});

it('with comment and emoji after function name identifier', () => {
const texts = getFunctionTexts('FROM index | STATS agg /* haha 😅 */ (*)');

expect(texts).toEqual(['agg /* haha 😅 */ (*)']);
});

it('with comment inside argument list', () => {
const texts = getFunctionTexts('FROM index | STATS agg ( /* haha 😅 */ )');

expect(texts).toEqual(['agg ( /* haha 😅 */ )']);
});

it('with emoji and comment in argument lists', () => {
const texts = getFunctionTexts(
'FROM index | STATS agg( /* haha 😅 */ max(foo), bar, baz), test( /* asdf */ * /* asdf */)'
);

expect(texts).toEqual([
'agg( /* haha 😅 */ max(foo), bar, baz)',
'max(foo)',
'test( /* asdf */ * /* asdf */)',
]);
});
});
13 changes: 6 additions & 7 deletions packages/kbn-esql-ast/src/parser/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@ export const formatIdentifierParts = (parts: string[]): string =>
parts.map(formatIdentifier).join('.');

export const getPosition = (
token: Pick<Token, 'start' | 'stop'> | null,
lastToken?: Pick<Token, 'stop'> | undefined
start: Pick<Token, 'start' | 'stop'> | null,
stop?: Pick<Token, 'stop'> | undefined
) => {
if (!token || token.start < 0) {
if (!start || start.start < 0) {
return { min: 0, max: 0 };
}
const endFirstToken = token.stop > -1 ? Math.max(token.stop + 1, token.start) : undefined;
const endLastToken = lastToken?.stop;
const endFirstToken = start.stop > -1 ? Math.max(start.stop + 1, start.start) : undefined;
return {
min: token.start,
max: endLastToken ?? endFirstToken ?? Infinity,
min: start.start,
max: stop?.stop ?? endFirstToken ?? Infinity,
};
};

Expand Down
41 changes: 32 additions & 9 deletions packages/kbn-kibana-manifest-schema/src/kibana_json_v2_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,10 @@ export const MANIFEST_V2: JSONSchema = {
`,
},
group: {
enum: ['common', 'platform', 'observability', 'security', 'search'],
enum: ['platform', 'observability', 'security', 'search'],
description: desc`
Specifies the group to which this module pertains.
`,
default: 'common',
},
visibility: {
enum: ['private', 'shared'],
description: desc`
Specifies the visibility of this module, i.e. whether it can be accessed by everybody or only modules in the same group
`,
default: 'shared',
},
devOnly: {
type: 'boolean',
Expand Down Expand Up @@ -112,6 +104,37 @@ export const MANIFEST_V2: JSONSchema = {
type: 'string',
},
},
allOf: [
{
if: {
properties: { group: { const: 'platform' } },
},
then: {
properties: {
visibility: {
enum: ['private', 'shared'],
description: desc`
Specifies the visibility of this module, i.e. whether it can be accessed by everybody or only modules in the same group
`,
default: 'shared',
},
},
required: ['visibility'],
},
else: {
properties: {
visibility: {
const: 'private',
description: desc`
Specifies the visibility of this module, i.e. whether it can be accessed by everybody or only modules in the same group
`,
default: 'private',
},
},
required: ['visibility'],
},
},
],
oneOf: [
{
type: 'object',
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pageLoadAssetSize:
actions: 20000
advancedSettings: 27596
aiAssistantManagementSelection: 19146
aiops: 10000
aiops: 16000
alerting: 106936
apm: 64385
banners: 17946
Expand Down
27 changes: 20 additions & 7 deletions src/core/server/integration_tests/http/logging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,28 @@ describe('request logging', () => {

describe('http server response logging', () => {
describe('configuration', () => {
let root: ReturnType<typeof createRoot>;

afterEach(async () => {
await root?.shutdown();
});
it('does not log with a default config', async () => {
const root = createRoot({
root = createRoot({
plugins: { initialize: false },
elasticsearch: { skipStartupConnectionCheck: true },
server: { restrictInternalApis: false },
logging: {
appenders: {
'test-console': { type: 'console', layout: { type: 'json' } },
},
loggers: [
{
name: 'http.server.response',
appenders: ['test-console'],
level: 'off',
},
],
},
});
await root.preboot();
const { http } = await root.setup();
Expand All @@ -47,12 +64,10 @@ describe('request logging', () => {

await request.get(root, '/ping').expect(200, 'pong');
expect(mockConsoleLog).not.toHaveBeenCalled();

await root.shutdown();
});

it('logs at the correct level and with the correct context', async () => {
const root = createRoot({
root = createRoot({
logging: {
appenders: {
'test-console': {
Expand Down Expand Up @@ -93,8 +108,6 @@ describe('request logging', () => {
const [level, logger] = mockConsoleLog.mock.calls[0][0].split('|');
expect(level).toBe('DEBUG');
expect(logger).toBe('http.server.response');

await root.shutdown();
});
});

Expand Down Expand Up @@ -131,7 +144,7 @@ describe('request logging', () => {
});

afterEach(async () => {
await root.shutdown();
await root?.shutdown();
});

it('handles a GET request', async () => {
Expand Down
7 changes: 7 additions & 0 deletions src/core/server/integration_tests/node/logging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ function createRootWithRoles(roles: string[]) {
roles,
},
logging: {
loggers: [
{
name: 'root',
appenders: ['test-console'],
level: 'info',
},
],
appenders: {
'test-console': {
type: 'console',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { createAction } from '@kbn/ui-actions-plugin/public';
import type { CoreStart } from '@kbn/core/public';
import { ACTION_CATEGORIZE_FIELD, type CategorizeFieldContext } from '@kbn/ml-ui-actions';
import type { AiopsPluginStartDeps } from '../../types';
import { showCategorizeFlyout } from './show_flyout';

export const createCategorizeFieldAction = (coreStart: CoreStart, plugins: AiopsPluginStartDeps) =>
createAction<CategorizeFieldContext>({
Expand All @@ -25,6 +24,7 @@ export const createCategorizeFieldAction = (coreStart: CoreStart, plugins: Aiops
},
execute: async (context: CategorizeFieldContext) => {
const { field, dataView, originatingApp, additionalFilter } = context;
const { showCategorizeFlyout } = await import('./show_flyout');
showCategorizeFlyout(field, dataView, coreStart, plugins, originatingApp, additionalFilter);
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

export type { LogCategorizationAppStateProps } from './log_categorization_app_state';
import { LogCategorizationAppState } from './log_categorization_app_state';
export { createCategorizeFieldAction } from './categorize_field_actions';

// required for dynamic import using React.lazy()
// eslint-disable-next-line import/no-default-export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function showCategorizeFlyout(
): Promise<void> {
const { overlays, application, i18n } = coreStart;

return new Promise(async (resolve, reject) => {
return new Promise((resolve, reject) => {
try {
const onFlyoutClose = () => {
flyoutSession.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ import type { DataView } from '@kbn/data-views-plugin/common';
import { DATA_VIEW_SAVED_OBJECT_TYPE } from '@kbn/data-views-plugin/common';
import type { ReactEmbeddableFactory } from '@kbn/embeddable-plugin/public';
import { i18n } from '@kbn/i18n';
import {
apiHasExecutionContext,
fetch$,
initializeTimeRange,
initializeTitles,
useBatchedPublishingSubjects,
} from '@kbn/presentation-publishing';

import fastIsEqual from 'fast-deep-equal';
import { cloneDeep } from 'lodash';
Expand Down Expand Up @@ -61,6 +54,14 @@ export const getChangePointChartEmbeddableFactory = (
return serializedState;
},
buildEmbeddable: async (state, buildApi, uuid, parentApi) => {
const {
apiHasExecutionContext,
fetch$,
initializeTimeRange,
initializeTitles,
useBatchedPublishingSubjects,
} = await import('@kbn/presentation-publishing');

const [coreStart, pluginStart] = await getStartServices();

const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ import type { DataView } from '@kbn/data-views-plugin/common';
import { DATA_VIEW_SAVED_OBJECT_TYPE } from '@kbn/data-views-plugin/common';
import type { ReactEmbeddableFactory } from '@kbn/embeddable-plugin/public';
import { i18n } from '@kbn/i18n';
import {
apiHasExecutionContext,
fetch$,
initializeTimeRange,
initializeTitles,
useBatchedPublishingSubjects,
} from '@kbn/presentation-publishing';
import fastIsEqual from 'fast-deep-equal';
import { cloneDeep } from 'lodash';
import React, { useMemo } from 'react';
Expand Down Expand Up @@ -58,6 +51,14 @@ export const getPatternAnalysisEmbeddableFactory = (
return serializedState;
},
buildEmbeddable: async (state, buildApi, uuid, parentApi) => {
const {
apiHasExecutionContext,
fetch$,
initializeTimeRange,
initializeTitles,
useBatchedPublishingSubjects,
} = await import('@kbn/presentation-publishing');

const [coreStart, pluginStart] = await getStartServices();

const {
Expand Down
Loading

0 comments on commit 3878972

Please sign in to comment.