Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into add-endpoint-…
Browse files Browse the repository at this point in the history
…alerts-url
  • Loading branch information
XavierM committed Jun 23, 2020
2 parents fa2c7f8 + 8956a33 commit a914816
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 85 deletions.
43 changes: 19 additions & 24 deletions test/functional/apps/context/_context_navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,47 @@
* under the License.
*/

import expect from '@kbn/expect';

const TEST_COLUMN_NAMES = ['@message'];
const TEST_FILTER_COLUMN_NAMES = [
['extension', 'jpg'],
['geo.src', 'IN'],
[
'agent',
'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.50 Safari/534.24',
],
];

export default function ({ getService, getPageObjects }) {
const retry = getService('retry');
const browser = getService('browser');
const docTable = getService('docTable');
const PageObjects = getPageObjects(['common', 'context', 'discover', 'timePicker']);

// FLAKY: https://github.com/elastic/kibana/issues/62866
describe.skip('context link in discover', function contextSize() {
describe('discover - context - back navigation', function contextSize() {
before(async function () {
await PageObjects.timePicker.setDefaultAbsoluteRangeViaUiSettings();
await PageObjects.common.navigateToApp('discover');
await PageObjects.timePicker.setDefaultAbsoluteRange();
await Promise.all(
TEST_COLUMN_NAMES.map((columnName) =>
PageObjects.discover.clickFieldListItemAdd(columnName)
)
);
for (const [columnName, value] of TEST_FILTER_COLUMN_NAMES) {
await PageObjects.discover.clickFieldListItem(columnName);
await PageObjects.discover.clickFieldListPlusFilter(columnName, value);
}
});

it('should go back after loading', async function () {
// navigate to the context view
await docTable.clickRowToggle({ rowIndex: 0 });
await (await docTable.getRowActions({ rowIndex: 0 }))[0].click();
await PageObjects.context.waitUntilContextLoadingHasFinished();
await PageObjects.context.clickSuccessorLoadMoreButton();
await PageObjects.context.clickSuccessorLoadMoreButton();
await PageObjects.context.clickSuccessorLoadMoreButton();
await PageObjects.context.waitUntilContextLoadingHasFinished();
await browser.goBack();
await PageObjects.discover.waitForDocTableLoadingComplete();
const hitCount = await PageObjects.discover.getHitCount();
expect(hitCount).to.be('522');
await retry.waitFor('user navigating to context and returning to discover', async () => {
// navigate to the context view
const initialHitCount = await PageObjects.discover.getHitCount();
await docTable.clickRowToggle({ rowIndex: 0 });
const rowActions = await docTable.getRowActions({ rowIndex: 0 });
await rowActions[0].click();
await PageObjects.context.waitUntilContextLoadingHasFinished();
await PageObjects.context.clickSuccessorLoadMoreButton();
await PageObjects.context.clickSuccessorLoadMoreButton();
await PageObjects.context.clickSuccessorLoadMoreButton();
await PageObjects.context.waitUntilContextLoadingHasFinished();
await browser.goBack();
await PageObjects.discover.waitForDocTableLoadingComplete();
const hitCount = await PageObjects.discover.getHitCount();
return initialHitCount === hitCount;
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import React, { useMemo } from 'react';
import numeral from '@elastic/numeral';
import { throttle } from 'lodash';
import { NOT_AVAILABLE_LABEL } from '../../../../../common/i18n';
import { Coordinate, TimeSeries } from '../../../../../typings/timeseries';
Expand All @@ -21,7 +20,7 @@ interface Props {
}

const tickFormatY = (y: Maybe<number>) => {
return numeral(y || 0).format('0 %');
return asPercent(y ?? 0, 1);
};

const formatTooltipValue = (coordinate: Coordinate) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
EuiIcon,
} from '@elastic/eui';
import styled from 'styled-components';
import { FORMATTERS, InfraFormatterType } from '../../../../../infra/public';
import { asPercent } from '../../../utils/formatters';

interface TransactionBreakdownKpi {
name: string;
Expand Down Expand Up @@ -65,9 +65,7 @@ const TransactionBreakdownKpiList: React.FC<Props> = ({ kpis }) => {
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiTitle size="s">
<span>
{FORMATTERS[InfraFormatterType.percent](kpi.percentage)}
</span>
<span>{asPercent(kpi.percentage, 1)}</span>
</EuiTitle>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import { asPercent } from '../formatters';

describe('formatters', () => {
describe('asPercent', () => {
it('should divide and format item as percent', () => {
expect(asPercent(3725, 10000, 'n/a')).toEqual('37.3%');
it('should format as integer when number is above 10', () => {
expect(asPercent(3725, 10000, 'n/a')).toEqual('37%');
});

it('should add a decimal when value is below 10', () => {
expect(asPercent(0.092, 1)).toEqual('9.2%');
});

it('should format when numerator is 0', () => {
expect(asPercent(0, 1, 'n/a')).toEqual('0.0%');
expect(asPercent(0, 1, 'n/a')).toEqual('0%');
});

it('should return fallback when denominator is undefined', () => {
Expand Down
8 changes: 8 additions & 0 deletions x-pack/plugins/apm/public/utils/formatters/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,13 @@ export function asPercent(
}

const decimal = numerator / denominator;

// 33.2 => 33%
// 3.32 => 3.3%
// 0 => 0%
if (Math.abs(decimal) >= 0.1 || decimal === 0) {
return numeral(decimal).format('0%');
}

return numeral(decimal).format('0.0%');
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export type MlApiServices = ReturnType<typeof mlApiServicesProvider>;
export const ml = mlApiServicesProvider(new HttpService(proxyHttpStart));

export function mlApiServicesProvider(httpService: HttpService) {
const { http } = httpService;
return {
getJobs(obj?: { jobId?: string }) {
const jobId = obj && obj.jobId ? `/${obj.jobId}` : '';
Expand Down Expand Up @@ -142,14 +141,14 @@ export function mlApiServicesProvider(httpService: HttpService) {
},

closeJob({ jobId }: { jobId: string }) {
return http<any>({
return httpService.http<any>({
path: `${basePath()}/anomaly_detectors/${jobId}/_close`,
method: 'POST',
});
},

forceCloseJob({ jobId }: { jobId: string }) {
return http<any>({
return httpService.http<any>({
path: `${basePath()}/anomaly_detectors/${jobId}/_close?force=true`,
method: 'POST',
});
Expand Down Expand Up @@ -278,14 +277,14 @@ export function mlApiServicesProvider(httpService: HttpService) {
},

stopDatafeed({ datafeedId }: { datafeedId: string }) {
return http<any>({
return httpService.http<any>({
path: `${basePath()}/datafeeds/${datafeedId}/_stop`,
method: 'POST',
});
},

forceStopDatafeed({ datafeedId }: { datafeedId: string }) {
return http<any>({
return httpService.http<any>({
path: `${basePath()}/datafeeds/${datafeedId}/_stop?force=true`,
method: 'POST',
});
Expand Down Expand Up @@ -697,7 +696,7 @@ export function mlApiServicesProvider(httpService: HttpService) {
},

getModelSnapshots(jobId: string, snapshotId?: string) {
return http<GetModelSnapshotsResponse>({
return httpService.http<GetModelSnapshotsResponse>({
path: `${basePath()}/anomaly_detectors/${jobId}/model_snapshots${
snapshotId !== undefined ? `/${snapshotId}` : ''
}`,
Expand All @@ -709,15 +708,15 @@ export function mlApiServicesProvider(httpService: HttpService) {
snapshotId: string,
body: { description?: string; retain?: boolean }
) {
return http<any>({
return httpService.http<any>({
path: `${basePath()}/anomaly_detectors/${jobId}/model_snapshots/${snapshotId}/_update`,
method: 'POST',
body: JSON.stringify(body),
});
},

deleteModelSnapshot(jobId: string, snapshotId: string) {
return http<any>({
return httpService.http<any>({
path: `${basePath()}/anomaly_detectors/${jobId}/model_snapshots/${snapshotId}`,
method: 'DELETE',
});
Expand Down
23 changes: 21 additions & 2 deletions x-pack/plugins/observability/public/data_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,36 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { FetchData, HasData } from './typings/data_handler';
import { ObservabilityFetchDataResponse, FetchDataResponse } from './typings/fetch_data_response';
import { ObservabilityApp } from '../typings/common';

interface FetchDataParams {
// The start timestamp in milliseconds of the queried time interval
startTime: string;
// The end timestamp in milliseconds of the queried time interval
endTime: string;
// The aggregation bucket size in milliseconds if applicable to the data source
bucketSize: string;
}

export type FetchData<T extends FetchDataResponse = FetchDataResponse> = (
fetchDataParams: FetchDataParams
) => Promise<T>;
export type HasData = () => Promise<boolean>;

interface DataHandler {
fetchData: FetchData;
hasData: HasData;
}

const dataHandlers: Partial<Record<ObservabilityApp, DataHandler>> = {};

export type RegisterDataHandler = (params: { appName: ObservabilityApp } & DataHandler) => void;
export type RegisterDataHandler<T extends ObservabilityApp = ObservabilityApp> = (params: {
appName: T;
fetchData: FetchData<ObservabilityFetchDataResponse[T]>;
hasData: HasData;
}) => void;

export const registerDataHandler: RegisterDataHandler = ({ appName, fetchData, hasData }) => {
dataHandlers[appName] = { fetchData, hasData };
};
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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.
*/

interface Percentage {
label: string;
pct: number;
color?: string;
}
interface Bytes {
label: string;
bytes: number;
color?: string;
}
interface Numeral {
label: string;
value: number;
color?: string;
}

export interface Coordinates {
x: number;
y?: number;
}

interface Series {
label: string;
coordinates: Coordinates[];
color?: string;
}

export interface FetchDataResponse {
title: string;
appLink: string;
}

export interface LogsFetchDataResponse extends FetchDataResponse {
stats: Record<string, Numeral>;
series: Record<string, Series>;
}

export interface MetricsFetchDataResponse extends FetchDataResponse {
stats: {
hosts: Numeral;
cpu: Percentage;
memory: Percentage;
disk: Percentage;
inboundTraffic: Bytes;
outboundTraffic: Bytes;
};
series: {
inboundTraffic: Series;
outboundTraffic: Series;
};
}

export interface UptimeFetchDataResponse extends FetchDataResponse {
stats: {
monitors: Numeral;
up: Numeral;
down: Numeral;
};
series: {
up: Series;
down: Series;
};
}

export interface ApmFetchDataResponse extends FetchDataResponse {
stats: {
services: Numeral;
transactions: Numeral;
};
series: {
transactions: Series;
};
}

export interface ObservabilityFetchDataResponse {
apm: ApmFetchDataResponse;
infra_metrics: MetricsFetchDataResponse;
infra_logs: LogsFetchDataResponse;
uptime: UptimeFetchDataResponse;
}

0 comments on commit a914816

Please sign in to comment.