Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into es-query
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Nov 14, 2019
2 parents 5888433 + 5a8fabd commit c7a2a6b
Show file tree
Hide file tree
Showing 13 changed files with 1,775 additions and 46 deletions.
76 changes: 57 additions & 19 deletions src/core/public/chrome/nav_links/nav_links_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,34 @@

import { NavLinksService } from './nav_links_service';
import { take, map, takeLast } from 'rxjs/operators';
import { LegacyApp } from '../../application';
import { App, LegacyApp } from '../../application';

const mockAppService = {
availableApps: new Map(),
availableLegacyApps: new Map<string, LegacyApp>([
[
'legacyApp1',
{ id: 'legacyApp1', order: 0, title: 'Legacy App 1', icon: 'legacyApp1', appUrl: '/app1' },
],
[
'legacyApp2',
availableApps: new Map<string, App>(
([
{ id: 'app1', order: 0, title: 'App 1', icon: 'app1' },
{
id: 'legacyApp2',
id: 'app2',
order: -10,
title: 'App 2',
euiIconType: 'canvasApp',
},
{ id: 'chromelessApp', order: 20, title: 'Chromless App', chromeless: true },
] as App[]).map(app => [app.id, app])
),
availableLegacyApps: new Map<string, LegacyApp>(
([
{ id: 'legacyApp1', order: 5, title: 'Legacy App 1', icon: 'legacyApp1', appUrl: '/app1' },
{
id: 'legacyApp2',
order: -5,
title: 'Legacy App 2',
euiIconType: 'canvasApp',
appUrl: '/app2',
},
],
['legacyApp3', { id: 'legacyApp3', order: 20, title: 'Legacy App 3', appUrl: '/app3' }],
]),
{ id: 'legacyApp3', order: 15, title: 'Legacy App 3', appUrl: '/app3' },
] as LegacyApp[]).map(app => [app.id, app])
),
} as any;

const mockHttp = {
Expand All @@ -58,6 +65,18 @@ describe('NavLinksService', () => {
});

describe('#getNavLinks$()', () => {
it('does not include `chromeless` applications', async () => {
expect(
await start
.getNavLinks$()
.pipe(
take(1),
map(links => links.map(l => l.id))
)
.toPromise()
).not.toContain('chromelessApp');
});

it('sorts navlinks by `order` property', async () => {
expect(
await start
Expand All @@ -67,7 +86,7 @@ describe('NavLinksService', () => {
map(links => links.map(l => l.id))
)
.toPromise()
).toEqual(['legacyApp2', 'legacyApp1', 'legacyApp3']);
).toEqual(['app2', 'legacyApp2', 'app1', 'legacyApp1', 'legacyApp3']);
});

it('emits multiple values', async () => {
Expand All @@ -78,8 +97,8 @@ describe('NavLinksService', () => {

service.stop();
expect(emittedLinks).toEqual([
['legacyApp2', 'legacyApp1', 'legacyApp3'],
['legacyApp2', 'legacyApp1', 'legacyApp3'],
['app2', 'legacyApp2', 'app1', 'legacyApp1', 'legacyApp3'],
['app2', 'legacyApp2', 'app1', 'legacyApp1', 'legacyApp3'],
]);
});

Expand All @@ -105,7 +124,13 @@ describe('NavLinksService', () => {

describe('#getAll()', () => {
it('returns a sorted array of navlinks', () => {
expect(start.getAll().map(l => l.id)).toEqual(['legacyApp2', 'legacyApp1', 'legacyApp3']);
expect(start.getAll().map(l => l.id)).toEqual([
'app2',
'legacyApp2',
'app1',
'legacyApp1',
'legacyApp3',
]);
});
});

Expand All @@ -130,7 +155,20 @@ describe('NavLinksService', () => {
map(links => links.map(l => l.id))
)
.toPromise()
).toEqual(['legacyApp2', 'legacyApp1', 'legacyApp3']);
).toEqual(['app2', 'legacyApp2', 'app1', 'legacyApp1', 'legacyApp3']);
});

it('does nothing on chromeless applications', async () => {
start.showOnly('chromelessApp');
expect(
await start
.getNavLinks$()
.pipe(
take(1),
map(links => links.map(l => l.id))
)
.toPromise()
).toEqual(['app2', 'legacyApp2', 'app1', 'legacyApp1', 'legacyApp3']);
});

it('removes all other links', async () => {
Expand All @@ -157,7 +195,7 @@ describe('NavLinksService', () => {
"icon": "legacyApp1",
"id": "legacyApp1",
"legacy": true,
"order": 0,
"order": 5,
"title": "Legacy App 1",
}
`);
Expand Down
24 changes: 13 additions & 11 deletions src/core/public/chrome/nav_links/nav_links_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,19 @@ export class NavLinksService {
private readonly stop$ = new ReplaySubject(1);

public start({ application, http }: StartDeps): ChromeNavLinks {
const appLinks = [...application.availableApps].map(
([appId, app]) =>
[
appId,
new NavLinkWrapper({
...app,
legacy: false,
baseUrl: relativeToAbsolute(http.basePath.prepend(`/app/${appId}`)),
}),
] as [string, NavLinkWrapper]
);
const appLinks = [...application.availableApps]
.filter(([, app]) => !app.chromeless)
.map(
([appId, app]) =>
[
appId,
new NavLinkWrapper({
...app,
legacy: false,
baseUrl: relativeToAbsolute(http.basePath.prepend(`/app/${appId}`)),
}),
] as [string, NavLinkWrapper]
);

const legacyAppLinks = [...application.availableLegacyApps].map(
([appId, app]) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,18 @@ export default function({ getService, getPageObjects }: PluginFunctionalProvider
await testSubjects.existOrFail('fooAppPageA');
});

it('chromeless applications are not visible in apps list', async () => {
expect(await appsMenu.linkExists('Chromeless')).to.be(false);
});

it('navigating to chromeless application hides chrome', async () => {
await appsMenu.clickLink('Chromeless');
await PageObjects.common.navigateToApp('chromeless');
await loadingScreenNotShown();
expect(await testSubjects.exists('headerGlobalNav')).to.be(false);
});

it('navigating away from chromeless application shows chrome', async () => {
await browser.goBack();
await PageObjects.common.navigateToApp('foo');
await loadingScreenNotShown();
expect(await testSubjects.exists('headerGlobalNav')).to.be(true);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import moment from 'moment';
import { get } from 'lodash';
import { get, uniq } from 'lodash';
import { createQuery } from '../create_query';
import { LogstashMetric } from '../metrics';

Expand Down Expand Up @@ -74,5 +74,6 @@ export async function getLogstashPipelineIds(req, logstashIndexPattern, { cluste

const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('monitoring');
const response = await callWithRequest(req, 'search', params);
return get(response, 'aggregations.nested_context.composite_data.buckets', []).map(bucket => bucket.key);
const data = get(response, 'aggregations.nested_context.composite_data.buckets', []).map(bucket => bucket.key);
return uniq(data, item => item.id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ describe('getInfraHref', () => {
expect(getInfraKubernetesHref(summary, '')).toBeUndefined();
});

it('getInfraKubernetesHref returns undefined when checks are null', () => {
summary.state.checks![0]!.kubernetes!.pod!.uid = null;
expect(getInfraKubernetesHref(summary, '')).toBeUndefined();
});

it('getInfraIpHref creates a link for valid parameters', () => {
const result = getInfraIpHref(summary, 'bar');
expect(result).toMatchSnapshot();
Expand All @@ -161,6 +166,11 @@ describe('getInfraHref', () => {
expect(getInfraIpHref(summary, 'foo')).toBeUndefined();
});

it('getInfraIpHref returns undefined when ip is null', () => {
summary.state.checks![0].monitor.ip = null;
expect(getInfraIpHref(summary, 'foo')).toBeUndefined();
});

it('getInfraIpHref returns a url for ors between multiple ips', () => {
summary.state.checks = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,28 @@ describe('getLoggingHref', () => {
expect(getLoggingContainerHref(summary, '')).toBeUndefined();
});

it('returns undefined if necessary container is null', () => {
summary.state.checks![0].container!.id = null;
expect(getLoggingContainerHref(summary, '')).toBeUndefined();
});

it('returns undefined if necessary pod is not present', () => {
delete summary.state.checks;
expect(getLoggingKubernetesHref(summary, '')).toBeUndefined();
});

it('returns undefined if necessary pod is null', () => {
summary.state.checks![0].kubernetes!.pod!.uid = null;
expect(getLoggingKubernetesHref(summary, '')).toBeUndefined();
});

it('returns undefined ip href if ip is not present', () => {
delete summary.state.checks;
expect(getLoggingIpHref(summary, '')).toBeUndefined();
});

it('returns undefined ip href if ip is null', () => {
summary.state.checks![0].monitor.ip = null;
expect(getLoggingIpHref(summary, '')).toBeUndefined();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const getInfraContainerHref = (
basePath: string
): string | undefined => {
const getHref = (value: string | string[] | undefined) => {
if (value === undefined) {
return value;
if (!value) {
return undefined;
}
const ret = !Array.isArray(value) ? value : value[0];
return addBasePath(basePath, `/app/infra#/link-to/container-detail/${encodeURIComponent(ret)}`);
Expand All @@ -27,8 +27,8 @@ export const getInfraKubernetesHref = (
basePath: string
): string | undefined => {
const getHref = (value: string | string[] | undefined) => {
if (value === undefined) {
return value;
if (!value) {
return undefined;
}
const ret = !Array.isArray(value) ? value : value[0];
return addBasePath(basePath, `/app/infra#/link-to/pod-detail/${encodeURIComponent(ret)}`);
Expand All @@ -39,8 +39,8 @@ export const getInfraKubernetesHref = (

export const getInfraIpHref = (summary: MonitorSummary, basePath: string) => {
const getHref = (value: string | string[] | undefined) => {
if (value === undefined) {
return value;
if (!value) {
return undefined;
}
if (!Array.isArray(value)) {
const expression = encodeURIComponent(`host.ip : ${value}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const getLoggingContainerHref = (
basePath: string
): string | undefined => {
const getHref = (value: string | string[] | undefined) => {
if (value === undefined) {
return value;
if (!value) {
return undefined;
}
const ret = !Array.isArray(value) ? value : value[0];
return addBasePath(
Expand All @@ -27,8 +27,8 @@ export const getLoggingContainerHref = (

export const getLoggingKubernetesHref = (summary: MonitorSummary, basePath: string) => {
const getHref = (value: string | string[] | undefined) => {
if (value === undefined) {
return value;
if (!value) {
return undefined;
}
const ret = !Array.isArray(value) ? value : value[0];
return addBasePath(
Expand All @@ -41,8 +41,8 @@ export const getLoggingKubernetesHref = (summary: MonitorSummary, basePath: stri

export const getLoggingIpHref = (summary: MonitorSummary, basePath: string) => {
const getHref = (value: string | string[] | undefined) => {
if (value === undefined) {
return value;
if (!value) {
return undefined;
}
const ret = !Array.isArray(value) ? value : value[0];
return addBasePath(
Expand Down
Loading

0 comments on commit c7a2a6b

Please sign in to comment.