Skip to content

Commit 63772b2

Browse files
authored
feat(cockpit): add route to update datasource name (#1333)
1 parent 877702c commit 63772b2

File tree

5 files changed

+127
-0
lines changed

5 files changed

+127
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
unmarshalListDataSourcesResponse,
3232
unmarshalListGrafanaProductDashboardsResponse,
3333
unmarshalListGrafanaUsersResponse,
34+
unmarshalListManagedAlertsResponse,
3435
unmarshalListPlansResponse,
3536
unmarshalListTokensResponse,
3637
unmarshalPlan,
@@ -59,6 +60,7 @@ import type {
5960
ListDataSourcesResponse,
6061
ListGrafanaProductDashboardsResponse,
6162
ListGrafanaUsersResponse,
63+
ListManagedAlertsResponse,
6264
ListPlansResponse,
6365
ListTokensResponse,
6466
Plan,
@@ -78,6 +80,7 @@ import type {
7880
RegionalApiGetUsageOverviewRequest,
7981
RegionalApiListContactPointsRequest,
8082
RegionalApiListDataSourcesRequest,
83+
RegionalApiListManagedAlertsRequest,
8184
RegionalApiListTokensRequest,
8285
RegionalApiTriggerTestAlertRequest,
8386
Token,
@@ -759,6 +762,39 @@ export class RegionalAPI extends ParentAPI {
759762
path: `/cockpit/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/alert-manager/contact-points/delete`,
760763
})
761764

765+
protected pageOfListManagedAlerts = (
766+
request: Readonly<RegionalApiListManagedAlertsRequest> = {},
767+
) =>
768+
this.client.fetch<ListManagedAlertsResponse>(
769+
{
770+
method: 'GET',
771+
path: `/cockpit/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/managed-alerts`,
772+
urlParams: urlParams(
773+
['order_by', request.orderBy],
774+
['page', request.page],
775+
[
776+
'page_size',
777+
request.pageSize ?? this.client.settings.defaultPageSize,
778+
],
779+
[
780+
'project_id',
781+
request.projectId ?? this.client.settings.defaultProjectId,
782+
],
783+
),
784+
},
785+
unmarshalListManagedAlertsResponse,
786+
)
787+
788+
/**
789+
* List managed alerts. List all managed alerts for the specified Project.
790+
*
791+
* @param request - The request {@link RegionalApiListManagedAlertsRequest}
792+
* @returns A Promise of ListManagedAlertsResponse
793+
*/
794+
listManagedAlerts = (
795+
request: Readonly<RegionalApiListManagedAlertsRequest> = {},
796+
) => enrichForPagination('alerts', this.pageOfListManagedAlerts, request)
797+
762798
/**
763799
* Enable managed alerts. Enable the sending of managed alerts for the
764800
* specified Project. Managed alerts are predefined alerts that apply to

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// If you have any remark or suggestion do not hesitate to open an issue.
33
export { GlobalAPI, RegionalAPI } from './api.gen'
44
export type {
5+
Alert,
56
AlertManager,
67
ContactPoint,
78
ContactPointEmail,
@@ -29,6 +30,8 @@ export type {
2930
ListGrafanaProductDashboardsResponse,
3031
ListGrafanaUsersRequestOrderBy,
3132
ListGrafanaUsersResponse,
33+
ListManagedAlertsRequestOrderBy,
34+
ListManagedAlertsResponse,
3235
ListPlansRequestOrderBy,
3336
ListPlansResponse,
3437
ListTokensRequestOrderBy,
@@ -51,6 +54,7 @@ export type {
5154
RegionalApiGetUsageOverviewRequest,
5255
RegionalApiListContactPointsRequest,
5356
RegionalApiListDataSourcesRequest,
57+
RegionalApiListManagedAlertsRequest,
5458
RegionalApiListTokensRequest,
5559
RegionalApiTriggerTestAlertRequest,
5660
Token,

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '../../../bridge'
99
import type { DefaultValues } from '../../../bridge'
1010
import type {
11+
Alert,
1112
AlertManager,
1213
ContactPoint,
1314
ContactPointEmail,
@@ -23,6 +24,7 @@ import type {
2324
ListDataSourcesResponse,
2425
ListGrafanaProductDashboardsResponse,
2526
ListGrafanaUsersResponse,
27+
ListManagedAlertsResponse,
2628
ListPlansResponse,
2729
ListTokensResponse,
2830
Plan,
@@ -255,6 +257,37 @@ export const unmarshalListGrafanaUsersResponse = (
255257
} as ListGrafanaUsersResponse
256258
}
257259

260+
const unmarshalAlert = (data: unknown): Alert => {
261+
if (!isJSONObject(data)) {
262+
throw new TypeError(
263+
`Unmarshalling the type 'Alert' failed as data isn't a dictionary.`,
264+
)
265+
}
266+
267+
return {
268+
description: data.description,
269+
name: data.name,
270+
product: data.product,
271+
productFamily: data.product_family,
272+
rule: data.rule,
273+
} as Alert
274+
}
275+
276+
export const unmarshalListManagedAlertsResponse = (
277+
data: unknown,
278+
): ListManagedAlertsResponse => {
279+
if (!isJSONObject(data)) {
280+
throw new TypeError(
281+
`Unmarshalling the type 'ListManagedAlertsResponse' failed as data isn't a dictionary.`,
282+
)
283+
}
284+
285+
return {
286+
alerts: unmarshalArrayOfObject(data.alerts, unmarshalAlert),
287+
totalCount: data.total_count,
288+
} as ListManagedAlertsResponse
289+
}
290+
258291
export const unmarshalListPlansResponse = (
259292
data: unknown,
260293
): ListPlansResponse => {

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ export type ListDataSourcesRequestOrderBy =
1818

1919
export type ListGrafanaUsersRequestOrderBy = 'login_asc' | 'login_desc'
2020

21+
export type ListManagedAlertsRequestOrderBy =
22+
| 'created_at_asc'
23+
| 'created_at_desc'
24+
| 'name_asc'
25+
| 'name_desc'
26+
| 'type_asc'
27+
| 'type_desc'
28+
2129
export type ListPlansRequestOrderBy = 'name_asc' | 'name_desc'
2230

2331
export type ListTokensRequestOrderBy =
@@ -111,6 +119,14 @@ export interface GrafanaUser {
111119
password?: string
112120
}
113121

122+
export interface Alert {
123+
productFamily: string
124+
product: string
125+
name: string
126+
rule: string
127+
description: string
128+
}
129+
114130
/** Type of pricing plan. */
115131
export interface Plan {
116132
/** Name of a given pricing plan. */
@@ -330,6 +346,14 @@ export interface ListGrafanaUsersResponse {
330346
grafanaUsers: GrafanaUser[]
331347
}
332348

349+
/** Response returned when listing data sources. */
350+
export interface ListManagedAlertsResponse {
351+
/** Total count of data sources matching the request. */
352+
totalCount: number
353+
/** Alerts matching the request within the pagination. */
354+
alerts: Alert[]
355+
}
356+
333357
/** Output returned when listing pricing plans. */
334358
export interface ListPlansResponse {
335359
/** Total count of available pricing plans. */
@@ -564,6 +588,26 @@ export type RegionalApiListDataSourcesRequest = {
564588
types?: DataSourceType[]
565589
}
566590

591+
/** Enable the sending of managed alerts. */
592+
export type RegionalApiListManagedAlertsRequest = {
593+
/**
594+
* Region to target. If none is passed will use default region from the
595+
* config.
596+
*/
597+
region?: Region
598+
/** Page number to return, from the paginated results. */
599+
page?: number
600+
/** Number of data sources to return per page. */
601+
pageSize?: number
602+
/** Sort order for data sources in the response. */
603+
orderBy?: ListManagedAlertsRequestOrderBy
604+
/**
605+
* Project ID to filter for, only data sources from this Project will be
606+
* returned.
607+
*/
608+
projectId?: string
609+
}
610+
567611
/** List tokens. */
568612
export type RegionalApiListTokensRequest = {
569613
/**

packages/clients/src/api/cockpit/v1/validation-rules.gen.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ export const RegionalApiListDataSourcesRequest = {
3737
},
3838
}
3939

40+
export const RegionalApiListManagedAlertsRequest = {
41+
page: {
42+
greaterThanOrEqual: 1,
43+
},
44+
pageSize: {
45+
greaterThanOrEqual: 1,
46+
lessThanOrEqual: 1000,
47+
},
48+
}
49+
4050
export const RegionalApiListTokensRequest = {
4151
page: {
4252
greaterThanOrEqual: 1,

0 commit comments

Comments
 (0)