Skip to content

Commit

Permalink
feat(cockpit): add regional get cockpit metrics (scaleway#1589)
Browse files Browse the repository at this point in the history
Co-authored-by: Jules Castéran <[email protected]>
  • Loading branch information
scaleway-bot and Codelax authored Nov 20, 2024
1 parent 0e32de2 commit 2e2d4fb
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
23 changes: 23 additions & 0 deletions packages/clients/src/api/cockpit/v1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
marshalRegionalApiTriggerTestAlertRequest,
marshalRegionalApiUpdateDataSourceRequest,
unmarshalAlertManager,
unmarshalCockpitMetrics,
unmarshalContactPoint,
unmarshalDataSource,
unmarshalGetConfigResponse,
Expand All @@ -42,6 +43,7 @@ import {
} from './marshalling.gen'
import type {
AlertManager,
CockpitMetrics,
ContactPoint,
DataSource,
GetConfigResponse,
Expand Down Expand Up @@ -78,6 +80,7 @@ import type {
RegionalApiEnableAlertManagerRequest,
RegionalApiEnableManagedAlertsRequest,
RegionalApiGetAlertManagerRequest,
RegionalApiGetCockpitMetricsRequest,
RegionalApiGetConfigRequest,
RegionalApiGetDataSourceRequest,
RegionalApiGetTokenRequest,
Expand Down Expand Up @@ -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<RegionalApiGetCockpitMetricsRequest>,
) =>
this.client.fetch<CockpitMetrics>(
{
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,
)
}
2 changes: 2 additions & 0 deletions packages/clients/src/api/cockpit/v1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export { GlobalAPI, RegionalAPI } from './api.gen'
export type {
Alert,
AlertManager,
CockpitMetrics,
ContactPoint,
ContactPointEmail,
DataSource,
Expand Down Expand Up @@ -51,6 +52,7 @@ export type {
RegionalApiEnableAlertManagerRequest,
RegionalApiEnableManagedAlertsRequest,
RegionalApiGetAlertManagerRequest,
RegionalApiGetCockpitMetricsRequest,
RegionalApiGetConfigRequest,
RegionalApiGetDataSourceRequest,
RegionalApiGetTokenRequest,
Expand Down
14 changes: 14 additions & 0 deletions packages/clients/src/api/cockpit/v1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import {
resolveOneOf,
unmarshalArrayOfObject,
unmarshalDate,
unmarshalTimeSeries,
} from '../../../bridge'
import type { DefaultValues } from '../../../bridge'
import type {
Alert,
AlertManager,
CockpitMetrics,
ContactPoint,
ContactPointEmail,
DataSource,
Expand Down Expand Up @@ -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 => {
Expand Down
15 changes: 13 additions & 2 deletions packages/clients/src/api/cockpit/v1/types.gen.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -207,6 +207,10 @@ export interface AlertManager {
region: Region
}

export interface CockpitMetrics {
timeseries: TimeSeries[]
}

/** Cockpit configuration. */
export interface GetConfigResponse {
/** Custom metrics retention configuration. */
Expand Down Expand Up @@ -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 = {
/**
Expand Down

0 comments on commit 2e2d4fb

Please sign in to comment.