Skip to content

Commit

Permalink
Merge branch 'master' into filebeat_notice
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Nov 13, 2019
2 parents 57f9c11 + 1010f28 commit f49ca9c
Show file tree
Hide file tree
Showing 63 changed files with 1,475 additions and 1,191 deletions.
13 changes: 10 additions & 3 deletions src/plugins/data/public/search/es_search/es_search_strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,25 @@
import { Observable } from 'rxjs';
import { ES_SEARCH_STRATEGY, IEsSearchResponse } from '../../../common/search';
import { SYNC_SEARCH_STRATEGY } from '../sync_search_strategy';
import { getEsPreference } from './get_es_preference';
import { TSearchStrategyProvider, ISearchStrategy, ISearchGeneric, ISearchContext } from '..';

export const esSearchStrategyProvider: TSearchStrategyProvider<typeof ES_SEARCH_STRATEGY> = (
context: ISearchContext,
search: ISearchGeneric
): ISearchStrategy<typeof ES_SEARCH_STRATEGY> => {
return {
search: (request, options) =>
search(
search: (request, options) => {
if (typeof request.params.preference === 'undefined') {
const setPreference = context.core.uiSettings.get('courier:setRequestPreference');
const customPreference = context.core.uiSettings.get('courier:customRequestPreference');
request.params.preference = getEsPreference(setPreference, customPreference);
}
return search(
{ ...request, serverStrategy: ES_SEARCH_STRATEGY },
options,
SYNC_SEARCH_STRATEGY
) as Observable<IEsSearchResponse>,
) as Observable<IEsSearchResponse>;
},
};
};
46 changes: 46 additions & 0 deletions src/plugins/data/public/search/es_search/get_es_preference.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 { getEsPreference } from './get_es_preference';

jest.useFakeTimers();

describe('Get ES preference', () => {
test('returns the session ID if set to sessionId', () => {
const setPreference = 'sessionId';
const customPreference = 'foobar';
const sessionId = 'my_session_id';
const preference = getEsPreference(setPreference, customPreference, sessionId);
expect(preference).toBe(sessionId);
});

test('returns the custom preference if set to custom', () => {
const setPreference = 'custom';
const customPreference = 'foobar';
const preference = getEsPreference(setPreference, customPreference);
expect(preference).toBe(customPreference);
});

test('returns undefined if set to none', () => {
const setPreference = 'none';
const customPreference = 'foobar';
const preference = getEsPreference(setPreference, customPreference);
expect(preference).toBe(undefined);
});
});
29 changes: 29 additions & 0 deletions src/plugins/data/public/search/es_search/get_es_preference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.
*/

const defaultSessionId = `${Date.now()}`;

export function getEsPreference(
setRequestPreference: string,
customRequestPreference?: string,
sessionId: string = defaultSessionId
) {
if (setRequestPreference === 'sessionId') return `${sessionId}`;
return setRequestPreference === 'custom' ? customRequestPreference : undefined;
}
5 changes: 1 addition & 4 deletions src/plugins/newsfeed/public/lib/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,7 @@ describe('getApi', () => {
.mockImplementationOnce(getHttpMockWithItems(successItems));

getApi(httpMock, configMock.newsfeed, '6.8.2')
.pipe(
take(4),
toArray()
)
.pipe(take(4), toArray())
.subscribe(result => {
expect(result).toMatchInlineSnapshot(`
Array [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { layout } from './layout';
import { metrics } from './metrics';
import { InventoryModel } from '../types';

export const container: InventoryModel = {
id: 'container',
requiredModules: ['docker'],
layout,
metrics,
requiredMetrics: [
'containerOverview',
'containerCpuUsage',
'containerMemory',
'containerNetworkTraffic',
'containerDiskIOBytes',
'containerDiskIOOps',
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,32 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { i18n } from '@kbn/i18n';
import { InventoryDetailLayoutCreator } from '../types';
import { nginxLayoutCreator } from '../shared/layouts/nginx';
import { LayoutPropsWithTheme } from '../../../public/pages/metrics/types';
import { Section } from '../../../public/pages/metrics/components/section';
import { SubSection } from '../../../public/pages/metrics/components/sub_section';
import { GaugesSectionVis } from '../../../public/pages/metrics/components/gauges_section_vis';
import { ChartSectionVis } from '../../../public/pages/metrics/components/chart_section_vis';
import { withTheme } from '../../../../../common/eui_styled_components';

export const layout: InventoryDetailLayoutCreator = theme => [
{
id: 'containerOverview',
label: i18n.translate('xpack.infra.metricDetailPage.containerMetricsLayout.layoutLabel', {
defaultMessage: 'Container',
}),
sections: [
{
id: 'containerOverview',
label: i18n.translate(
'xpack.infra.metricDetailPage.containerMetricsLayout.overviewSection.sectionLabel',
{
defaultMessage: 'Overview',
}
),
requires: ['docker.cpu', 'docker.memory', 'docker.network'],
type: 'gauges',
visConfig: {
seriesOverrides: {
export const Layout = withTheme(({ metrics, theme }: LayoutPropsWithTheme) => (
<React.Fragment>
<Section
navLabel={i18n.translate('xpack.infra.metricDetailPage.containerMetricsLayout.layoutLabel', {
defaultMessage: 'Container',
})}
sectionLabel={i18n.translate(
'xpack.infra.metricDetailPage.containerMetricsLayout.overviewSection.sectionLabel',
{
defaultMessage: 'Container Overview',
}
)}
metrics={metrics}
>
<SubSection id="containerOverview">
<GaugesSectionVis
seriesOverrides={{
cpu: {
name: i18n.translate(
'xpack.infra.metricDetailPage.containerMetricsLayout.overviewSection.cpuUsageSeriesLabel',
Expand Down Expand Up @@ -71,62 +73,59 @@ export const layout: InventoryDetailLayoutCreator = theme => [
formatter: 'bits',
formatterTemplate: '{{value}}/s',
},
},
},
},
{
id: 'containerCpuUsage',
label: i18n.translate(
}}
/>
</SubSection>
<SubSection
id="containerCpuUsage"
label={i18n.translate(
'xpack.infra.metricDetailPage.containerMetricsLayout.cpuUsageSection.sectionLabel',
{
defaultMessage: 'CPU Usage',
}
),
requires: ['docker.cpu'],
type: 'chart',
visConfig: {
stacked: true,
type: 'area',
formatter: 'percent',
seriesOverrides: {
)}
>
<ChartSectionVis
stacked={true}
type="area"
formatter="percent"
seriesOverrides={{
cpu: { color: theme.eui.euiColorVis1 },
},
},
},
{
id: 'containerMemory',
label: i18n.translate(
}}
/>
</SubSection>
<SubSection
id="containerMemory"
label={i18n.translate(
'xpack.infra.metricDetailPage.containerMetricsLayout.memoryUsageSection.sectionLabel',
{
defaultMessage: 'Memory Usage',
}
),
requires: ['docker.memory'],
type: 'chart',
visConfig: {
stacked: true,
type: 'area',
formatter: 'percent',
seriesOverrides: {
)}
>
<ChartSectionVis
stacked={true}
type="area"
formatter="percent"
seriesOverrides={{
memory: { color: theme.eui.euiColorVis1 },
},
},
},
{
id: 'containerNetworkTraffic',
label: i18n.translate(
}}
/>
</SubSection>
<SubSection
id="containerNetworkTraffic"
label={i18n.translate(
'xpack.infra.metricDetailPage.containerMetricsLayout.networkTrafficSection.sectionLabel',
{
defaultMessage: 'Network Traffic',
}
),
requires: ['docker.network'],
type: 'chart',
visConfig: {
formatter: 'bits',
formatterTemplate: '{{value}}/s',
type: 'area',
seriesOverrides: {
)}
>
<ChartSectionVis
formatter="bits"
formatterTemplate="{{value}}/s"
type="area"
seriesOverrides={{
rx: {
color: theme.eui.euiColorVis1,
name: i18n.translate(
Expand All @@ -145,24 +144,23 @@ export const layout: InventoryDetailLayoutCreator = theme => [
}
),
},
},
},
},
{
id: 'containerDiskIOOps',
label: i18n.translate(
}}
/>
</SubSection>
<SubSection
id="containerDiskIOOps"
label={i18n.translate(
'xpack.infra.metricDetailPage.containerMetricsLayout.diskIoOpsSection.sectionLabel',
{
defaultMessage: 'Disk IO (Ops)',
}
),
requires: ['docker.diskio'],
type: 'chart',
visConfig: {
formatter: 'number',
formatterTemplate: '{{value}}/s',
type: 'area',
seriesOverrides: {
)}
>
<ChartSectionVis
type="area"
formatterTemplate="{{value}}/s"
formatter="number"
seriesOverrides={{
read: {
color: theme.eui.euiColorVis1,
name: i18n.translate(
Expand All @@ -181,24 +179,23 @@ export const layout: InventoryDetailLayoutCreator = theme => [
}
),
},
},
},
},
{
id: 'containerDiskIOBytes',
label: i18n.translate(
}}
/>
</SubSection>
<SubSection
id="containerDiskIOBytes"
label={i18n.translate(
'xpack.infra.metricDetailPage.containerMetricsLayout.diskIoBytesSection.sectionLabel',
{
defaultMessage: 'Disk IO (Bytes)',
}
),
requires: ['docker.diskio'],
type: 'chart',
visConfig: {
formatter: 'bytes',
formatterTemplate: '{{value}}/s',
type: 'area',
seriesOverrides: {
)}
>
<ChartSectionVis
type="area"
formatter="bytes"
formatterTemplate="{{value}}/s"
seriesOverrides={{
read: {
color: theme.eui.euiColorVis1,
name: i18n.translate(
Expand All @@ -217,10 +214,9 @@ export const layout: InventoryDetailLayoutCreator = theme => [
}
),
},
},
},
},
],
},
...nginxLayoutCreator(theme),
];
}}
/>
</SubSection>
</Section>
</React.Fragment>
));
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export const metrics: InventoryMetrics = {
containerMemory,
},
snapshot: { cpu, memory, rx, tx },
defaultSnapshot: 'cpu',
};
Loading

0 comments on commit f49ca9c

Please sign in to comment.