Skip to content

Commit

Permalink
addressing pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Jul 9, 2020
1 parent 429c39c commit 7e5b9ae
Show file tree
Hide file tree
Showing 18 changed files with 54 additions and 58 deletions.
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,15 +4,16 @@
* 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: '2020-07-02T13:25:11.629Z',
end: '2020-07-09T14:25:11.629Z',
start: moment('2020-07-02T13:25:11.629Z').valueOf(),
end: moment('2020-07-09T14:25:11.629Z').valueOf(),
},
relativeTime: {
start: 'now-15m',
Expand All @@ -36,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 @@ -48,7 +49,7 @@ describe('Observability dashboard data', () => {
],
})
);
const response = await fetchLandingPageData(params);
const response = await fetchOverviewPageData(params);
expect(response).toEqual({
appLink: '/app/apm#/services?rangeFrom=now-15m&rangeTo=now',
stats: {
Expand Down Expand Up @@ -79,7 +80,7 @@ describe('Observability dashboard data', () => {
transactionCoordinates: [],
})
);
const response = await fetchLandingPageData(params);
const response = await fetchOverviewPageData(params);
expect(response).toEqual({
appLink: '/app/apm#/services?rangeFrom=now-15m&rangeTo=now',
stats: {
Expand All @@ -106,7 +107,7 @@ describe('Observability dashboard data', () => {
transactionCoordinates: [{ x: 1 }, { x: 2 }, { x: 3 }],
})
);
const response = await fetchLandingPageData(params);
const response = await fetchOverviewPageData(params);
expect(response).toEqual({
appLink: '/app/apm#/services?rangeFrom=now-15m&rangeTo=now',
stats: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ import {
} from '../../../../observability/public';
import { callApmApi } from './createCallApmApi';

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

Expand Down Expand Up @@ -52,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,
observabilityOverviewDataRoute,
} 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(observabilityOverviewDataRoute)

// 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 observabilityOverviewDataRoute = createRoute(() => ({
path: '/api/apm/observability_overview',
params: {
query: t.intersection([rangeRt, t.type({ bucketSize: t.string })]),
},
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/infra/public/metrics_overview_fetchers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ describe('Metrics UI Observability Homepage Functions', () => {
const bucketSize = '300s';
const response = await fetchData({
absoluteTime: {
start: startTime.toISOString(),
end: endTime.toISOString(),
start: startTime.valueOf(),
end: endTime.valueOf(),
},
relativeTime: {
start: 'now-15m',
Expand Down
9 changes: 4 additions & 5 deletions x-pack/plugins/infra/public/metrics_overview_fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ export const createMetricsFetchData = (
const [coreServices] = await getStartServices();
const { http } = coreServices;

const from = moment(absoluteTime.start).valueOf();
const to = moment(absoluteTime.end).valueOf();
const { start, end } = absoluteTime;

const snapshotRequest: SnapshotRequest = {
sourceId: 'default',
Expand All @@ -90,8 +89,8 @@ export const createMetricsFetchData = (
nodeType: 'host',
includeTimeseries: true,
timerange: {
from,
to,
from: start,
to: end,
interval: bucketSize,
forceInterval: true,
ignoreLookback: true,
Expand All @@ -102,7 +101,7 @@ export const createMetricsFetchData = (
body: JSON.stringify(snapshotRequest),
});
return {
appLink: `/app/metrics/inventory?waffleTime=(currentTime:${to},isAutoReloading:!f)`,
appLink: `/app/metrics/inventory?waffleTime=(currentTime:${end},isAutoReloading:!f)`,
stats: {
hosts: {
type: 'number',
Expand Down
9 changes: 3 additions & 6 deletions x-pack/plugins/infra/public/utils/logs_overview_fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ export function getLogsOverviewDataFetcher(
data
);

const timeSpanInMinutes =
(Date.parse(params.absoluteTime.end).valueOf() -
Date.parse(params.absoluteTime.start).valueOf()) /
(1000 * 60);
const timeSpanInMinutes = (params.absoluteTime.end - params.absoluteTime.start) / (1000 * 60);

return {
appLink: `/app/logs/stream?logPosition=(end:${encode(params.relativeTime.end)},start:${encode(
Expand Down Expand Up @@ -120,8 +117,8 @@ function buildLogOverviewQuery(logParams: LogParams, params: FetchDataParams) {
return {
range: {
[logParams.timestampField]: {
gt: params.absoluteTime.start,
lte: params.absoluteTime.end,
gt: new Date(params.absoluteTime.start).toISOString(),
lte: new Date(params.absoluteTime.end).toISOString(),
format: 'strict_date_optional_time',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { StyledStat } from '../../styled_stat';
import { onBrushEnd } from '../helper';

interface Props {
absoluteTime: { start?: string; end?: string };
absoluteTime: { start?: number; end?: number };
relativeTime: { start: string; end: string };
bucketSize?: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { StyledStat } from '../../styled_stat';
import { onBrushEnd } from '../helper';

interface Props {
absoluteTime: { start?: string; end?: string };
absoluteTime: { start?: number; end?: number };
relativeTime: { start: string; end: string };
bucketSize?: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ChartContainer } from '../../chart_container';
import { StyledStat } from '../../styled_stat';

interface Props {
absoluteTime: { start?: string; end?: string };
absoluteTime: { start?: number; end?: number };
relativeTime: { start: string; end: string };
bucketSize?: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { StyledStat } from '../../styled_stat';
import { onBrushEnd } from '../helper';

interface Props {
absoluteTime: { start?: string; end?: string };
absoluteTime: { start?: number; end?: number };
relativeTime: { start: string; end: string };
bucketSize?: string;
}
Expand Down
18 changes: 7 additions & 11 deletions x-pack/plugins/observability/public/pages/overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ interface Props {
routeParams: RouteParams<'/overview'>;
}

function calculatetBucketSize({ startTime, endTime }: { startTime?: string; endTime?: string }) {
if (startTime && endTime) {
return getBucketSize({
start: moment.utc(startTime).valueOf(),
end: moment.utc(endTime).valueOf(),
minInterval: '60s',
});
function calculatetBucketSize({ start, end }: { start?: number; end?: number }) {
if (start && end) {
return getBucketSize({ start, end, minInterval: '60s' });
}
}

Expand Down Expand Up @@ -66,13 +62,13 @@ export const OverviewPage = ({ routeParams }: Props) => {
};

const absoluteTime = {
start: getAbsoluteTime(relativeTime.start),
end: getAbsoluteTime(relativeTime.end, { roundUp: true }),
start: moment.utc(getAbsoluteTime(relativeTime.start)).valueOf(),
end: moment.utc(getAbsoluteTime(relativeTime.end, { roundUp: true })).valueOf(),
};

const bucketSize = calculatetBucketSize({
startTime: absoluteTime.start,
endTime: absoluteTime.end,
start: absoluteTime.start,
end: absoluteTime.end,
});

const appEmptySections = getEmptySections({ core }).filter(({ id }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface Series {
}

export interface FetchDataParams {
absoluteTime: { start: string; end: string };
absoluteTime: { start: number; end: number };
relativeTime: { start: string; end: string };
bucketSize: string;
}
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/uptime/public/apps/uptime_overview_fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export async function fetchUptimeOverviewData({
relativeTime,
bucketSize,
}: FetchDataParams) {
const { start, end } = absoluteTime;
const start = new Date(absoluteTime.start).toISOString();
const end = new Date(absoluteTime.end).toISOString();
const snapshot = await fetchSnapshotCount({
dateRangeStart: start,
dateRangeEnd: end,
Expand Down

0 comments on commit 7e5b9ae

Please sign in to comment.