From 2e2d4fb8e27338260f1f8dd4e9bbb9b0d1909280 Mon Sep 17 00:00:00 2001 From: Scaleway Bot Date: Wed, 20 Nov 2024 15:47:12 +0100 Subject: [PATCH] feat(cockpit): add regional get cockpit metrics (#1589) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jules Castéran --- .../clients/src/api/cockpit/v1/api.gen.ts | 23 +++++++++++++++++++ .../clients/src/api/cockpit/v1/index.gen.ts | 2 ++ .../src/api/cockpit/v1/marshalling.gen.ts | 14 +++++++++++ .../clients/src/api/cockpit/v1/types.gen.ts | 15 ++++++++++-- 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/packages/clients/src/api/cockpit/v1/api.gen.ts b/packages/clients/src/api/cockpit/v1/api.gen.ts index e04a5b3db..eb45e6f31 100644 --- a/packages/clients/src/api/cockpit/v1/api.gen.ts +++ b/packages/clients/src/api/cockpit/v1/api.gen.ts @@ -23,6 +23,7 @@ import { marshalRegionalApiTriggerTestAlertRequest, marshalRegionalApiUpdateDataSourceRequest, unmarshalAlertManager, + unmarshalCockpitMetrics, unmarshalContactPoint, unmarshalDataSource, unmarshalGetConfigResponse, @@ -42,6 +43,7 @@ import { } from './marshalling.gen' import type { AlertManager, + CockpitMetrics, ContactPoint, DataSource, GetConfigResponse, @@ -78,6 +80,7 @@ import type { RegionalApiEnableAlertManagerRequest, RegionalApiEnableManagedAlertsRequest, RegionalApiGetAlertManagerRequest, + RegionalApiGetCockpitMetricsRequest, RegionalApiGetConfigRequest, RegionalApiGetDataSourceRequest, RegionalApiGetTokenRequest, @@ -915,4 +918,24 @@ export class RegionalAPI extends ParentAPI { method: 'POST', path: `/cockpit/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/alert-manager/trigger-test-alert`, }) + + getCockpitMetrics = ( + request: Readonly, + ) => + this.client.fetch( + { + method: 'GET', + path: `/cockpit/v1beta1/cockpit/metrics`, + urlParams: urlParams( + ['end_date', request.endDate], + [ + 'project_id', + request.projectId ?? this.client.settings.defaultProjectId, + ], + ['query', request.query], + ['start_date', request.startDate], + ), + }, + unmarshalCockpitMetrics, + ) } diff --git a/packages/clients/src/api/cockpit/v1/index.gen.ts b/packages/clients/src/api/cockpit/v1/index.gen.ts index 421639703..995b85a99 100644 --- a/packages/clients/src/api/cockpit/v1/index.gen.ts +++ b/packages/clients/src/api/cockpit/v1/index.gen.ts @@ -4,6 +4,7 @@ export { GlobalAPI, RegionalAPI } from './api.gen' export type { Alert, AlertManager, + CockpitMetrics, ContactPoint, ContactPointEmail, DataSource, @@ -51,6 +52,7 @@ export type { RegionalApiEnableAlertManagerRequest, RegionalApiEnableManagedAlertsRequest, RegionalApiGetAlertManagerRequest, + RegionalApiGetCockpitMetricsRequest, RegionalApiGetConfigRequest, RegionalApiGetDataSourceRequest, RegionalApiGetTokenRequest, diff --git a/packages/clients/src/api/cockpit/v1/marshalling.gen.ts b/packages/clients/src/api/cockpit/v1/marshalling.gen.ts index 30b8ad846..aee142232 100644 --- a/packages/clients/src/api/cockpit/v1/marshalling.gen.ts +++ b/packages/clients/src/api/cockpit/v1/marshalling.gen.ts @@ -5,11 +5,13 @@ import { resolveOneOf, unmarshalArrayOfObject, unmarshalDate, + unmarshalTimeSeries, } from '../../../bridge' import type { DefaultValues } from '../../../bridge' import type { Alert, AlertManager, + CockpitMetrics, ContactPoint, ContactPointEmail, DataSource, @@ -178,6 +180,18 @@ export const unmarshalAlertManager = (data: unknown): AlertManager => { } as AlertManager } +export const unmarshalCockpitMetrics = (data: unknown): CockpitMetrics => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'CockpitMetrics' failed as data isn't a dictionary.`, + ) + } + + return { + timeseries: unmarshalArrayOfObject(data.timeseries, unmarshalTimeSeries), + } as CockpitMetrics +} + const unmarshalGetConfigResponseRetention = ( data: unknown, ): GetConfigResponseRetention => { diff --git a/packages/clients/src/api/cockpit/v1/types.gen.ts b/packages/clients/src/api/cockpit/v1/types.gen.ts index fbb3922ea..1ca010d26 100644 --- a/packages/clients/src/api/cockpit/v1/types.gen.ts +++ b/packages/clients/src/api/cockpit/v1/types.gen.ts @@ -1,8 +1,8 @@ // This file was automatically generated. DO NOT EDIT. // If you have any remark or suggestion do not hesitate to open an issue. -import type { Region } from '../../../bridge' +import type { Region, TimeSeries } from '../../../bridge' -export type DataSourceOrigin = 'unknown_origin' | 'scaleway' | 'external' +export type DataSourceOrigin = 'unknown_origin' | 'scaleway' | 'custom' export type DataSourceType = 'unknown_type' | 'metrics' | 'logs' | 'traces' @@ -207,6 +207,10 @@ export interface AlertManager { region: Region } +export interface CockpitMetrics { + timeseries: TimeSeries[] +} + /** Cockpit configuration. */ export interface GetConfigResponse { /** Custom metrics retention configuration. */ @@ -535,6 +539,13 @@ export type RegionalApiGetAlertManagerRequest = { projectId?: string } +export type RegionalApiGetCockpitMetricsRequest = { + projectId?: string + startDate?: Date + endDate?: Date + query: string +} + /** Get Cockpit configuration. */ export type RegionalApiGetConfigRequest = { /**