Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
Browse files Browse the repository at this point in the history
…-rule-type
  • Loading branch information
patrykkopycinski committed Jul 14, 2020
2 parents 51780f9 + 3374b2d commit 96d4007
Show file tree
Hide file tree
Showing 76 changed files with 531 additions and 449 deletions.
13 changes: 7 additions & 6 deletions src/core/public/application/scoped_history.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
import { Location } from 'history';
import { ScopedHistory } from './scoped_history';

type ScopedHistoryMock = jest.Mocked<Pick<ScopedHistory, keyof ScopedHistory>>;
export type ScopedHistoryMock = jest.Mocked<ScopedHistory>;

const createMock = ({
pathname = '/',
search = '',
hash = '',
key,
state,
...overrides
}: Partial<Location & ScopedHistoryMock> = {}) => {
const mock: ScopedHistoryMock = {
}: Partial<Location> = {}) => {
const mock: jest.Mocked<Pick<ScopedHistory, keyof ScopedHistory>> = {
block: jest.fn(),
createHref: jest.fn(),
createSubHistory: jest.fn(),
Expand All @@ -39,7 +39,6 @@ const createMock = ({
listen: jest.fn(),
push: jest.fn(),
replace: jest.fn(),
...overrides,
action: 'PUSH',
length: 1,
location: {
Expand All @@ -51,7 +50,9 @@ const createMock = ({
},
};

return mock;
// jest.Mocked still expects private methods and properties to be present, even
// if not part of the public contract.
return mock as ScopedHistoryMock;
};

export const scopedHistoryMock = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { coreMock, scopedHistoryMock } from '../../../../../core/public/mocks';
import { EmbeddableStateTransfer } from '.';
import { ApplicationStart, ScopedHistory } from '../../../../../core/public';
import { ApplicationStart } from '../../../../../core/public';

function mockHistoryState(state: unknown) {
return scopedHistoryMock.create({ state });
Expand All @@ -46,10 +46,7 @@ describe('embeddable state transfer', () => {

it('can send an outgoing originating app state in append mode', async () => {
const historyMock = mockHistoryState({ kibanaIsNowForSports: 'extremeSportsKibana' });
stateTransfer = new EmbeddableStateTransfer(
application.navigateToApp,
(historyMock as unknown) as ScopedHistory
);
stateTransfer = new EmbeddableStateTransfer(application.navigateToApp, historyMock);
await stateTransfer.navigateToEditor(destinationApp, {
state: { originatingApp },
appendToExistingState: true,
Expand All @@ -74,10 +71,7 @@ describe('embeddable state transfer', () => {

it('can send an outgoing embeddable package state in append mode', async () => {
const historyMock = mockHistoryState({ kibanaIsNowForSports: 'extremeSportsKibana' });
stateTransfer = new EmbeddableStateTransfer(
application.navigateToApp,
(historyMock as unknown) as ScopedHistory
);
stateTransfer = new EmbeddableStateTransfer(application.navigateToApp, historyMock);
await stateTransfer.navigateToWithEmbeddablePackage(destinationApp, {
state: { type: 'coolestType', id: '150' },
appendToExistingState: true,
Expand All @@ -90,40 +84,28 @@ describe('embeddable state transfer', () => {

it('can fetch an incoming originating app state', async () => {
const historyMock = mockHistoryState({ originatingApp: 'extremeSportsKibana' });
stateTransfer = new EmbeddableStateTransfer(
application.navigateToApp,
(historyMock as unknown) as ScopedHistory
);
stateTransfer = new EmbeddableStateTransfer(application.navigateToApp, historyMock);
const fetchedState = stateTransfer.getIncomingEditorState();
expect(fetchedState).toEqual({ originatingApp: 'extremeSportsKibana' });
});

it('returns undefined with originating app state is not in the right shape', async () => {
const historyMock = mockHistoryState({ kibanaIsNowForSports: 'extremeSportsKibana' });
stateTransfer = new EmbeddableStateTransfer(
application.navigateToApp,
(historyMock as unknown) as ScopedHistory
);
stateTransfer = new EmbeddableStateTransfer(application.navigateToApp, historyMock);
const fetchedState = stateTransfer.getIncomingEditorState();
expect(fetchedState).toBeUndefined();
});

it('can fetch an incoming embeddable package state', async () => {
const historyMock = mockHistoryState({ type: 'skisEmbeddable', id: '123' });
stateTransfer = new EmbeddableStateTransfer(
application.navigateToApp,
(historyMock as unknown) as ScopedHistory
);
stateTransfer = new EmbeddableStateTransfer(application.navigateToApp, historyMock);
const fetchedState = stateTransfer.getIncomingEmbeddablePackage();
expect(fetchedState).toEqual({ type: 'skisEmbeddable', id: '123' });
});

it('returns undefined when embeddable package is not in the right shape', async () => {
const historyMock = mockHistoryState({ kibanaIsNowForSports: 'extremeSportsKibana' });
stateTransfer = new EmbeddableStateTransfer(
application.navigateToApp,
(historyMock as unknown) as ScopedHistory
);
stateTransfer = new EmbeddableStateTransfer(application.navigateToApp, historyMock);
const fetchedState = stateTransfer.getIncomingEmbeddablePackage();
expect(fetchedState).toBeUndefined();
});
Expand All @@ -135,10 +117,7 @@ describe('embeddable state transfer', () => {
test1: 'test1',
test2: 'test2',
});
stateTransfer = new EmbeddableStateTransfer(
application.navigateToApp,
(historyMock as unknown) as ScopedHistory
);
stateTransfer = new EmbeddableStateTransfer(application.navigateToApp, historyMock);
stateTransfer.getIncomingEmbeddablePackage({ keysToRemoveAfterFetch: ['type', 'id'] });
expect(historyMock.replace).toHaveBeenCalledWith(
expect.objectContaining({ state: { test1: 'test1', test2: 'test2' } })
Expand All @@ -152,10 +131,7 @@ describe('embeddable state transfer', () => {
test1: 'test1',
test2: 'test2',
});
stateTransfer = new EmbeddableStateTransfer(
application.navigateToApp,
(historyMock as unknown) as ScopedHistory
);
stateTransfer = new EmbeddableStateTransfer(application.navigateToApp, historyMock);
stateTransfer.getIncomingEmbeddablePackage();
expect(historyMock.location.state).toEqual({
type: 'skisEmbeddable',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,14 @@

.series > path,
.series > rect {
fill-opacity: .8;
stroke-opacity: 1;
stroke-width: 0;
}

.series > path {
fill-opacity: .8;
}

.blur_shape {
// sass-lint:disable-block no-important
opacity: .3 !important;
Expand Down
8 changes: 3 additions & 5 deletions x-pack/plugins/apm/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import { toggleAppLinkInNav } from './toggleAppLinkInNav';
import { setReadonlyBadge } from './updateBadge';
import { createStaticIndexPattern } from './services/rest/index_pattern';
import {
fetchLandingPageData,
fetchOverviewPageData,
hasData,
} from './services/rest/observability_dashboard';
} from './services/rest/apm_overview_fetchers';

export type ApmPluginSetup = void;
export type ApmPluginStart = void;
Expand Down Expand Up @@ -81,9 +81,7 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
if (plugins.observability) {
plugins.observability.dashboard.register({
appName: 'apm',
fetchData: async (params) => {
return fetchLandingPageData(params);
},
fetchData: fetchOverviewPageData,
hasData,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { fetchLandingPageData, hasData } from './observability_dashboard';
import moment from 'moment';
import { fetchOverviewPageData, hasData } from './apm_overview_fetchers';
import * as createCallApmApi from './createCallApmApi';

describe('Observability dashboard data', () => {
const callApmApiMock = jest.spyOn(createCallApmApi, 'callApmApi');
const params = {
absoluteTime: {
start: moment('2020-07-02T13:25:11.629Z').valueOf(),
end: moment('2020-07-09T14:25:11.629Z').valueOf(),
},
relativeTime: {
start: 'now-15m',
end: 'now',
},
bucketSize: '600s',
};
afterEach(() => {
callApmApiMock.mockClear();
});
Expand All @@ -25,7 +37,7 @@ describe('Observability dashboard data', () => {
});
});

describe('fetchLandingPageData', () => {
describe('fetchOverviewPageData', () => {
it('returns APM data with series and stats', async () => {
callApmApiMock.mockImplementation(() =>
Promise.resolve({
Expand All @@ -37,14 +49,9 @@ describe('Observability dashboard data', () => {
],
})
);
const response = await fetchLandingPageData({
startTime: '1',
endTime: '2',
bucketSize: '3',
});
const response = await fetchOverviewPageData(params);
expect(response).toEqual({
title: 'APM',
appLink: '/app/apm',
appLink: '/app/apm#/services?rangeFrom=now-15m&rangeTo=now',
stats: {
services: {
type: 'number',
Expand Down Expand Up @@ -73,14 +80,9 @@ describe('Observability dashboard data', () => {
transactionCoordinates: [],
})
);
const response = await fetchLandingPageData({
startTime: '1',
endTime: '2',
bucketSize: '3',
});
const response = await fetchOverviewPageData(params);
expect(response).toEqual({
title: 'APM',
appLink: '/app/apm',
appLink: '/app/apm#/services?rangeFrom=now-15m&rangeTo=now',
stats: {
services: {
type: 'number',
Expand All @@ -105,14 +107,9 @@ describe('Observability dashboard data', () => {
transactionCoordinates: [{ x: 1 }, { x: 2 }, { x: 3 }],
})
);
const response = await fetchLandingPageData({
startTime: '1',
endTime: '2',
bucketSize: '3',
});
const response = await fetchOverviewPageData(params);
expect(response).toEqual({
title: 'APM',
appLink: '/app/apm',
appLink: '/app/apm#/services?rangeFrom=now-15m&rangeTo=now',
stats: {
services: {
type: 'number',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,33 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { i18n } from '@kbn/i18n';
import { mean } from 'lodash';
import {
ApmFetchDataResponse,
FetchDataParams,
} from '../../../../observability/public';
import { callApmApi } from './createCallApmApi';

export const fetchLandingPageData = async ({
startTime,
endTime,
export const fetchOverviewPageData = async ({
absoluteTime,
relativeTime,
bucketSize,
}: FetchDataParams): Promise<ApmFetchDataResponse> => {
const data = await callApmApi({
pathname: '/api/apm/observability_dashboard',
params: { query: { start: startTime, end: endTime, bucketSize } },
pathname: '/api/apm/observability_overview',
params: {
query: {
start: new Date(absoluteTime.start).toISOString(),
end: new Date(absoluteTime.end).toISOString(),
bucketSize,
},
},
});

const { serviceCount, transactionCoordinates } = data;

return {
title: i18n.translate('xpack.apm.observabilityDashboard.title', {
defaultMessage: 'APM',
}),
appLink: '/app/apm',
appLink: `/app/apm#/services?rangeFrom=${relativeTime.start}&rangeTo=${relativeTime.end}`,
stats: {
services: {
type: 'number',
Expand All @@ -54,6 +56,6 @@ export const fetchLandingPageData = async ({

export async function hasData() {
return await callApmApi({
pathname: '/api/apm/observability_dashboard/has_data',
pathname: '/api/apm/observability_overview/has_data',
});
}
10 changes: 5 additions & 5 deletions x-pack/plugins/apm/server/routes/create_apm_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ import {
rumServicesRoute,
} from './rum_client';
import {
observabilityDashboardHasDataRoute,
observabilityDashboardDataRoute,
} from './observability_dashboard';
observabilityOverviewHasDataRoute,
observabilityOverviewRoute,
} from './observability_overview';
import {
anomalyDetectionJobsRoute,
createAnomalyDetectionJobsRoute,
Expand Down Expand Up @@ -176,8 +176,8 @@ const createApmApi = () => {
.add(rumServicesRoute)

// Observability dashboard
.add(observabilityDashboardHasDataRoute)
.add(observabilityDashboardDataRoute)
.add(observabilityOverviewHasDataRoute)
.add(observabilityOverviewRoute)

// Anomaly detection
.add(anomalyDetectionJobsRoute)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
*/
import * as t from 'io-ts';
import { setupRequest } from '../lib/helpers/setup_request';
import { hasData } from '../lib/observability_dashboard/has_data';
import { getServiceCount } from '../lib/observability_overview/get_service_count';
import { getTransactionCoordinates } from '../lib/observability_overview/get_transaction_coordinates';
import { hasData } from '../lib/observability_overview/has_data';
import { createRoute } from './create_route';
import { rangeRt } from './default_api_types';
import { getServiceCount } from '../lib/observability_dashboard/get_service_count';
import { getTransactionCoordinates } from '../lib/observability_dashboard/get_transaction_coordinates';

export const observabilityDashboardHasDataRoute = createRoute(() => ({
path: '/api/apm/observability_dashboard/has_data',
export const observabilityOverviewHasDataRoute = createRoute(() => ({
path: '/api/apm/observability_overview/has_data',
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
return await hasData({ setup });
},
}));

export const observabilityDashboardDataRoute = createRoute(() => ({
path: '/api/apm/observability_dashboard',
export const observabilityOverviewRoute = createRoute(() => ({
path: '/api/apm/observability_overview',
params: {
query: t.intersection([rangeRt, t.type({ bucketSize: t.string })]),
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 96d4007

Please sign in to comment.