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
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;
}