From 572d006d9fdc0c544e7188125f10e5d6113b8455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Marcondes?= <55978943+cauemarcondes@users.noreply.github.com> Date: Tue, 23 Jun 2020 14:08:17 +0100 Subject: [PATCH 1/4] [Observability]Adding specific Return APIs for each plugin (#69257) * Adding specific apis for each plugin * adding metric hosts stat * addressing PR comment * addressing PR comments * changing series to key/value * exporting interfaces * adding label to stat * refactoring types Co-authored-by: Elastic Machine --- .../observability/public/data_handler.ts | 23 ++++- .../public/typings/data_handler/index.d.ts | 42 --------- .../typings/fetch_data_response/index.d.ts | 86 +++++++++++++++++++ 3 files changed, 107 insertions(+), 44 deletions(-) delete mode 100644 x-pack/plugins/observability/public/typings/data_handler/index.d.ts create mode 100644 x-pack/plugins/observability/public/typings/fetch_data_response/index.d.ts diff --git a/x-pack/plugins/observability/public/data_handler.ts b/x-pack/plugins/observability/public/data_handler.ts index 30a7357404d23b..8f80f79b2e829a 100644 --- a/x-pack/plugins/observability/public/data_handler.ts +++ b/x-pack/plugins/observability/public/data_handler.ts @@ -4,9 +4,23 @@ * 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 = ( + fetchDataParams: FetchDataParams +) => Promise; +export type HasData = () => Promise; + interface DataHandler { fetchData: FetchData; hasData: HasData; @@ -14,7 +28,12 @@ interface DataHandler { const dataHandlers: Partial> = {}; -export type RegisterDataHandler = (params: { appName: ObservabilityApp } & DataHandler) => void; +export type RegisterDataHandler = (params: { + appName: T; + fetchData: FetchData; + hasData: HasData; +}) => void; + export const registerDataHandler: RegisterDataHandler = ({ appName, fetchData, hasData }) => { dataHandlers[appName] = { fetchData, hasData }; }; diff --git a/x-pack/plugins/observability/public/typings/data_handler/index.d.ts b/x-pack/plugins/observability/public/typings/data_handler/index.d.ts deleted file mode 100644 index a208e4e7c223d5..00000000000000 --- a/x-pack/plugins/observability/public/typings/data_handler/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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 Stat { - label: string; - value: string; - color?: string; -} - -export interface Coordinates { - x: number; - y?: number; -} - -interface Series { - label: string; - coordinates: Coordinates[]; - color?: string; - key?: string; -} - -interface FetchDataResponse { - title: string; - appLink: string; - stats: Stat[]; - series: Series[]; -} -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 = (fetchDataParams: FetchDataParams) => Promise; - -export type HasData = () => Promise; diff --git a/x-pack/plugins/observability/public/typings/fetch_data_response/index.d.ts b/x-pack/plugins/observability/public/typings/fetch_data_response/index.d.ts new file mode 100644 index 00000000000000..30ecb24a58a5a5 --- /dev/null +++ b/x-pack/plugins/observability/public/typings/fetch_data_response/index.d.ts @@ -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; + series: Record; +} + +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; +} From 43ed4e20432bd620ff94048c5ebe294afe75c19d Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Tue, 23 Jun 2020 15:55:58 +0200 Subject: [PATCH 2/4] [ML] fix ml api services (#69681) --- .../application/services/ml_api_service/index.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/ml/public/application/services/ml_api_service/index.ts b/x-pack/plugins/ml/public/application/services/ml_api_service/index.ts index 6d32fca6a645c1..af6944d7ae2d24 100644 --- a/x-pack/plugins/ml/public/application/services/ml_api_service/index.ts +++ b/x-pack/plugins/ml/public/application/services/ml_api_service/index.ts @@ -109,7 +109,6 @@ export type MlApiServices = ReturnType; 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}` : ''; @@ -142,14 +141,14 @@ export function mlApiServicesProvider(httpService: HttpService) { }, closeJob({ jobId }: { jobId: string }) { - return http({ + return httpService.http({ path: `${basePath()}/anomaly_detectors/${jobId}/_close`, method: 'POST', }); }, forceCloseJob({ jobId }: { jobId: string }) { - return http({ + return httpService.http({ path: `${basePath()}/anomaly_detectors/${jobId}/_close?force=true`, method: 'POST', }); @@ -278,14 +277,14 @@ export function mlApiServicesProvider(httpService: HttpService) { }, stopDatafeed({ datafeedId }: { datafeedId: string }) { - return http({ + return httpService.http({ path: `${basePath()}/datafeeds/${datafeedId}/_stop`, method: 'POST', }); }, forceStopDatafeed({ datafeedId }: { datafeedId: string }) { - return http({ + return httpService.http({ path: `${basePath()}/datafeeds/${datafeedId}/_stop?force=true`, method: 'POST', }); @@ -697,7 +696,7 @@ export function mlApiServicesProvider(httpService: HttpService) { }, getModelSnapshots(jobId: string, snapshotId?: string) { - return http({ + return httpService.http({ path: `${basePath()}/anomaly_detectors/${jobId}/model_snapshots${ snapshotId !== undefined ? `/${snapshotId}` : '' }`, @@ -709,7 +708,7 @@ export function mlApiServicesProvider(httpService: HttpService) { snapshotId: string, body: { description?: string; retain?: boolean } ) { - return http({ + return httpService.http({ path: `${basePath()}/anomaly_detectors/${jobId}/model_snapshots/${snapshotId}/_update`, method: 'POST', body: JSON.stringify(body), @@ -717,7 +716,7 @@ export function mlApiServicesProvider(httpService: HttpService) { }, deleteModelSnapshot(jobId: string, snapshotId: string) { - return http({ + return httpService.http({ path: `${basePath()}/anomaly_detectors/${jobId}/model_snapshots/${snapshotId}`, method: 'DELETE', }); From cc893f3da4ad92c6ec10cfc96d5a2ad362789775 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Tue, 23 Jun 2020 16:02:22 +0200 Subject: [PATCH 3/4] [Discover] Unskip context navigation functional test (#68771) --- .../apps/context/_context_navigation.js | 43 ++++++++----------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/test/functional/apps/context/_context_navigation.js b/test/functional/apps/context/_context_navigation.js index 92b109c7263ff5..babefe488d7bcf 100644 --- a/test/functional/apps/context/_context_navigation.js +++ b/test/functional/apps/context/_context_navigation.js @@ -17,12 +17,8 @@ * 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', @@ -30,20 +26,15 @@ const TEST_FILTER_COLUMN_NAMES = [ ]; 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); @@ -51,18 +42,22 @@ export default function ({ getService, getPageObjects }) { }); 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; + }); }); }); } From 8956a33e4c6abcbff31b6d178aaeadce38b6b513 Mon Sep 17 00:00:00 2001 From: Dario Gieselaar Date: Tue, 23 Jun 2020 16:34:50 +0200 Subject: [PATCH 4/4] [APM] Use asPercent to format breakdown chart (#69384) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Søren Louv-Jansen Co-authored-by: Elastic Machine --- .../TransactionBreakdownGraph/index.tsx | 3 +-- .../TransactionBreakdownKpiList.tsx | 6 ++---- .../utils/formatters/__test__/formatters.test.ts | 10 +++++++--- .../plugins/apm/public/utils/formatters/formatters.ts | 8 ++++++++ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownGraph/index.tsx b/x-pack/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownGraph/index.tsx index 0afed6c3c1fa8c..2cb3696f880027 100644 --- a/x-pack/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownGraph/index.tsx +++ b/x-pack/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownGraph/index.tsx @@ -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'; @@ -21,7 +20,7 @@ interface Props { } const tickFormatY = (y: Maybe) => { - return numeral(y || 0).format('0 %'); + return asPercent(y ?? 0, 1); }; const formatTooltipValue = (coordinate: Coordinate) => { diff --git a/x-pack/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownKpiList.tsx b/x-pack/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownKpiList.tsx index eda8f19c949a3d..3898679f835371 100644 --- a/x-pack/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownKpiList.tsx +++ b/x-pack/plugins/apm/public/components/shared/TransactionBreakdown/TransactionBreakdownKpiList.tsx @@ -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; @@ -65,9 +65,7 @@ const TransactionBreakdownKpiList: React.FC = ({ kpis }) => { - - {FORMATTERS[InfraFormatterType.percent](kpi.percentage)} - + {asPercent(kpi.percentage, 1)} diff --git a/x-pack/plugins/apm/public/utils/formatters/__test__/formatters.test.ts b/x-pack/plugins/apm/public/utils/formatters/__test__/formatters.test.ts index f6ed88a850a5b2..66101baf3a7461 100644 --- a/x-pack/plugins/apm/public/utils/formatters/__test__/formatters.test.ts +++ b/x-pack/plugins/apm/public/utils/formatters/__test__/formatters.test.ts @@ -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', () => { diff --git a/x-pack/plugins/apm/public/utils/formatters/formatters.ts b/x-pack/plugins/apm/public/utils/formatters/formatters.ts index 9fdac85c7154ff..649f11063b149a 100644 --- a/x-pack/plugins/apm/public/utils/formatters/formatters.ts +++ b/x-pack/plugins/apm/public/utils/formatters/formatters.ts @@ -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%'); }