Skip to content

Commit

Permalink
feat(cockpit): add route to update datasource name (#1333)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot authored Jun 20, 2024
1 parent 877702c commit 63772b2
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/clients/src/api/cockpit/v1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
unmarshalListDataSourcesResponse,
unmarshalListGrafanaProductDashboardsResponse,
unmarshalListGrafanaUsersResponse,
unmarshalListManagedAlertsResponse,
unmarshalListPlansResponse,
unmarshalListTokensResponse,
unmarshalPlan,
Expand Down Expand Up @@ -59,6 +60,7 @@ import type {
ListDataSourcesResponse,
ListGrafanaProductDashboardsResponse,
ListGrafanaUsersResponse,
ListManagedAlertsResponse,
ListPlansResponse,
ListTokensResponse,
Plan,
Expand All @@ -78,6 +80,7 @@ import type {
RegionalApiGetUsageOverviewRequest,
RegionalApiListContactPointsRequest,
RegionalApiListDataSourcesRequest,
RegionalApiListManagedAlertsRequest,
RegionalApiListTokensRequest,
RegionalApiTriggerTestAlertRequest,
Token,
Expand Down Expand Up @@ -759,6 +762,39 @@ export class RegionalAPI extends ParentAPI {
path: `/cockpit/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/alert-manager/contact-points/delete`,
})

protected pageOfListManagedAlerts = (
request: Readonly<RegionalApiListManagedAlertsRequest> = {},
) =>
this.client.fetch<ListManagedAlertsResponse>(
{
method: 'GET',
path: `/cockpit/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/managed-alerts`,
urlParams: urlParams(
['order_by', request.orderBy],
['page', request.page],
[
'page_size',
request.pageSize ?? this.client.settings.defaultPageSize,
],
[
'project_id',
request.projectId ?? this.client.settings.defaultProjectId,
],
),
},
unmarshalListManagedAlertsResponse,
)

/**
* List managed alerts. List all managed alerts for the specified Project.
*
* @param request - The request {@link RegionalApiListManagedAlertsRequest}
* @returns A Promise of ListManagedAlertsResponse
*/
listManagedAlerts = (
request: Readonly<RegionalApiListManagedAlertsRequest> = {},
) => enrichForPagination('alerts', this.pageOfListManagedAlerts, request)

/**
* Enable managed alerts. Enable the sending of managed alerts for the
* specified Project. Managed alerts are predefined alerts that apply to
Expand Down
4 changes: 4 additions & 0 deletions packages/clients/src/api/cockpit/v1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// If you have any remark or suggestion do not hesitate to open an issue.
export { GlobalAPI, RegionalAPI } from './api.gen'
export type {
Alert,
AlertManager,
ContactPoint,
ContactPointEmail,
Expand Down Expand Up @@ -29,6 +30,8 @@ export type {
ListGrafanaProductDashboardsResponse,
ListGrafanaUsersRequestOrderBy,
ListGrafanaUsersResponse,
ListManagedAlertsRequestOrderBy,
ListManagedAlertsResponse,
ListPlansRequestOrderBy,
ListPlansResponse,
ListTokensRequestOrderBy,
Expand All @@ -51,6 +54,7 @@ export type {
RegionalApiGetUsageOverviewRequest,
RegionalApiListContactPointsRequest,
RegionalApiListDataSourcesRequest,
RegionalApiListManagedAlertsRequest,
RegionalApiListTokensRequest,
RegionalApiTriggerTestAlertRequest,
Token,
Expand Down
33 changes: 33 additions & 0 deletions packages/clients/src/api/cockpit/v1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '../../../bridge'
import type { DefaultValues } from '../../../bridge'
import type {
Alert,
AlertManager,
ContactPoint,
ContactPointEmail,
Expand All @@ -23,6 +24,7 @@ import type {
ListDataSourcesResponse,
ListGrafanaProductDashboardsResponse,
ListGrafanaUsersResponse,
ListManagedAlertsResponse,
ListPlansResponse,
ListTokensResponse,
Plan,
Expand Down Expand Up @@ -255,6 +257,37 @@ export const unmarshalListGrafanaUsersResponse = (
} as ListGrafanaUsersResponse
}

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

return {
description: data.description,
name: data.name,
product: data.product,
productFamily: data.product_family,
rule: data.rule,
} as Alert
}

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

return {
alerts: unmarshalArrayOfObject(data.alerts, unmarshalAlert),
totalCount: data.total_count,
} as ListManagedAlertsResponse
}

export const unmarshalListPlansResponse = (
data: unknown,
): ListPlansResponse => {
Expand Down
44 changes: 44 additions & 0 deletions packages/clients/src/api/cockpit/v1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ export type ListDataSourcesRequestOrderBy =

export type ListGrafanaUsersRequestOrderBy = 'login_asc' | 'login_desc'

export type ListManagedAlertsRequestOrderBy =
| 'created_at_asc'
| 'created_at_desc'
| 'name_asc'
| 'name_desc'
| 'type_asc'
| 'type_desc'

export type ListPlansRequestOrderBy = 'name_asc' | 'name_desc'

export type ListTokensRequestOrderBy =
Expand Down Expand Up @@ -111,6 +119,14 @@ export interface GrafanaUser {
password?: string
}

export interface Alert {
productFamily: string
product: string
name: string
rule: string
description: string
}

/** Type of pricing plan. */
export interface Plan {
/** Name of a given pricing plan. */
Expand Down Expand Up @@ -330,6 +346,14 @@ export interface ListGrafanaUsersResponse {
grafanaUsers: GrafanaUser[]
}

/** Response returned when listing data sources. */
export interface ListManagedAlertsResponse {
/** Total count of data sources matching the request. */
totalCount: number
/** Alerts matching the request within the pagination. */
alerts: Alert[]
}

/** Output returned when listing pricing plans. */
export interface ListPlansResponse {
/** Total count of available pricing plans. */
Expand Down Expand Up @@ -564,6 +588,26 @@ export type RegionalApiListDataSourcesRequest = {
types?: DataSourceType[]
}

/** Enable the sending of managed alerts. */
export type RegionalApiListManagedAlertsRequest = {
/**
* Region to target. If none is passed will use default region from the
* config.
*/
region?: Region
/** Page number to return, from the paginated results. */
page?: number
/** Number of data sources to return per page. */
pageSize?: number
/** Sort order for data sources in the response. */
orderBy?: ListManagedAlertsRequestOrderBy
/**
* Project ID to filter for, only data sources from this Project will be
* returned.
*/
projectId?: string
}

/** List tokens. */
export type RegionalApiListTokensRequest = {
/**
Expand Down
10 changes: 10 additions & 0 deletions packages/clients/src/api/cockpit/v1/validation-rules.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ export const RegionalApiListDataSourcesRequest = {
},
}

export const RegionalApiListManagedAlertsRequest = {
page: {
greaterThanOrEqual: 1,
},
pageSize: {
greaterThanOrEqual: 1,
lessThanOrEqual: 1000,
},
}

export const RegionalApiListTokensRequest = {
page: {
greaterThanOrEqual: 1,
Expand Down

0 comments on commit 63772b2

Please sign in to comment.