Skip to content

Commit

Permalink
Merge branch 'master' into alexwizp-reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Feb 3, 2020
2 parents 9b048e4 + cc9ff6d commit 54a27af
Show file tree
Hide file tree
Showing 49 changed files with 857 additions and 370 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-project-assigner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
name: Assign a PR to project based on label
steps:
- name: Assign to project
uses: elastic/github-actions/project-assigner@v1.0.0
uses: elastic/github-actions/project-assigner@v1.0.1
id: project_assigner
with:
issue-mappings: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/project-assigner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
name: Assign issue or PR to project based on label
steps:
- name: Assign to project
uses: elastic/github-actions/project-assigner@v1.0.0
uses: elastic/github-actions/project-assigner@v1.0.1
id: project_assigner
with:
issue-mappings: '[{"label": "Team:AppArch", "projectName": "kibana-app-arch", "columnId": 6173895}, {"label": "Feature:Lens", "projectName": "Lens", "columnId": 6219363}, {"label": "Team:Canvas", "projectName": "canvas", "columnId": 6187593}]'
Expand Down
88 changes: 88 additions & 0 deletions src/core/public/application/ui/app_container.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React from 'react';
import { mount } from 'enzyme';

import { AppContainer } from './app_container';
import { Mounter, AppMountParameters, AppStatus } from '../types';

describe('AppContainer', () => {
const appId = 'someApp';
const setAppLeaveHandler = jest.fn();

const flushPromises = async () => {
await new Promise(async resolve => {
setImmediate(() => resolve());
});
};

const createResolver = (): [Promise<void>, () => void] => {
let resolve: () => void | undefined;
const promise = new Promise<void>(r => {
resolve = r;
});
return [promise, resolve!];
};

const createMounter = (promise: Promise<void>): Mounter => ({
appBasePath: '/base-path',
appRoute: '/some-route',
unmountBeforeMounting: false,
mount: async ({ element }: AppMountParameters) => {
await promise;
const container = document.createElement('div');
container.innerHTML = 'some-content';
element.appendChild(container);
return () => container.remove();
},
});

it('should hide the "not found" page before mounting the route', async () => {
const [waitPromise, resolvePromise] = createResolver();
const mounter = createMounter(waitPromise);

const wrapper = mount(
<AppContainer
appId={appId}
appStatus={AppStatus.inaccessible}
mounter={mounter}
setAppLeaveHandler={setAppLeaveHandler}
/>
);

expect(wrapper.text()).toContain('Application Not Found');

wrapper.setProps({
appId,
setAppLeaveHandler,
mounter,
appStatus: AppStatus.accessible,
});
wrapper.update();

expect(wrapper.text()).toEqual('');

resolvePromise();
await flushPromises();
wrapper.update();

expect(wrapper.text()).toContain('some-content');
});
});
18 changes: 10 additions & 8 deletions src/core/public/application/ui/app_container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,27 @@ export const AppContainer: FunctionComponent<Props> = ({
unmountRef.current = null;
}
};
const mount = async () => {
if (!mounter || appStatus !== AppStatus.accessible) {
return setAppNotFound(true);
}

if (mounter.unmountBeforeMounting) {
unmount();
}
if (!mounter || appStatus !== AppStatus.accessible) {
return setAppNotFound(true);
}
setAppNotFound(false);

if (mounter.unmountBeforeMounting) {
unmount();
}

const mount = async () => {
unmountRef.current =
(await mounter.mount({
appBasePath: mounter.appBasePath,
element: elementRef.current!,
onAppLeave: handler => setAppLeaveHandler(appId, handler),
})) || null;
setAppNotFound(false);
};

mount();

return unmount;
}, [appId, appStatus, mounter, setAppLeaveHandler]);

Expand Down
7 changes: 4 additions & 3 deletions src/plugins/console/server/lib/elasticsearch_proxy_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import _ from 'lodash';
import http from 'http';
import https from 'https';
import url from 'url';
import { Duration } from 'moment';

const createAgent = (legacyConfig: any) => {
import { ESConfigForProxy } from '../types';

const createAgent = (legacyConfig: ESConfigForProxy) => {
const target = url.parse(_.head(legacyConfig.hosts));
if (!/^https/.test(target.protocol || '')) return new http.Agent();

Expand Down Expand Up @@ -59,7 +60,7 @@ const createAgent = (legacyConfig: any) => {
return new https.Agent(agentOptions);
};

export const getElasticsearchProxyConfig = (legacyConfig: { requestTimeout: Duration }) => {
export const getElasticsearchProxyConfig = (legacyConfig: ESConfigForProxy) => {
return {
timeout: legacyConfig.requestTimeout.asMilliseconds(),
agent: createAgent(legacyConfig),
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/console/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ export class ConsoleServerPlugin implements Plugin<ConsoleSetup> {
const legacyConfig = readLegacyEsConfig();
return {
...elasticsearch,
hosts: legacyConfig.hosts,
requestHeadersWhitelist: legacyConfig.requestHeadersWhitelist,
customHeaders: legacyConfig.customHeaders,
...legacyConfig,
};
},
pathFilters: proxyPathFilters,
Expand Down
8 changes: 8 additions & 0 deletions src/plugins/console/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ export interface ESConfigForProxy {
requestHeadersWhitelist: string[];
customHeaders: Record<string, any>;
requestTimeout: Duration;
ssl?: {
verificationMode: 'none' | 'certificate' | 'full';
certificateAuthorities: string[] | string;
alwaysPresentCertificate: boolean;
certificate?: string;
key?: string;
keyPassphrase?: string;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import {
EuiFlexGroup,
EuiFlexItem,
EuiHorizontalRule,
EuiTitle
} from '@elastic/eui';
import cytoscape from 'cytoscape';
import React from 'react';
import { Buttons } from './Buttons';
import { Info } from './Info';
import { ServiceMetricList } from './ServiceMetricList';

const popoverMinWidth = 280;

interface ContentsProps {
focusedServiceName?: string;
isService: boolean;
label: string;
onFocusClick: () => void;
selectedNodeData: cytoscape.NodeDataDefinition;
selectedNodeServiceName: string;
}

export function Contents({
selectedNodeData,
focusedServiceName,
isService,
label,
onFocusClick,
selectedNodeServiceName
}: ContentsProps) {
return (
<EuiFlexGroup
direction="column"
gutterSize="s"
style={{ minWidth: popoverMinWidth }}
>
<EuiFlexItem>
<EuiTitle size="xxs">
<h3>{label}</h3>
</EuiTitle>
<EuiHorizontalRule margin="xs" />
</EuiFlexItem>
<EuiFlexItem>
{isService ? (
<ServiceMetricList serviceName={selectedNodeServiceName} />
) : (
<Info {...selectedNodeData} />
)}
</EuiFlexItem>
{isService && (
<Buttons
focusedServiceName={focusedServiceName}
onFocusClick={onFocusClick}
selectedNodeServiceName={selectedNodeServiceName}
/>
)}
</EuiFlexGroup>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import lightTheme from '@elastic/eui/dist/eui_theme_light.json';
import { i18n } from '@kbn/i18n';
import cytoscape from 'cytoscape';
import React from 'react';
import styled from 'styled-components';
import lightTheme from '@elastic/eui/dist/eui_theme_light.json';

const ItemRow = styled.div`
line-height: 2;
Expand All @@ -19,8 +20,8 @@ const ItemTitle = styled.dt`

const ItemDescription = styled.dd``;

interface InfoProps {
type: string;
interface InfoProps extends cytoscape.NodeDataDefinition {
type?: string;
subtype?: string;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { storiesOf } from '@storybook/react';
import React from 'react';
import {
ApmPluginContext,
ApmPluginContextValue
} from '../../../../context/ApmPluginContext';
import { Contents } from './Contents';

const selectedNodeData = {
id: 'opbeans-node',
label: 'opbeans-node',
href:
'#/services/opbeans-node/service-map?rangeFrom=now-24h&rangeTo=now&refreshPaused=true&refreshInterval=0',
agentName: 'nodejs',
type: 'service'
};

storiesOf('app/ServiceMap/Popover/Contents', module).add(
'example',
() => {
return (
<ApmPluginContext.Provider
value={
({ core: { notifications: {} } } as unknown) as ApmPluginContextValue
}
>
<Contents
selectedNodeData={selectedNodeData}
isService={true}
label="opbeans-node"
onFocusClick={() => {}}
selectedNodeServiceName="opbeans-node"
/>
</ApmPluginContext.Provider>
);
},
{
info: {
propTablesExclude: [ApmPluginContext.Provider],
source: false
}
}
);
Loading

0 comments on commit 54a27af

Please sign in to comment.