Skip to content

Commit

Permalink
[Observability]Adding specific Return APIs for each plugin (elastic#6…
Browse files Browse the repository at this point in the history
…9257)

* 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 <[email protected]>
  • Loading branch information
2 people authored and lukeelmers committed Jun 23, 2020
1 parent f38404f commit 654974c
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 44 deletions.
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;
}

0 comments on commit 654974c

Please sign in to comment.