Skip to content

Commit

Permalink
Merge branch 'main' into infra-ui-fix-lazy-public-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Jan 25, 2022
2 parents 7d5bb90 + e4f97cd commit 382ac4a
Show file tree
Hide file tree
Showing 69 changed files with 1,729 additions and 419 deletions.
105 changes: 104 additions & 1 deletion src/core/public/application/utils/parse_app_url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ describe('parseAppUrl', () => {
id: 'bar',
appRoute: '/custom-bar',
});
createApp({
id: 're',
});
createApp({
id: 'retail',
});
});

describe('with absolute paths', () => {
Expand All @@ -51,6 +57,14 @@ describe('parseAppUrl', () => {
app: 'bar',
path: undefined,
});
expect(parseAppUrl('/base-path/app/re', basePath, apps, currentUrl)).toEqual({
app: 're',
path: undefined,
});
expect(parseAppUrl('/base-path/app/retail', basePath, apps, currentUrl)).toEqual({
app: 'retail',
path: undefined,
});
});
it('parses the path', () => {
expect(parseAppUrl('/base-path/app/foo/some/path', basePath, apps, currentUrl)).toEqual({
Expand All @@ -63,6 +77,14 @@ describe('parseAppUrl', () => {
app: 'bar',
path: '/another/path/',
});
expect(parseAppUrl('/base-path/app/re/tail', basePath, apps, currentUrl)).toEqual({
app: 're',
path: '/tail',
});
expect(parseAppUrl('/base-path/app/retail/path', basePath, apps, currentUrl)).toEqual({
app: 'retail',
path: '/path',
});
});
it('includes query and hash in the path for default app route', () => {
expect(parseAppUrl('/base-path/app/foo#hash/bang', basePath, apps, currentUrl)).toEqual({
Expand All @@ -89,6 +111,18 @@ describe('parseAppUrl', () => {
app: 'foo',
path: '/path#hash/bang?hello=dolly',
});
expect(parseAppUrl('/base-path/app/re#hash/bang', basePath, apps, currentUrl)).toEqual({
app: 're',
path: '#hash/bang',
});
expect(parseAppUrl('/base-path/app/retail?hello=dolly', basePath, apps, currentUrl)).toEqual({
app: 'retail',
path: '?hello=dolly',
});
expect(parseAppUrl('/base-path/app/retail#hash/bang', basePath, apps, currentUrl)).toEqual({
app: 'retail',
path: '#hash/bang',
});
});
it('includes query and hash in the path for custom app route', () => {
expect(parseAppUrl('/base-path/custom-bar#hash/bang', basePath, apps, currentUrl)).toEqual({
Expand Down Expand Up @@ -190,7 +224,6 @@ describe('parseAppUrl', () => {
path: '/path#hash?hello=dolly',
});
});

it('returns undefined if the relative path redirect outside of the basePath', () => {
expect(
parseAppUrl(
Expand All @@ -201,6 +234,19 @@ describe('parseAppUrl', () => {
)
).toBeUndefined();
});
it('works with inclusive app ids', () => {
expect(
parseAppUrl(
'./retail/path',
basePath,
apps,
'https://kibana.local:8080/base-path/app/current'
)
).toEqual({
app: 'retail',
path: '/path',
});
});
});

describe('with absolute urls', () => {
Expand All @@ -217,6 +263,18 @@ describe('parseAppUrl', () => {
app: 'bar',
path: undefined,
});
expect(
parseAppUrl('https://kibana.local:8080/base-path/app/re', basePath, apps, currentUrl)
).toEqual({
app: 're',
path: undefined,
});
expect(
parseAppUrl('https://kibana.local:8080/base-path/app/retail', basePath, apps, currentUrl)
).toEqual({
app: 'retail',
path: undefined,
});
});
it('parses the path', () => {
expect(
Expand All @@ -241,6 +299,29 @@ describe('parseAppUrl', () => {
app: 'bar',
path: '/another/path/',
});

expect(
parseAppUrl(
'https://kibana.local:8080/base-path/app/re/some/path',
basePath,
apps,
currentUrl
)
).toEqual({
app: 're',
path: '/some/path',
});
expect(
parseAppUrl(
'https://kibana.local:8080/base-path/app/retail/another/path/',
basePath,
apps,
currentUrl
)
).toEqual({
app: 'retail',
path: '/another/path/',
});
});
it('includes query and hash in the path for default app routes', () => {
expect(
Expand Down Expand Up @@ -298,6 +379,28 @@ describe('parseAppUrl', () => {
app: 'foo',
path: '/path#hash/bang?hello=dolly',
});
expect(
parseAppUrl(
'https://kibana.local:8080/base-path/app/re#hash/bang',
basePath,
apps,
currentUrl
)
).toEqual({
app: 're',
path: '#hash/bang',
});
expect(
parseAppUrl(
'https://kibana.local:8080/base-path/app/re?hello=dolly',
basePath,
apps,
currentUrl
)
).toEqual({
app: 're',
path: '?hello=dolly',
});
});
it('includes query and hash in the path for custom app route', () => {
expect(
Expand Down
15 changes: 14 additions & 1 deletion src/core/public/application/utils/parse_app_url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const parseAppUrl = (
for (const app of apps.values()) {
const appPath = app.appRoute || `/app/${app.id}`;

if (url.startsWith(appPath)) {
if (urlInApp(url, appPath)) {
const path = url.substr(appPath.length);
return {
app: app.id,
Expand All @@ -70,3 +70,16 @@ export const parseAppUrl = (
}
}
};

const separators = ['/', '?', '#'];

const urlInApp = (url: string, appPath: string) => {
if (url === appPath) {
return true;
}
if (url.startsWith(appPath)) {
const nextChar = url.substring(appPath.length, appPath.length + 1);
return separators.includes(nextChar);
}
return false;
};
Original file line number Diff line number Diff line change
Expand Up @@ -540,14 +540,13 @@ describe('instrumentQueryAndDeprecationLogger', () => {
});
client.diagnostic.emit('response', new errors.ResponseError(response), response);

// One debug log entry from 'elasticsearch.query' context
expect(loggingSystemMock.collect(logger).debug.length).toEqual(1);
expect(loggingSystemMock.collect(logger).info[0][0]).toMatch(
// Test debug[1] since theree is one log entry from 'elasticsearch.query' context
expect(loggingSystemMock.collect(logger).debug[1][0]).toMatch(
'Elasticsearch deprecation: 299 Elasticsearch-8.1.0 "GET /_path is deprecated"'
);
expect(loggingSystemMock.collect(logger).info[0][0]).toMatch('Origin:kibana');
expect(loggingSystemMock.collect(logger).info[0][0]).toMatch(/Stack trace:\n.*at/);
expect(loggingSystemMock.collect(logger).info[0][0]).toMatch(
expect(loggingSystemMock.collect(logger).debug[1][0]).toMatch('Origin:kibana');
expect(loggingSystemMock.collect(logger).debug[1][0]).toMatch(/Stack trace:\n.*at/);
expect(loggingSystemMock.collect(logger).debug[1][0]).toMatch(
/Query:\n.*400\n.*GET \/_path\?hello\=dolly \[illegal_argument_exception\]: request \[\/_path\] contains unrecognized parameter: \[name\]/
);
});
Expand All @@ -573,7 +572,6 @@ describe('instrumentQueryAndDeprecationLogger', () => {
});
client.diagnostic.emit('response', null, response);

expect(loggingSystemMock.collect(logger).info).toEqual([]);
// Test debug[1] since theree is one log entry from 'elasticsearch.query' context
expect(loggingSystemMock.collect(logger).debug[1][0]).toMatch(
'Elasticsearch deprecation: 299 Elasticsearch-8.1.0 "GET /_path is deprecated"'
Expand Down Expand Up @@ -608,14 +606,13 @@ describe('instrumentQueryAndDeprecationLogger', () => {
});
client.diagnostic.emit('response', null, response);

// One debug log entry from 'elasticsearch.query' context
expect(loggingSystemMock.collect(logger).debug.length).toEqual(1);
expect(loggingSystemMock.collect(logger).info[0][0]).toMatch(
// Test debug[1] since theree is one log entry from 'elasticsearch.query' context
expect(loggingSystemMock.collect(logger).debug[1][0]).toMatch(
'Elasticsearch deprecation: 299 Elasticsearch-8.1.0 "GET /_path is deprecated"'
);
expect(loggingSystemMock.collect(logger).info[0][0]).toMatch('Origin:kibana');
expect(loggingSystemMock.collect(logger).info[0][0]).toMatch(/Stack trace:\n.*at/);
expect(loggingSystemMock.collect(logger).info[0][0]).toMatch(
expect(loggingSystemMock.collect(logger).debug[1][0]).toMatch('Origin:kibana');
expect(loggingSystemMock.collect(logger).debug[1][0]).toMatch(/Stack trace:\n.*at/);
expect(loggingSystemMock.collect(logger).debug[1][0]).toMatch(
/Query:\n.*200\n.*GET \/_path\?hello\=dolly/
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,9 @@ export const instrumentEsQueryAndDeprecationLogger = ({
// Strip the first 5 stack trace lines as these are irrelavent to finding the call site
const stackTrace = new Error().stack?.split('\n').slice(5).join('\n');

const deprecationMsg = `Elasticsearch deprecation: ${event.warnings}\nOrigin:${requestOrigin}\nStack trace:\n${stackTrace}\nQuery:\n${queryMsg}`;
if (requestOrigin === 'kibana') {
deprecationLogger.info(deprecationMsg);
} else {
deprecationLogger.debug(deprecationMsg);
}
deprecationLogger.debug(
`Elasticsearch deprecation: ${event.warnings}\nOrigin:${requestOrigin}\nStack trace:\n${stackTrace}\nQuery:\n${queryMsg}`
);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('migration from 7.7.2-xpack with 100k objects', () => {
loggers: [
{
name: 'root',
level: 'info',
appenders: ['file'],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ function createRoot() {
loggers: [
{
name: 'root',
level: 'info',
appenders: ['file'],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ function createRoot() {
loggers: [
{
name: 'root',
level: 'info',
appenders: ['file'],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function createRoot() {
loggers: [
{
name: 'root',
level: 'info',
appenders: ['file'],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ function createRoot(options: { maxBatchSizeBytes?: number }) {
loggers: [
{
name: 'root',
level: 'info',
appenders: ['file'],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function createRoot(options: { maxBatchSizeBytes?: number }) {
loggers: [
{
name: 'root',
level: 'info',
appenders: ['file'],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ function createRoot() {
{
name: 'root',
appenders: ['file'],
level: 'info',
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ function createRoot() {
{
name: 'root',
appenders: ['file'],
level: 'info',
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ describe('migrating from 7.3.0-xpack which used v1 migrations', () => {
{
name: 'root',
appenders: ['file'],
level: 'info',
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ describe('migrating from the same Kibana version that used v1 migrations', () =>
{
name: 'root',
appenders: ['file'],
level: 'info',
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function createRoot({ logFileName, hosts }: RootConfig) {
{
name: 'root',
appenders: ['file'],
level: 'info',
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ async function createRoot({ logFileName }: CreateRootConfig) {
{
name: 'root',
appenders: ['file'],
level: 'info',
},
{
name: 'savedobjects-service',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ function createRoot() {
loggers: [
{
name: 'root',
level: 'info',
appenders: ['file'],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function createRoot() {
loggers: [
{
name: 'root',
level: 'info',
appenders: ['file'],
},
],
Expand Down
19 changes: 19 additions & 0 deletions src/core/test_helpers/kbn_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,25 @@ export function createRootWithCorePlugins(settings = {}, cliArgs: Partial<CliArg
username: kibanaServerTestUser.username,
password: kibanaServerTestUser.password,
},
// Log ES deprecations to surface these in CI
logging: {
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' } },
},
},
// createRootWithSettings sets default value to "true", so undefined should be threatened as "true".
...(cliArgs.oss === false
? {
Expand Down
Loading

0 comments on commit 382ac4a

Please sign in to comment.