From c307c8ecaf61f44729c1fa65da34a6efa346ae2f Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Tue, 16 Jun 2020 14:08:29 +0200 Subject: [PATCH 1/8] Adding specific apis for each plugin --- .../observability/public/data_handler.ts | 9 ++- .../public/typings/data_handler/index.d.ts | 62 ++++++++++++++++--- 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/observability/public/data_handler.ts b/x-pack/plugins/observability/public/data_handler.ts index 30a7357404d23..382812903fd8e 100644 --- a/x-pack/plugins/observability/public/data_handler.ts +++ b/x-pack/plugins/observability/public/data_handler.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { FetchData, HasData } from './typings/data_handler'; +import { FetchData, HasData, ObservabilityFetchDataResponse } from './typings/data_handler'; import { ObservabilityApp } from '../typings/common'; interface DataHandler { @@ -14,7 +14,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 index a208e4e7c223d..014ff27ca4ba8 100644 --- a/x-pack/plugins/observability/public/typings/data_handler/index.d.ts +++ b/x-pack/plugins/observability/public/typings/data_handler/index.d.ts @@ -4,9 +4,17 @@ * you may not use this file except in compliance with the Elastic License. */ -interface Stat { - label: string; - value: string; +interface Percentage { + pct: number; +} +interface Bytes { + bytes: number; +} +interface Numeral { + numeral: number; +} + +interface Color { color?: string; } @@ -25,9 +33,48 @@ interface Series { interface FetchDataResponse { title: string; appLink: string; - stats: Stat[]; series: Series[]; } + +interface LogsFetchDataResponse extends FetchDataResponse { + stats: { + [logName: string]: Numeral; + }; +} + +interface MetricsFetchDataResponse extends FetchDataResponse { + stats: { + cpu: Percentage & Color; + memory: Percentage & Color; + disk: Percentage & Color; + inboundTraffic: Bytes & Color; + outboundTraffic: Bytes & Color; + }; +} + +interface UptimeFetchDataResponse extends FetchDataResponse { + stats: { + monitors: Numeral & Color; + up: Numeral & Color; + down: Numeral & Color; + }; +} + +interface ApmFetchDataResponse extends FetchDataResponse { + stats: { + services: Numeral & Color; + transactions: Numeral & Color; + errorRate?: Percentage & Color; + }; +} + +export interface ObservabilityFetchDataResponse { + apm: ApmFetchDataResponse; + infra_metrics: MetricsFetchDataResponse; + infra_logs: LogsFetchDataResponse; + uptime: UptimeFetchDataResponse; +} + interface FetchDataParams { // The start timestamp in milliseconds of the queried time interval startTime: string; @@ -37,6 +84,7 @@ interface FetchDataParams { bucketSize: string; } -export type FetchData = (fetchDataParams: FetchDataParams) => Promise; - -export type HasData = () => Promise; +type FetchData = ( + fetchDataParams: FetchDataParams +) => Promise; +type HasData = () => Promise; From 3b27f63c142a009d98556d9c8a7c5834c22fb3c6 Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Tue, 16 Jun 2020 17:50:57 +0200 Subject: [PATCH 2/8] adding metric hosts stat --- .../plugins/observability/public/typings/data_handler/index.d.ts | 1 + 1 file changed, 1 insertion(+) 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 index 014ff27ca4ba8..ab2e3977ea56c 100644 --- a/x-pack/plugins/observability/public/typings/data_handler/index.d.ts +++ b/x-pack/plugins/observability/public/typings/data_handler/index.d.ts @@ -44,6 +44,7 @@ interface LogsFetchDataResponse extends FetchDataResponse { interface MetricsFetchDataResponse extends FetchDataResponse { stats: { + hots: Numeral & Color; cpu: Percentage & Color; memory: Percentage & Color; disk: Percentage & Color; From ebb663ec044030643e9f8653470edc8328a84ac8 Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Wed, 17 Jun 2020 09:10:29 +0200 Subject: [PATCH 3/8] addressing PR comment --- .../observability/public/typings/data_handler/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index ab2e3977ea56c..7fb544657eb6c 100644 --- a/x-pack/plugins/observability/public/typings/data_handler/index.d.ts +++ b/x-pack/plugins/observability/public/typings/data_handler/index.d.ts @@ -85,7 +85,7 @@ interface FetchDataParams { bucketSize: string; } -type FetchData = ( +export type FetchData = ( fetchDataParams: FetchDataParams ) => Promise; type HasData = () => Promise; From abc6ffddb18695677ac5db781bfeb9f0bfd31aad Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Thu, 18 Jun 2020 09:01:24 +0200 Subject: [PATCH 4/8] addressing PR comments --- .../public/typings/data_handler/index.d.ts | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) 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 index 7fb544657eb6c..4de987408f978 100644 --- a/x-pack/plugins/observability/public/typings/data_handler/index.d.ts +++ b/x-pack/plugins/observability/public/typings/data_handler/index.d.ts @@ -6,15 +6,14 @@ interface Percentage { pct: number; + color?: string; } interface Bytes { bytes: number; + color?: string; } interface Numeral { - numeral: number; -} - -interface Color { + value: number; color?: string; } @@ -37,35 +36,33 @@ interface FetchDataResponse { } interface LogsFetchDataResponse extends FetchDataResponse { - stats: { - [logName: string]: Numeral; - }; + stats: Record; } interface MetricsFetchDataResponse extends FetchDataResponse { stats: { - hots: Numeral & Color; - cpu: Percentage & Color; - memory: Percentage & Color; - disk: Percentage & Color; - inboundTraffic: Bytes & Color; - outboundTraffic: Bytes & Color; + hots: Numeral; + cpu: Percentage; + memory: Percentage; + disk: Percentage; + inboundTraffic: Bytes; + outboundTraffic: Bytes; }; } interface UptimeFetchDataResponse extends FetchDataResponse { stats: { - monitors: Numeral & Color; - up: Numeral & Color; - down: Numeral & Color; + monitors: Numeral; + up: Numeral; + down: Numeral; }; } interface ApmFetchDataResponse extends FetchDataResponse { stats: { - services: Numeral & Color; - transactions: Numeral & Color; - errorRate?: Percentage & Color; + services: Numeral; + transactions: Numeral; + errorRate?: Percentage; }; } From 738aed0fc93a33e18f0e9e46b9c29cc0d10d97e5 Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Tue, 23 Jun 2020 09:30:06 +0200 Subject: [PATCH 5/8] changing series to key/value --- .../public/typings/data_handler/index.d.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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 index 4de987408f978..7b9aa07386544 100644 --- a/x-pack/plugins/observability/public/typings/data_handler/index.d.ts +++ b/x-pack/plugins/observability/public/typings/data_handler/index.d.ts @@ -26,28 +26,31 @@ interface Series { label: string; coordinates: Coordinates[]; color?: string; - key?: string; } interface FetchDataResponse { title: string; appLink: string; - series: Series[]; } interface LogsFetchDataResponse extends FetchDataResponse { stats: Record; + series: Record; } interface MetricsFetchDataResponse extends FetchDataResponse { stats: { - hots: Numeral; + hosts: Numeral; cpu: Percentage; memory: Percentage; disk: Percentage; inboundTraffic: Bytes; outboundTraffic: Bytes; }; + series: { + inboundTraffic: Series; + outboundTraffic: Series; + }; } interface UptimeFetchDataResponse extends FetchDataResponse { @@ -56,13 +59,19 @@ interface UptimeFetchDataResponse extends FetchDataResponse { up: Numeral; down: Numeral; }; + series: { + up: Series; + down: Series; + }; } interface ApmFetchDataResponse extends FetchDataResponse { stats: { services: Numeral; transactions: Numeral; - errorRate?: Percentage; + }; + series: { + transactions: Series; }; } From 5373f97681c74ef39349d9353ef0e3f3f61b4f8b Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Tue, 23 Jun 2020 10:25:52 +0200 Subject: [PATCH 6/8] exporting interfaces --- .../observability/public/typings/data_handler/index.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 index 7b9aa07386544..3faea6b673562 100644 --- a/x-pack/plugins/observability/public/typings/data_handler/index.d.ts +++ b/x-pack/plugins/observability/public/typings/data_handler/index.d.ts @@ -33,12 +33,12 @@ interface FetchDataResponse { appLink: string; } -interface LogsFetchDataResponse extends FetchDataResponse { +export interface LogsFetchDataResponse extends FetchDataResponse { stats: Record; series: Record; } -interface MetricsFetchDataResponse extends FetchDataResponse { +export interface MetricsFetchDataResponse extends FetchDataResponse { stats: { hosts: Numeral; cpu: Percentage; @@ -53,7 +53,7 @@ interface MetricsFetchDataResponse extends FetchDataResponse { }; } -interface UptimeFetchDataResponse extends FetchDataResponse { +export interface UptimeFetchDataResponse extends FetchDataResponse { stats: { monitors: Numeral; up: Numeral; @@ -65,7 +65,7 @@ interface UptimeFetchDataResponse extends FetchDataResponse { }; } -interface ApmFetchDataResponse extends FetchDataResponse { +export interface ApmFetchDataResponse extends FetchDataResponse { stats: { services: Numeral; transactions: Numeral; From d9e63c5389f5a6fd4e49911061cba404df66510e Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Tue, 23 Jun 2020 11:23:48 +0200 Subject: [PATCH 7/8] adding label to stat --- .../observability/public/typings/data_handler/index.d.ts | 3 +++ 1 file changed, 3 insertions(+) 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 index 3faea6b673562..b4e85ed21eefa 100644 --- a/x-pack/plugins/observability/public/typings/data_handler/index.d.ts +++ b/x-pack/plugins/observability/public/typings/data_handler/index.d.ts @@ -5,14 +5,17 @@ */ interface Percentage { + label: string; pct: number; color?: string; } interface Bytes { + label: string; bytes: number; color?: string; } interface Numeral { + label: string; value: number; color?: string; } From e04f6f4e2d297e3418470b31ce4cb11443306661 Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Tue, 23 Jun 2020 13:24:07 +0200 Subject: [PATCH 8/8] refactoring types --- .../plugins/observability/public/data_handler.ts | 16 +++++++++++++++- .../index.d.ts | 16 +--------------- 2 files changed, 16 insertions(+), 16 deletions(-) rename x-pack/plugins/observability/public/typings/{data_handler => fetch_data_response}/index.d.ts (76%) diff --git a/x-pack/plugins/observability/public/data_handler.ts b/x-pack/plugins/observability/public/data_handler.ts index 382812903fd8e..8f80f79b2e829 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, ObservabilityFetchDataResponse } 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; diff --git a/x-pack/plugins/observability/public/typings/data_handler/index.d.ts b/x-pack/plugins/observability/public/typings/fetch_data_response/index.d.ts similarity index 76% rename from x-pack/plugins/observability/public/typings/data_handler/index.d.ts rename to x-pack/plugins/observability/public/typings/fetch_data_response/index.d.ts index b4e85ed21eefa..30ecb24a58a5a 100644 --- a/x-pack/plugins/observability/public/typings/data_handler/index.d.ts +++ b/x-pack/plugins/observability/public/typings/fetch_data_response/index.d.ts @@ -31,7 +31,7 @@ interface Series { color?: string; } -interface FetchDataResponse { +export interface FetchDataResponse { title: string; appLink: string; } @@ -84,17 +84,3 @@ export interface ObservabilityFetchDataResponse { infra_logs: LogsFetchDataResponse; uptime: UptimeFetchDataResponse; } - -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; -type HasData = () => Promise;