Skip to content

Commit b0b8f80

Browse files
authored
feat(cockpit): get usage metrics (#562)
1 parent e8bd249 commit b0b8f80

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

packages/clients/src/api/cockpit/v1beta1/api.gen.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
marshalResetGrafanaUserPasswordRequest,
2424
marshalTriggerTestAlertRequest,
2525
unmarshalCockpit,
26+
unmarshalCockpitMetrics,
2627
unmarshalContactPoint,
2728
unmarshalGrafanaUser,
2829
unmarshalListContactPointsResponse,
@@ -33,6 +34,7 @@ import {
3334
import type {
3435
ActivateCockpitRequest,
3536
Cockpit,
37+
CockpitMetrics,
3638
ContactPoint,
3739
CreateContactPointRequest,
3840
CreateGrafanaUserRequest,
@@ -43,6 +45,7 @@ import type {
4345
DeleteTokenRequest,
4446
DisableManagedAlertsRequest,
4547
EnableManagedAlertsRequest,
48+
GetCockpitMetricsRequest,
4649
GetCockpitRequest,
4750
GetTokenRequest,
4851
GrafanaUser,
@@ -127,6 +130,30 @@ export class API extends ParentAPI {
127130
options,
128131
)
129132

133+
/**
134+
* Get cockpit metrics. Get the cockpit metrics with the given project ID.
135+
*
136+
* @param request - The request {@link GetCockpitMetricsRequest}
137+
* @returns A Promise of CockpitMetrics
138+
*/
139+
getCockpitMetrics = (request: Readonly<GetCockpitMetricsRequest> = {}) =>
140+
this.client.fetch<CockpitMetrics>(
141+
{
142+
method: 'GET',
143+
path: `/cockpit/v1beta1/cockpit/metrics`,
144+
urlParams: urlParams(
145+
['end_date', request.endDate],
146+
['metric_name', request.metricName],
147+
[
148+
'project_id',
149+
request.projectId ?? this.client.settings.defaultProjectId,
150+
],
151+
['start_date', request.startDate],
152+
),
153+
},
154+
unmarshalCockpitMetrics,
155+
)
156+
130157
/**
131158
* Deactivate a cockpit. Deactivate a cockpit associated with the given
132159
* project ID.

packages/clients/src/api/cockpit/v1beta1/index.gen.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type {
66
ActivateCockpitRequest,
77
Cockpit,
88
CockpitEndpoints,
9+
CockpitMetrics,
910
CockpitStatus,
1011
ContactPoint,
1112
ContactPointEmail,
@@ -18,6 +19,7 @@ export type {
1819
DeleteTokenRequest,
1920
DisableManagedAlertsRequest,
2021
EnableManagedAlertsRequest,
22+
GetCockpitMetricsRequest,
2123
GetCockpitRequest,
2224
GetTokenRequest,
2325
GrafanaUser,

packages/clients/src/api/cockpit/v1beta1/marshalling.gen.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import {
66
resolveOneOf,
77
unmarshalArrayOfObject,
88
unmarshalDate,
9+
unmarshalTimeSeries,
910
} from '../../../bridge'
1011
import type { DefaultValues } from '../../../bridge'
1112
import type {
1213
ActivateCockpitRequest,
1314
Cockpit,
1415
CockpitEndpoints,
16+
CockpitMetrics,
1517
ContactPoint,
1618
ContactPointEmail,
1719
CreateContactPointRequest,
@@ -140,6 +142,18 @@ export const unmarshalCockpit = (data: unknown) => {
140142
} as Cockpit
141143
}
142144

145+
export const unmarshalCockpitMetrics = (data: unknown) => {
146+
if (!isJSONObject(data)) {
147+
throw new TypeError(
148+
`Unmarshalling the type 'CockpitMetrics' failed as data isn't a dictionary.`,
149+
)
150+
}
151+
152+
return {
153+
timeseries: unmarshalArrayOfObject(data.timeseries, unmarshalTimeSeries),
154+
} as CockpitMetrics
155+
}
156+
143157
export const unmarshalListContactPointsResponse = (data: unknown) => {
144158
if (!isJSONObject(data)) {
145159
throw new TypeError(

packages/clients/src/api/cockpit/v1beta1/types.gen.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// This file was automatically generated. DO NOT EDIT.
22
// If you have any remark or suggestion do not hesitate to open an issue.
3+
import type { TimeSeries } from '../../../bridge'
34

45
export type CockpitStatus =
56
| 'unknown_status'
@@ -43,6 +44,12 @@ export interface CockpitEndpoints {
4344
grafanaUrl: string
4445
}
4546

47+
/** Cockpit metrics. */
48+
export interface CockpitMetrics {
49+
/** Timeseries array. */
50+
timeseries: TimeSeries[]
51+
}
52+
4653
/** Alert contact point. Contact point. */
4754
export interface ContactPoint {
4855
/**
@@ -119,6 +126,17 @@ export type GetCockpitRequest = {
119126
projectId?: string
120127
}
121128

129+
export type GetCockpitMetricsRequest = {
130+
/** Project ID. */
131+
projectId?: string
132+
/** Start date. */
133+
startDate?: Date
134+
/** End date. */
135+
endDate?: Date
136+
/** Metric name. */
137+
metricName?: string
138+
}
139+
122140
export type DeactivateCockpitRequest = {
123141
projectId?: string
124142
}

0 commit comments

Comments
 (0)