[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 <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
6cc8ea1861
commit
572d006d9f
|
@ -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<T extends FetchDataResponse = FetchDataResponse> = (
|
||||
fetchDataParams: FetchDataParams
|
||||
) => Promise<T>;
|
||||
export type HasData = () => Promise<boolean>;
|
||||
|
||||
interface DataHandler {
|
||||
fetchData: FetchData;
|
||||
hasData: HasData;
|
||||
|
@ -14,7 +28,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 };
|
||||
};
|
||||
|
|
|
@ -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<FetchDataResponse>;
|
||||
|
||||
export type HasData = () => Promise<boolean>;
|
86
x-pack/plugins/observability/public/typings/fetch_data_response/index.d.ts
vendored
Normal file
86
x-pack/plugins/observability/public/typings/fetch_data_response/index.d.ts
vendored
Normal file
|
@ -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;
|
||||
}
|
Loading…
Reference in a new issue