Skip to content

Commit

Permalink
Merge branch 'main' into eui-upgrade-47.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Feb 17, 2022
2 parents 8172e57 + f792e5d commit cdf28f3
Show file tree
Hide file tree
Showing 39 changed files with 520 additions and 709 deletions.
4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@
/x-pack/plugins/triggers_actions_ui/ @elastic/response-ops
/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/ @elastic/response-ops
/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/ @elastic/response-ops
/docs/user/alerting/ @elastic/response-ops
/docs/management/connectors/ @elastic/response-ops
/docs/user/alerting/ @elastic/response-ops @elastic/mlr-docs
/docs/management/connectors/ @elastic/response-ops @elastic/mlr-docs
#CC# /x-pack/plugins/stack_alerts @elastic/response-ops
/x-pack/plugins/cases/ @elastic/response-ops
/x-pack/test/cases_api_integration/ @elastic/response-ops
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/label-qa-fixed-in.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ jobs:
}
}
prnumber: ${{ github.event.number }}
token: ${{ secrets.FLEET_TECH_KIBANA_USER_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.FLEET_TECH_KIBANA_USER_TOKEN }}
- uses: sergeysova/jq-action@v2
id: issues_to_label
with:
Expand Down Expand Up @@ -75,4 +76,5 @@ jobs:
}
issueid: ${{ matrix.issueNodeId }}
labelids: ${{ needs.fetch_issues_to_label.outputs.label_ids }}
token: ${{ secrets.FLEET_TECH_KIBANA_USER_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.FLEET_TECH_KIBANA_USER_TOKEN }}
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"**/handlebars/uglify-js": "^3.14.3",
"**/hoist-non-react-statics": "^3.3.2",
"**/html-minifier/uglify-js": "^3.14.3",
"**/isomorphic-fetch/node-fetch": "^2.6.1",
"**/isomorphic-fetch/node-fetch": "^2.6.7",
"**/istanbul-lib-coverage": "^3.2.0",
"**/json-schema": "^0.4.0",
"**/minimist": "^1.2.5",
Expand All @@ -93,7 +93,8 @@
"**/trim": "1.0.1",
"**/typescript": "4.5.3",
"**/underscore": "^1.13.1",
"globby/fast-glob": "3.2.7"
"globby/fast-glob": "3.2.7",
"puppeteer/node-fetch": "^2.6.7"
},
"dependencies": {
"@babel/runtime": "^7.17.2",
Expand Down Expand Up @@ -305,7 +306,7 @@
"monaco-editor": "^0.22.3",
"mustache": "^2.3.2",
"nock": "12.0.3",
"node-fetch": "^2.6.1",
"node-fetch": "^2.6.7",
"node-forge": "^1.2.1",
"nodemailer": "^6.6.2",
"normalize-path": "^3.0.0",
Expand Down Expand Up @@ -643,7 +644,7 @@
"@types/ncp": "^2.0.1",
"@types/nock": "^10.0.3",
"@types/node": "16.10.2",
"@types/node-fetch": "^2.5.7",
"@types/node-fetch": "^2.6.0",
"@types/node-forge": "^1.0.0",
"@types/nodemailer": "^6.4.0",
"@types/normalize-path": "^3.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,40 @@ describe('KibanaExecutionContext', () => {
expect(value).toBe('type:name:41;child-test-type:child-test-name:42');
});

it('returns an escaped string representation of provided execution contextStringified', () => {
it('returns an escaped string representation of provided execution context', () => {
const context: KibanaExecutionContext = {
id: 'Visualization☺漢字',
type: 'test☺type',
name: 'test漢name',
description: 'test字description',
};

const value = new ExecutionContextContainer(context).toString();
expect(value).toBe(
'test%E2%98%BAtype:test%E6%BC%A2name:Visualization%E2%98%BA%E6%BC%A2%E5%AD%97'
);
});

it('returns an escaped string representation of provided execution context parent', () => {
const parentContext: KibanaExecutionContext = {
id: 'Dashboard☺漢字',
type: 'test☺type',
name: 'test漢name',
description: 'parent-descripton',
};
const parentContainer = new ExecutionContextContainer(parentContext);

const context: KibanaExecutionContext = {
id: 'Visualization',
type: 'test-type',
name: 'test-name',
description: 'test-description',
};

const value = new ExecutionContextContainer(context).toString();
expect(value).toBe('test-type:test-name:Visualization%E2%98%BA%E6%BC%A2%E5%AD%97');
const value = new ExecutionContextContainer(context, parentContainer).toString();
expect(value).toBe(
'test%E2%98%BAtype:test%E6%BC%A2name:Dashboard%E2%98%BA%E6%BC%A2%E5%AD%97;test-type:test-name:Visualization'
);
});

it('trims a string representation of provided execution context if it is bigger max allowed size', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,23 @@ export interface IExecutionContextContainer {
}

function stringify(ctx: KibanaExecutionContext): string {
const stringifiedCtx = `${ctx.type}:${ctx.name}:${encodeURIComponent(ctx.id!)}`;
const stringifiedCtx = `${encodeURIComponent(ctx.type)}:${encodeURIComponent(
ctx.name
)}:${encodeURIComponent(ctx.id!)}`;
return ctx.child ? `${stringifiedCtx};${stringify(ctx.child)}` : stringifiedCtx;
}

export class ExecutionContextContainer implements IExecutionContextContainer {
readonly #context: Readonly<KibanaExecutionContext>;

constructor(context: KibanaExecutionContext, parent?: IExecutionContextContainer) {
this.#context = parent ? { ...parent.toJSON(), child: context } : context;
}

toString(): string {
return enforceMaxLength(stringify(this.#context));
}

toJSON() {
return this.#context;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ const parentContext = {
description: 'test-description',
};

const withUtf8CharsContext = {
type: 'test字type',
name: 'test漢字name',
id: '9000☺',
description: 'test-description',
};

describe('trace', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let root: ReturnType<typeof kbnTestServer.createRoot>;
Expand Down Expand Up @@ -384,6 +391,35 @@ describe('trace', () => {
expect(response.body).toEqual(parentContext);
});

it('supports UTF-8 characters', async () => {
const { http } = await root.setup();
const { createRouter } = http;

const router = createRouter('');
router.get({ path: '/execution-context', validate: false }, async (context, req, res) => {
const { headers } = await context.core.elasticsearch.client.asCurrentUser.ping(
{},
{ meta: true }
);
return res.ok({ body: headers || {} });
});

await root.start();
const response = await kbnTestServer.request
.get(root, '/execution-context')
.set('x-opaque-id', 'utf-test')
.set(new ExecutionContextContainer(withUtf8CharsContext).toHeader())
.expect(200);

const rawOpaqueId = response.body['x-opaque-id'];
expect(rawOpaqueId).toEqual(
'utf-test;kibana:test%E5%AD%97type:test%E6%BC%A2%E5%AD%97name:9000%E2%98%BA'
);
expect(decodeURIComponent(rawOpaqueId)).toEqual(
'utf-test;kibana:test字type:test漢字name:9000☺'
);
});

it('execution context is the same for all the lifecycle events', async () => {
const { executionContext, http } = await root.setup();
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
getQueryParams,
removeQueryParam,
} from '../../../../../kibana_utils/public';
import { SEARCH_SESSION_ID_QUERY_PARAM } from '../../../url_generator';
import { SEARCH_SESSION_ID_QUERY_PARAM } from '../../../constants';

export interface DiscoverSearchSessionManagerDeps {
history: History;
Expand Down
9 changes: 9 additions & 0 deletions src/plugins/discover/public/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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.
*/

export const SEARCH_SESSION_ID_QUERY_PARAM = 'searchSessionId';
6 changes: 0 additions & 6 deletions src/plugins/discover/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,5 @@ export type { ISearchEmbeddable, SearchInput } from './embeddable';
export { SEARCH_EMBEDDABLE_TYPE } from './embeddable';
export { loadSharingDataHelpers } from './utils';

export type { DiscoverUrlGeneratorState } from './url_generator';

/**
* @deprecated
*/
export { DISCOVER_APP_URL_GENERATOR } from './url_generator';
export { DISCOVER_APP_LOCATOR } from './locator';
export type { DiscoverAppLocator, DiscoverAppLocatorParams } from './locator';
3 changes: 0 additions & 3 deletions src/plugins/discover/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ const createSetupContract = (): Setup => {

const createStartContract = (): Start => {
const startContract: Start = {
urlGenerator: {
createUrl: jest.fn(),
} as unknown as DiscoverStart['urlGenerator'],
locator: sharePluginMock.createLocator(),
};
return startContract;
Expand Down
36 changes: 2 additions & 34 deletions src/plugins/discover/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { UiActionsStart, UiActionsSetup } from 'src/plugins/ui_actions/public';
import { EmbeddableStart, EmbeddableSetup } from 'src/plugins/embeddable/public';
import { ChartsPluginStart } from 'src/plugins/charts/public';
import { NavigationPublicPluginStart as NavigationStart } from 'src/plugins/navigation/public';
import { SharePluginStart, SharePluginSetup, UrlGeneratorContract } from 'src/plugins/share/public';
import { SharePluginStart, SharePluginSetup } from 'src/plugins/share/public';
import { UrlForwardingSetup, UrlForwardingStart } from 'src/plugins/url_forwarding/public';
import { HomePublicPluginSetup } from 'src/plugins/home/public';
import { Start as InspectorPublicPluginStart } from 'src/plugins/inspector/public';
Expand All @@ -31,7 +31,6 @@ import { DataPublicPluginStart, DataPublicPluginSetup, esFilters } from '../../d
import { SavedObjectsStart } from '../../saved_objects/public';
import { createKbnUrlTracker } from '../../kibana_utils/public';
import { DEFAULT_APP_CATEGORIES } from '../../../core/public';
import { UrlGeneratorState } from '../../share/public';
import { DocViewInput, DocViewInputFn } from './services/doc_views/doc_views_types';
import { DocViewsRegistry } from './services/doc_views/doc_views_registry';
import {
Expand All @@ -45,12 +44,6 @@ import {
} from './kibana_services';
import { registerFeature } from './register_feature';
import { buildServices } from './build_services';
import {
DiscoverUrlGeneratorState,
DISCOVER_APP_URL_GENERATOR,
DiscoverUrlGenerator,
SEARCH_SESSION_ID_QUERY_PARAM,
} from './url_generator';
import { DiscoverAppLocatorDefinition, DiscoverAppLocator } from './locator';
import { SearchEmbeddableFactory } from './embeddable';
import { UsageCollectionSetup } from '../../usage_collection/public';
Expand All @@ -64,12 +57,7 @@ import { injectTruncateStyles } from './utils/truncate_styles';
import { DOC_TABLE_LEGACY, TRUNCATE_MAX_HEIGHT } from '../common';
import { DataViewEditorStart } from '../../../plugins/data_view_editor/public';
import { useDiscoverServices } from './utils/use_discover_services';

declare module '../../share/public' {
export interface UrlGeneratorStateMapping {
[DISCOVER_APP_URL_GENERATOR]: UrlGeneratorState<DiscoverUrlGeneratorState>;
}
}
import { SEARCH_SESSION_ID_QUERY_PARAM } from './constants';

const DocViewerLegacyTable = React.lazy(
() => import('./services/doc_views/components/doc_viewer_table/legacy')
Expand Down Expand Up @@ -123,11 +111,6 @@ export interface DiscoverSetup {
}

export interface DiscoverStart {
/**
* @deprecated Use URL locator instead. URL generator will be removed.
*/
readonly urlGenerator: undefined | UrlGeneratorContract<'DISCOVER_APP_URL_GENERATOR'>;

/**
* `share` plugin URL locator for Discover app. Use it to generate links into
* Discover application, for example, navigate:
Expand Down Expand Up @@ -205,25 +188,11 @@ export class DiscoverPlugin
private appStateUpdater = new BehaviorSubject<AppUpdater>(() => ({}));
private docViewsRegistry: DocViewsRegistry | null = null;
private stopUrlTracking: (() => void) | undefined = undefined;

/**
* @deprecated
*/
private urlGenerator?: DiscoverStart['urlGenerator'];
private locator?: DiscoverAppLocator;

setup(core: CoreSetup<DiscoverStartPlugins, DiscoverStart>, plugins: DiscoverSetupPlugins) {
const baseUrl = core.http.basePath.prepend('/app/discover');

if (plugins.share) {
this.urlGenerator = plugins.share.urlGenerators.registerUrlGenerator(
new DiscoverUrlGenerator({
appBasePath: baseUrl,
useHash: core.uiSettings.get('state:storeInSessionStorage'),
})
);
}

if (plugins.share) {
this.locator = plugins.share.url.locators.create(
new DiscoverAppLocatorDefinition({
Expand Down Expand Up @@ -420,7 +389,6 @@ export class DiscoverPlugin
injectTruncateStyles(core.uiSettings.get(TRUNCATE_MAX_HEIGHT));

return {
urlGenerator: this.urlGenerator,
locator: this.locator,
};
}
Expand Down
Loading

0 comments on commit cdf28f3

Please sign in to comment.