Skip to content

Commit

Permalink
feat(cockpit): list and get Grafana dashboards (scaleway#916)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot authored Oct 10, 2023
1 parent d0986c8 commit 3f695fa
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 0 deletions.
69 changes: 69 additions & 0 deletions packages/clients/src/api/cockpit/v1beta1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ import {
unmarshalCockpitMetrics,
unmarshalContactPoint,
unmarshalDatasource,
unmarshalGrafanaProductDashboard,
unmarshalGrafanaUser,
unmarshalListContactPointsResponse,
unmarshalListDatasourcesResponse,
unmarshalListGrafanaProductDashboardsResponse,
unmarshalListGrafanaUsersResponse,
unmarshalListPlansResponse,
unmarshalListTokensResponse,
Expand All @@ -55,12 +57,16 @@ import type {
EnableManagedAlertsRequest,
GetCockpitMetricsRequest,
GetCockpitRequest,
GetGrafanaProductDashboardRequest,
GetTokenRequest,
GrafanaProductDashboard,
GrafanaUser,
ListContactPointsRequest,
ListContactPointsResponse,
ListDatasourcesRequest,
ListDatasourcesResponse,
ListGrafanaProductDashboardsRequest,
ListGrafanaProductDashboardsResponse,
ListGrafanaUsersRequest,
ListGrafanaUsersResponse,
ListPlansRequest,
Expand Down Expand Up @@ -595,4 +601,67 @@ export class API extends ParentAPI {
},
unmarshalSelectPlanResponse,
)

protected pageOfListGrafanaProductDashboards = (
request: Readonly<ListGrafanaProductDashboardsRequest> = {},
) =>
this.client.fetch<ListGrafanaProductDashboardsResponse>(
{
method: 'GET',
path: `/cockpit/v1beta1/grafana-product-dashboards`,
urlParams: urlParams(
['page', request.page],
[
'page_size',
request.pageSize ?? this.client.settings.defaultPageSize,
],
[
'project_id',
request.projectId ?? this.client.settings.defaultProjectId,
],
['tags', request.tags],
),
},
unmarshalListGrafanaProductDashboardsResponse,
)

/**
* List product dashboards. Get a list of available product dashboards.
*
* @param request - The request {@link ListGrafanaProductDashboardsRequest}
* @returns A Promise of ListGrafanaProductDashboardsResponse
*/
listGrafanaProductDashboards = (
request: Readonly<ListGrafanaProductDashboardsRequest> = {},
) =>
enrichForPagination(
'dashboards',
this.pageOfListGrafanaProductDashboards,
request,
)

/**
* Get a product dashboard. Get a product dashboard specified by the dashboard
* ID.
*
* @param request - The request {@link GetGrafanaProductDashboardRequest}
* @returns A Promise of GrafanaProductDashboard
*/
getGrafanaProductDashboard = (
request: Readonly<GetGrafanaProductDashboardRequest>,
) =>
this.client.fetch<GrafanaProductDashboard>(
{
method: 'GET',
path: `/cockpit/v1beta1/grafana-product-dashboards/${validatePathParam(
'dashboardName',
request.dashboardName,
)}`,
urlParams: urlParams([
'project_id',
request.projectId ?? this.client.settings.defaultProjectId,
]),
},
unmarshalGrafanaProductDashboard,
)
}
4 changes: 4 additions & 0 deletions packages/clients/src/api/cockpit/v1beta1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ export type {
EnableManagedAlertsRequest,
GetCockpitMetricsRequest,
GetCockpitRequest,
GetGrafanaProductDashboardRequest,
GetTokenRequest,
GrafanaProductDashboard,
GrafanaUser,
GrafanaUserRole,
ListContactPointsRequest,
ListContactPointsResponse,
ListDatasourcesRequest,
ListDatasourcesRequestOrderBy,
ListDatasourcesResponse,
ListGrafanaProductDashboardsRequest,
ListGrafanaProductDashboardsResponse,
ListGrafanaUsersRequest,
ListGrafanaUsersRequestOrderBy,
ListGrafanaUsersResponse,
Expand Down
36 changes: 36 additions & 0 deletions packages/clients/src/api/cockpit/v1beta1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ import type {
DeleteGrafanaUserRequest,
DisableManagedAlertsRequest,
EnableManagedAlertsRequest,
GrafanaProductDashboard,
GrafanaUser,
ListContactPointsResponse,
ListDatasourcesResponse,
ListGrafanaProductDashboardsResponse,
ListGrafanaUsersResponse,
ListPlansResponse,
ListTokensResponse,
Expand Down Expand Up @@ -115,6 +117,22 @@ export const unmarshalDatasource = (data: unknown) => {
} as Datasource
}

export const unmarshalGrafanaProductDashboard = (data: unknown) => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'GrafanaProductDashboard' failed as data isn't a dictionary.`,
)
}

return {
dashboardName: data.dashboard_name,
tags: data.tags,
title: data.title,
url: data.url,
variables: data.variables,
} as GrafanaProductDashboard
}

export const unmarshalGrafanaUser = (data: unknown) => {
if (!isJSONObject(data)) {
throw new TypeError(
Expand Down Expand Up @@ -229,6 +247,24 @@ export const unmarshalListDatasourcesResponse = (data: unknown) => {
} as ListDatasourcesResponse
}

export const unmarshalListGrafanaProductDashboardsResponse = (
data: unknown,
) => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'ListGrafanaProductDashboardsResponse' failed as data isn't a dictionary.`,
)
}

return {
dashboards: unmarshalArrayOfObject(
data.dashboards,
unmarshalGrafanaProductDashboard,
),
totalCount: data.total_count,
} as ListGrafanaProductDashboardsResponse
}

export const unmarshalListGrafanaUsersResponse = (data: unknown) => {
if (!isJSONObject(data)) {
throw new TypeError(
Expand Down
43 changes: 43 additions & 0 deletions packages/clients/src/api/cockpit/v1beta1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ export interface Datasource {
type: DatasourceType
}

/** Grafana dashboard. Grafana product dashboard. */
export interface GrafanaProductDashboard {
/** Name of the dashboard. */
dashboardName: string
/** Title of the dashboard. */
title: string
/** URL of the dashboard. */
url: string
/** Tags of the dashboard. */
tags: string[]
/** Variables of the dashboard. */
variables: string[]
}

/** Grafana user. */
export interface GrafanaUser {
/** ID of the Grafana user. */
Expand Down Expand Up @@ -136,6 +150,17 @@ export interface ListDatasourcesResponse {
datasources: Datasource[]
}

/**
* Response returned when getting a list of dashboards. List grafana product
* dashboards response.
*/
export interface ListGrafanaProductDashboardsResponse {
/** Count of grafana dasboards. */
totalCount: number
/** Information on grafana dashboards. */
dashboards: GrafanaProductDashboard[]
}

/** Response returned when listing Grafana users. List grafana users response. */
export interface ListGrafanaUsersResponse {
/** Count of all Grafana users. */
Expand Down Expand Up @@ -388,3 +413,21 @@ export type SelectPlanRequest = {
/** ID of the pricing plan. */
planId: string
}

export type ListGrafanaProductDashboardsRequest = {
/** ID of the Project. */
projectId?: string
/** Page number. */
page?: number
/** Page size. */
pageSize?: number
/** Tags to filter the dashboards. */
tags?: string[]
}

export type GetGrafanaProductDashboardRequest = {
/** Name of the dashboard. */
dashboardName: string
/** ID of the Project. */
projectId?: string
}

0 comments on commit 3f695fa

Please sign in to comment.