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

[Metrics UI] Remove TSVB dependency from Metrics Explorer APIs #74804

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions x-pack/plugins/infra/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
*/

export const DEFAULT_SOURCE_ID = 'default';
export const METRICS_INDEX_PATTERN = 'metrics-*,metricbeat-*';
export const LOGS_INDEX_PATTERN = 'logs-*,filebeat-*,kibana_sample_data_logs*';
export const TIMESTAMP_FIELD = '@timestamp';
1 change: 1 addition & 0 deletions x-pack/plugins/infra/common/http_api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './log_analysis';
export * from './metadata_api';
export * from './log_entries';
export * from './metrics_explorer';
export * from './metrics_api';
97 changes: 97 additions & 0 deletions x-pack/plugins/infra/common/http_api/metrics_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* 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.
*/

import * as rt from 'io-ts';
import { MetricsUIAggregationRT } from '../inventory_models/types';
import { afterKeyObjectRT } from './metrics_explorer';

export const MetricsAPITimerangeRT = rt.type({
field: rt.string,
from: rt.number,
to: rt.number,
interval: rt.string,
});

const groupByRT = rt.union([rt.string, rt.null, rt.undefined]);

export const MetricsAPIMetricRT = rt.type({
id: rt.string,
aggregations: MetricsUIAggregationRT,
});

export const MetricsAPIRequestRT = rt.intersection([
rt.type({
timerange: MetricsAPITimerangeRT,
indexPattern: rt.string,
metrics: rt.array(MetricsAPIMetricRT),
}),
rt.partial({
groupBy: rt.array(groupByRT),
afterKey: rt.union([rt.null, afterKeyObjectRT]),
limit: rt.union([rt.number, rt.null, rt.undefined]),
filters: rt.array(rt.object),
forceInterval: rt.boolean,
dropLastBucket: rt.boolean,
alignDataToEnd: rt.boolean,
}),
]);

export const MetricsAPIPageInfoRT = rt.type({
afterKey: rt.union([rt.null, afterKeyObjectRT, rt.undefined]),
interval: rt.number,
});

export const MetricsAPIColumnTypeRT = rt.keyof({
date: null,
number: null,
string: null,
});

export const MetricsAPIColumnRT = rt.type({
name: rt.string,
type: MetricsAPIColumnTypeRT,
});

export const MetricsAPIRowRT = rt.intersection([
rt.type({
timestamp: rt.number,
}),
rt.record(rt.string, rt.union([rt.string, rt.number, rt.null, rt.undefined])),
]);

export const MetricsAPISeriesRT = rt.intersection([
rt.type({
id: rt.string,
columns: rt.array(MetricsAPIColumnRT),
rows: rt.array(MetricsAPIRowRT),
}),
rt.partial({
keys: rt.array(rt.string),
}),
]);

export const MetricsAPIResponseRT = rt.type({
series: rt.array(MetricsAPISeriesRT),
info: MetricsAPIPageInfoRT,
});

export type MetricsAPITimerange = rt.TypeOf<typeof MetricsAPITimerangeRT>;

export type MetricsAPIColumnType = rt.TypeOf<typeof MetricsAPIColumnTypeRT>;

export type MetricsAPIMetric = rt.TypeOf<typeof MetricsAPIMetricRT>;

export type MetricsAPIPageInfo = rt.TypeOf<typeof MetricsAPIPageInfoRT>;

export type MetricsAPIColumn = rt.TypeOf<typeof MetricsAPIColumnRT>;

export type MetricsAPIRow = rt.TypeOf<typeof MetricsAPIRowRT>;

export type MetricsAPISeries = rt.TypeOf<typeof MetricsAPISeriesRT>;

export type MetricsAPIRequest = rt.TypeOf<typeof MetricsAPIRequestRT>;

export type MetricsAPIResponse = rt.TypeOf<typeof MetricsAPIResponseRT>;
2 changes: 2 additions & 0 deletions x-pack/plugins/infra/common/http_api/metrics_explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export const metricsExplorerResponseRT = rt.type({
pageInfo: metricsExplorerPageInfoRT,
});

export type AfterKey = rt.TypeOf<typeof afterKeyObjectRT>;

export type MetricsExplorerAggregation = rt.TypeOf<typeof metricsExplorerAggregationRT>;

export type MetricsExplorerColumnType = rt.TypeOf<typeof metricsExplorerColumnTypeRT>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const cpu: SnapshotModel = {
export const cpu: MetricsUIAggregation = {
cpu_avg: {
avg: {
field: 'aws.ec2.cpu.total.pct',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const diskIOReadBytes: SnapshotModel = {
export const diskIOReadBytes: MetricsUIAggregation = {
diskIOReadBytes: {
avg: {
field: 'aws.ec2.diskio.read.bytes_per_sec',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const diskIOWriteBytes: SnapshotModel = {
export const diskIOWriteBytes: MetricsUIAggregation = {
diskIOWriteBytes: {
avg: {
field: 'aws.ec2.diskio.write.bytes_per_sec',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const rx: SnapshotModel = {
export const rx: MetricsUIAggregation = {
rx: {
avg: {
field: 'aws.ec2.network.in.bytes_per_sec',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const tx: SnapshotModel = {
export const tx: MetricsUIAggregation = {
tx: {
avg: {
field: 'aws.ec2.network.in.bytes_per_sec',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const cpu: SnapshotModel = {
export const cpu: MetricsUIAggregation = {
cpu_avg: {
avg: {
field: 'aws.rds.cpu.total.pct',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const rdsActiveTransactions: SnapshotModel = {
export const rdsActiveTransactions: MetricsUIAggregation = {
rdsActiveTransactions: {
avg: {
field: 'aws.rds.transactions.active',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const rdsConnections: SnapshotModel = {
export const rdsConnections: MetricsUIAggregation = {
rdsConnections: {
avg: {
field: 'aws.rds.database_connections',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const rdsLatency: SnapshotModel = {
export const rdsLatency: MetricsUIAggregation = {
rdsLatency: {
avg: {
field: 'aws.rds.latency.dml',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const rdsQueriesExecuted: SnapshotModel = {
export const rdsQueriesExecuted: MetricsUIAggregation = {
rdsQueriesExecuted: {
avg: {
field: 'aws.rds.queries',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const s3BucketSize: SnapshotModel = {
export const s3BucketSize: MetricsUIAggregation = {
s3BucketSize: {
max: {
field: 'aws.s3_daily_storage.bucket.size.bytes',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const s3DownloadBytes: SnapshotModel = {
export const s3DownloadBytes: MetricsUIAggregation = {
s3DownloadBytes: {
max: {
field: 'aws.s3_request.downloaded.bytes',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const s3NumberOfObjects: SnapshotModel = {
export const s3NumberOfObjects: MetricsUIAggregation = {
s3NumberOfObjects: {
max: {
field: 'aws.s3_daily_storage.number_of_objects',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const s3TotalRequests: SnapshotModel = {
export const s3TotalRequests: MetricsUIAggregation = {
s3TotalRequests: {
max: {
field: 'aws.s3_request.requests.total',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const s3UploadBytes: SnapshotModel = {
export const s3UploadBytes: MetricsUIAggregation = {
s3UploadBytes: {
max: {
field: 'aws.s3_request.uploaded.bytes',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const sqsMessagesDelayed: SnapshotModel = {
export const sqsMessagesDelayed: MetricsUIAggregation = {
sqsMessagesDelayed: {
max: {
field: 'aws.sqs.messages.delayed',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const sqsMessagesEmpty: SnapshotModel = {
export const sqsMessagesEmpty: MetricsUIAggregation = {
sqsMessagesEmpty: {
max: {
field: 'aws.sqs.messages.not_visible',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const sqsMessagesSent: SnapshotModel = {
export const sqsMessagesSent: MetricsUIAggregation = {
sqsMessagesSent: {
max: {
field: 'aws.sqs.messages.sent',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const sqsMessagesVisible: SnapshotModel = {
export const sqsMessagesVisible: MetricsUIAggregation = {
sqsMessagesVisible: {
avg: {
field: 'aws.sqs.messages.visible',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const sqsOldestMessage: SnapshotModel = {
export const sqsOldestMessage: MetricsUIAggregation = {
sqsOldestMessage: {
max: {
field: 'aws.sqs.oldest_message_age.sec',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const cpu: SnapshotModel = {
export const cpu: MetricsUIAggregation = {
cpu: {
avg: {
field: 'docker.cpu.total.pct',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const memory: SnapshotModel = { memory: { avg: { field: 'docker.memory.usage.pct' } } };
export const memory: MetricsUIAggregation = {
memory: { avg: { field: 'docker.memory.usage.pct' } },
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SnapshotModel } from '../../../types';
import { MetricsUIAggregation } from '../../../types';

export const cpu: SnapshotModel = {
export const cpu: MetricsUIAggregation = {
cpu_user: {
avg: {
field: 'system.cpu.user.pct',
Expand Down
Loading