Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages_generated/cockpit/src/v1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
unmarshalDisableAlertRulesResponse,
unmarshalEnableAlertRulesResponse,
unmarshalGetConfigResponse,
unmarshalGetRulesCountResponse,
unmarshalGrafana,
unmarshalGrafanaProductDashboard,
unmarshalGrafanaUser,
Expand All @@ -53,6 +54,7 @@ import type {
DisableAlertRulesResponse,
EnableAlertRulesResponse,
GetConfigResponse,
GetRulesCountResponse,
GlobalApiCreateGrafanaUserRequest,
GlobalApiDeleteGrafanaUserRequest,
GlobalApiGetCurrentPlanRequest,
Expand Down Expand Up @@ -90,6 +92,7 @@ import type {
RegionalApiGetAlertManagerRequest,
RegionalApiGetConfigRequest,
RegionalApiGetDataSourceRequest,
RegionalApiGetRulesCountRequest,
RegionalApiGetTokenRequest,
RegionalApiGetUsageOverviewRequest,
RegionalApiListAlertsRequest,
Expand Down Expand Up @@ -690,6 +693,25 @@ The output returned displays a URL to access the Alert manager, and whether the
unmarshalAlertManager,
)

/**
* Get a detailed count of enabled rules in the specified Project. Includes preconfigured and custom alerting and recording rules.. Get a detailed count of enabled rules in the specified Project. Includes preconfigured and custom alerting and recording rules.
*
* @param request - The request {@link RegionalApiGetRulesCountRequest}
* @returns A Promise of GetRulesCountResponse
*/
getRulesCount = (request: Readonly<RegionalApiGetRulesCountRequest> = {}) =>
this.client.fetch<GetRulesCountResponse>(
{
method: 'GET',
path: `/cockpit/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/rules/count`,
urlParams: urlParams([
'project_id',
request.projectId ?? this.client.settings.defaultProjectId,
]),
},
unmarshalGetRulesCountResponse,
)

/**
* Create a contact point. Contact points are email addresses associated with the default receiver, that the Alert manager sends alerts to.
The source of the alerts are data sources within the same Project and region as the Alert manager.
Expand Down
3 changes: 3 additions & 0 deletions packages_generated/cockpit/src/v1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type {
EnableAlertRulesResponse,
GetConfigResponse,
GetConfigResponseRetention,
GetRulesCountResponse,
GlobalApiCreateGrafanaUserRequest,
GlobalApiDeleteGrafanaUserRequest,
GlobalApiGetCurrentPlanRequest,
Expand Down Expand Up @@ -62,6 +63,7 @@ export type {
RegionalApiGetAlertManagerRequest,
RegionalApiGetConfigRequest,
RegionalApiGetDataSourceRequest,
RegionalApiGetRulesCountRequest,
RegionalApiGetTokenRequest,
RegionalApiGetUsageOverviewRequest,
RegionalApiListAlertsRequest,
Expand All @@ -71,6 +73,7 @@ export type {
RegionalApiTriggerTestAlertRequest,
RegionalApiUpdateContactPointRequest,
RegionalApiUpdateDataSourceRequest,
RulesCount,
Token,
TokenScope,
Usage,
Expand Down
35 changes: 35 additions & 0 deletions packages_generated/cockpit/src/v1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
EnableAlertRulesResponse,
GetConfigResponse,
GetConfigResponseRetention,
GetRulesCountResponse,
GlobalApiCreateGrafanaUserRequest,
GlobalApiResetGrafanaUserPasswordRequest,
GlobalApiSelectPlanRequest,
Expand Down Expand Up @@ -46,6 +47,7 @@ import type {
RegionalApiTriggerTestAlertRequest,
RegionalApiUpdateContactPointRequest,
RegionalApiUpdateDataSourceRequest,
RulesCount,
Token,
Usage,
UsageOverview,
Expand Down Expand Up @@ -257,6 +259,39 @@ export const unmarshalGetConfigResponse = (
} as GetConfigResponse
}

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

return {
dataSourceId: data.data_source_id,
dataSourceName: data.data_source_name,
rulesCount: data.rules_count,
} as RulesCount
}

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

return {
customRulesCount: data.custom_rules_count,
preconfiguredRulesCount: data.preconfigured_rules_count,
rulesCountByDatasource: unmarshalArrayOfObject(
data.rules_count_by_datasource,
unmarshalRulesCount,
),
} as GetRulesCountResponse
}

export const unmarshalGrafana = (data: unknown): Grafana => {
if (!isJSONObject(data)) {
throw new TypeError(
Expand Down
41 changes: 41 additions & 0 deletions packages_generated/cockpit/src/v1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ export interface GetConfigResponseRetention {
defaultDays: number
}

export interface RulesCount {
/**
* ID of the data source.
*/
dataSourceId: string
/**
* Name of the data source.
*/
dataSourceName: string
/**
* Total count of rules associated with this data source.
*/
rulesCount: number
}

/**
* Structure representing an alert.
*/
Expand Down Expand Up @@ -430,6 +445,21 @@ export interface GetConfigResponse {
productLogsRetention?: GetConfigResponseRetention
}

export interface GetRulesCountResponse {
/**
* Total count of rules grouped by data source.
*/
rulesCountByDatasource: RulesCount[]
/**
* Total count of preconfigured rules.
*/
preconfiguredRulesCount: number
/**
* Total count of custom rules.
*/
customRulesCount: number
}

/**
* Create a Grafana user.
*/
Expand Down Expand Up @@ -953,6 +983,17 @@ export type RegionalApiGetDataSourceRequest = {
dataSourceId: string
}

export type RegionalApiGetRulesCountRequest = {
/**
* Region to target. If none is passed will use default region from the config.
*/
region?: ScwRegion
/**
* ID of the Project to retrieve the rule count for.
*/
projectId?: string
}

/**
* Get a token.
*/
Expand Down
Loading