Skip to content

Commit 3f695fa

Browse files
authored
feat(cockpit): list and get Grafana dashboards (#916)
1 parent d0986c8 commit 3f695fa

File tree

4 files changed

+152
-0
lines changed

4 files changed

+152
-0
lines changed

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ import {
2828
unmarshalCockpitMetrics,
2929
unmarshalContactPoint,
3030
unmarshalDatasource,
31+
unmarshalGrafanaProductDashboard,
3132
unmarshalGrafanaUser,
3233
unmarshalListContactPointsResponse,
3334
unmarshalListDatasourcesResponse,
35+
unmarshalListGrafanaProductDashboardsResponse,
3436
unmarshalListGrafanaUsersResponse,
3537
unmarshalListPlansResponse,
3638
unmarshalListTokensResponse,
@@ -55,12 +57,16 @@ import type {
5557
EnableManagedAlertsRequest,
5658
GetCockpitMetricsRequest,
5759
GetCockpitRequest,
60+
GetGrafanaProductDashboardRequest,
5861
GetTokenRequest,
62+
GrafanaProductDashboard,
5963
GrafanaUser,
6064
ListContactPointsRequest,
6165
ListContactPointsResponse,
6266
ListDatasourcesRequest,
6367
ListDatasourcesResponse,
68+
ListGrafanaProductDashboardsRequest,
69+
ListGrafanaProductDashboardsResponse,
6470
ListGrafanaUsersRequest,
6571
ListGrafanaUsersResponse,
6672
ListPlansRequest,
@@ -595,4 +601,67 @@ export class API extends ParentAPI {
595601
},
596602
unmarshalSelectPlanResponse,
597603
)
604+
605+
protected pageOfListGrafanaProductDashboards = (
606+
request: Readonly<ListGrafanaProductDashboardsRequest> = {},
607+
) =>
608+
this.client.fetch<ListGrafanaProductDashboardsResponse>(
609+
{
610+
method: 'GET',
611+
path: `/cockpit/v1beta1/grafana-product-dashboards`,
612+
urlParams: urlParams(
613+
['page', request.page],
614+
[
615+
'page_size',
616+
request.pageSize ?? this.client.settings.defaultPageSize,
617+
],
618+
[
619+
'project_id',
620+
request.projectId ?? this.client.settings.defaultProjectId,
621+
],
622+
['tags', request.tags],
623+
),
624+
},
625+
unmarshalListGrafanaProductDashboardsResponse,
626+
)
627+
628+
/**
629+
* List product dashboards. Get a list of available product dashboards.
630+
*
631+
* @param request - The request {@link ListGrafanaProductDashboardsRequest}
632+
* @returns A Promise of ListGrafanaProductDashboardsResponse
633+
*/
634+
listGrafanaProductDashboards = (
635+
request: Readonly<ListGrafanaProductDashboardsRequest> = {},
636+
) =>
637+
enrichForPagination(
638+
'dashboards',
639+
this.pageOfListGrafanaProductDashboards,
640+
request,
641+
)
642+
643+
/**
644+
* Get a product dashboard. Get a product dashboard specified by the dashboard
645+
* ID.
646+
*
647+
* @param request - The request {@link GetGrafanaProductDashboardRequest}
648+
* @returns A Promise of GrafanaProductDashboard
649+
*/
650+
getGrafanaProductDashboard = (
651+
request: Readonly<GetGrafanaProductDashboardRequest>,
652+
) =>
653+
this.client.fetch<GrafanaProductDashboard>(
654+
{
655+
method: 'GET',
656+
path: `/cockpit/v1beta1/grafana-product-dashboards/${validatePathParam(
657+
'dashboardName',
658+
request.dashboardName,
659+
)}`,
660+
urlParams: urlParams([
661+
'project_id',
662+
request.projectId ?? this.client.settings.defaultProjectId,
663+
]),
664+
},
665+
unmarshalGrafanaProductDashboard,
666+
)
598667
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@ export type {
2424
EnableManagedAlertsRequest,
2525
GetCockpitMetricsRequest,
2626
GetCockpitRequest,
27+
GetGrafanaProductDashboardRequest,
2728
GetTokenRequest,
29+
GrafanaProductDashboard,
2830
GrafanaUser,
2931
GrafanaUserRole,
3032
ListContactPointsRequest,
3133
ListContactPointsResponse,
3234
ListDatasourcesRequest,
3335
ListDatasourcesRequestOrderBy,
3436
ListDatasourcesResponse,
37+
ListGrafanaProductDashboardsRequest,
38+
ListGrafanaProductDashboardsResponse,
3539
ListGrafanaUsersRequest,
3640
ListGrafanaUsersRequestOrderBy,
3741
ListGrafanaUsersResponse,

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ import type {
2626
DeleteGrafanaUserRequest,
2727
DisableManagedAlertsRequest,
2828
EnableManagedAlertsRequest,
29+
GrafanaProductDashboard,
2930
GrafanaUser,
3031
ListContactPointsResponse,
3132
ListDatasourcesResponse,
33+
ListGrafanaProductDashboardsResponse,
3234
ListGrafanaUsersResponse,
3335
ListPlansResponse,
3436
ListTokensResponse,
@@ -115,6 +117,22 @@ export const unmarshalDatasource = (data: unknown) => {
115117
} as Datasource
116118
}
117119

120+
export const unmarshalGrafanaProductDashboard = (data: unknown) => {
121+
if (!isJSONObject(data)) {
122+
throw new TypeError(
123+
`Unmarshalling the type 'GrafanaProductDashboard' failed as data isn't a dictionary.`,
124+
)
125+
}
126+
127+
return {
128+
dashboardName: data.dashboard_name,
129+
tags: data.tags,
130+
title: data.title,
131+
url: data.url,
132+
variables: data.variables,
133+
} as GrafanaProductDashboard
134+
}
135+
118136
export const unmarshalGrafanaUser = (data: unknown) => {
119137
if (!isJSONObject(data)) {
120138
throw new TypeError(
@@ -229,6 +247,24 @@ export const unmarshalListDatasourcesResponse = (data: unknown) => {
229247
} as ListDatasourcesResponse
230248
}
231249

250+
export const unmarshalListGrafanaProductDashboardsResponse = (
251+
data: unknown,
252+
) => {
253+
if (!isJSONObject(data)) {
254+
throw new TypeError(
255+
`Unmarshalling the type 'ListGrafanaProductDashboardsResponse' failed as data isn't a dictionary.`,
256+
)
257+
}
258+
259+
return {
260+
dashboards: unmarshalArrayOfObject(
261+
data.dashboards,
262+
unmarshalGrafanaProductDashboard,
263+
),
264+
totalCount: data.total_count,
265+
} as ListGrafanaProductDashboardsResponse
266+
}
267+
232268
export const unmarshalListGrafanaUsersResponse = (data: unknown) => {
233269
if (!isJSONObject(data)) {
234270
throw new TypeError(

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ export interface Datasource {
101101
type: DatasourceType
102102
}
103103

104+
/** Grafana dashboard. Grafana product dashboard. */
105+
export interface GrafanaProductDashboard {
106+
/** Name of the dashboard. */
107+
dashboardName: string
108+
/** Title of the dashboard. */
109+
title: string
110+
/** URL of the dashboard. */
111+
url: string
112+
/** Tags of the dashboard. */
113+
tags: string[]
114+
/** Variables of the dashboard. */
115+
variables: string[]
116+
}
117+
104118
/** Grafana user. */
105119
export interface GrafanaUser {
106120
/** ID of the Grafana user. */
@@ -136,6 +150,17 @@ export interface ListDatasourcesResponse {
136150
datasources: Datasource[]
137151
}
138152

153+
/**
154+
* Response returned when getting a list of dashboards. List grafana product
155+
* dashboards response.
156+
*/
157+
export interface ListGrafanaProductDashboardsResponse {
158+
/** Count of grafana dasboards. */
159+
totalCount: number
160+
/** Information on grafana dashboards. */
161+
dashboards: GrafanaProductDashboard[]
162+
}
163+
139164
/** Response returned when listing Grafana users. List grafana users response. */
140165
export interface ListGrafanaUsersResponse {
141166
/** Count of all Grafana users. */
@@ -388,3 +413,21 @@ export type SelectPlanRequest = {
388413
/** ID of the pricing plan. */
389414
planId: string
390415
}
416+
417+
export type ListGrafanaProductDashboardsRequest = {
418+
/** ID of the Project. */
419+
projectId?: string
420+
/** Page number. */
421+
page?: number
422+
/** Page size. */
423+
pageSize?: number
424+
/** Tags to filter the dashboards. */
425+
tags?: string[]
426+
}
427+
428+
export type GetGrafanaProductDashboardRequest = {
429+
/** Name of the dashboard. */
430+
dashboardName: string
431+
/** ID of the Project. */
432+
projectId?: string
433+
}

0 commit comments

Comments
 (0)