Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Observability]Adding specific Return APIs for each plugin #69257

Merged
merged 10 commits into from
Jun 23, 2020
9 changes: 7 additions & 2 deletions x-pack/plugins/observability/public/data_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -14,7 +14,12 @@ interface DataHandler {

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
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
* you may not use this file except in compliance with the Elastic License.
*/

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

Expand All @@ -25,9 +32,47 @@ interface Series {
interface FetchDataResponse {
title: string;
appLink: string;
stats: Stat[];
series: Series[];
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
}

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

interface MetricsFetchDataResponse extends FetchDataResponse {
stats: {
hots: Numeral;
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
cpu: Percentage;
memory: Percentage;
disk: Percentage;
inboundTraffic: Bytes;
outboundTraffic: Bytes;
};
}

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

interface ApmFetchDataResponse extends FetchDataResponse {
stats: {
services: Numeral;
transactions: Numeral;
errorRate?: Percentage;
};
}

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;
Expand All @@ -37,6 +82,7 @@ interface FetchDataParams {
bucketSize: string;
}

export type FetchData = (fetchDataParams: FetchDataParams) => Promise<FetchDataResponse>;

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