Skip to content

feat(cockpit): add EnablePreconfiguredAlertRules endpoint #2014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2025
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
44 changes: 44 additions & 0 deletions packages/clients/src/api/cockpit/v1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import {
marshalRegionalApiCreateTokenRequest,
marshalRegionalApiDeleteContactPointRequest,
marshalRegionalApiDisableAlertManagerRequest,
marshalRegionalApiDisableAlertRulesRequest,
marshalRegionalApiDisableManagedAlertsRequest,
marshalRegionalApiEnableAlertManagerRequest,
marshalRegionalApiEnableAlertRulesRequest,
marshalRegionalApiEnableManagedAlertsRequest,
marshalRegionalApiTriggerTestAlertRequest,
marshalRegionalApiUpdateContactPointRequest,
Expand Down Expand Up @@ -75,8 +77,10 @@ import type {
RegionalApiDeleteDataSourceRequest,
RegionalApiDeleteTokenRequest,
RegionalApiDisableAlertManagerRequest,
RegionalApiDisableAlertRulesRequest,
RegionalApiDisableManagedAlertsRequest,
RegionalApiEnableAlertManagerRequest,
RegionalApiEnableAlertRulesRequest,
RegionalApiEnableManagedAlertsRequest,
RegionalApiGetAlertManagerRequest,
RegionalApiGetConfigRequest,
Expand Down Expand Up @@ -853,6 +857,46 @@ If you need to receive alerts for other receivers, you can create additional con
unmarshalAlertManager,
)

/**
* Enable preconfigured alert rules. Enable alert rules from the list of available preconfigured rules.. Enable preconfigured alert rules. Enable alert rules from the list of available preconfigured rules.
*
* @param request - The request {@link RegionalApiEnableAlertRulesRequest}
*/
enableAlertRules = (
request: Readonly<RegionalApiEnableAlertRulesRequest> = {},
) =>
this.client.fetch<void>({
body: JSON.stringify(
marshalRegionalApiEnableAlertRulesRequest(
request,
this.client.settings,
),
),
headers: jsonContentHeaders,
method: 'POST',
path: `/cockpit/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/alert-manager/enable-alert-rules`,
})

/**
* Disable preconfigured alert rules. Disable alert rules from the list of available preconfigured rules.. Disable preconfigured alert rules. Disable alert rules from the list of available preconfigured rules.
*
* @param request - The request {@link RegionalApiDisableAlertRulesRequest}
*/
disableAlertRules = (
request: Readonly<RegionalApiDisableAlertRulesRequest> = {},
) =>
this.client.fetch<void>({
body: JSON.stringify(
marshalRegionalApiDisableAlertRulesRequest(
request,
this.client.settings,
),
),
headers: jsonContentHeaders,
method: 'POST',
path: `/cockpit/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/alert-manager/disable-alert-rules`,
})

/**
* Trigger a test alert. Send a test alert to the Alert manager to make sure your contact points get notified.
*
Expand Down
3 changes: 3 additions & 0 deletions packages/clients/src/api/cockpit/v1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@ export type {
ListTokensResponse,
Plan,
PlanName,
PreconfiguredAlertData,
RegionalApiCreateContactPointRequest,
RegionalApiCreateDataSourceRequest,
RegionalApiCreateTokenRequest,
RegionalApiDeleteContactPointRequest,
RegionalApiDeleteDataSourceRequest,
RegionalApiDeleteTokenRequest,
RegionalApiDisableAlertManagerRequest,
RegionalApiDisableAlertRulesRequest,
RegionalApiDisableManagedAlertsRequest,
RegionalApiEnableAlertManagerRequest,
RegionalApiEnableAlertRulesRequest,
RegionalApiEnableManagedAlertsRequest,
RegionalApiGetAlertManagerRequest,
RegionalApiGetConfigRequest,
Expand Down
38 changes: 38 additions & 0 deletions packages/clients/src/api/cockpit/v1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ import type {
ListPlansResponse,
ListTokensResponse,
Plan,
PreconfiguredAlertData,
RegionalApiCreateContactPointRequest,
RegionalApiCreateDataSourceRequest,
RegionalApiCreateTokenRequest,
RegionalApiDeleteContactPointRequest,
RegionalApiDisableAlertManagerRequest,
RegionalApiDisableAlertRulesRequest,
RegionalApiDisableManagedAlertsRequest,
RegionalApiEnableAlertManagerRequest,
RegionalApiEnableAlertRulesRequest,
RegionalApiEnableManagedAlertsRequest,
RegionalApiTriggerTestAlertRequest,
RegionalApiUpdateContactPointRequest,
Expand Down Expand Up @@ -236,6 +239,22 @@ export const unmarshalGrafana = (data: unknown): Grafana => {
} as Grafana
}

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

return {
displayDescription: data.display_description,
displayName: data.display_name,
preconfiguredRuleId: data.preconfigured_rule_id,
} as PreconfiguredAlertData
}

const unmarshalAlert = (data: unknown): Alert => {
if (!isJSONObject(data)) {
throw new TypeError(
Expand All @@ -249,6 +268,9 @@ const unmarshalAlert = (data: unknown): Alert => {
enabled: data.enabled,
name: data.name,
preconfigured: data.preconfigured,
preconfiguredData: data.preconfigured_data
? unmarshalPreconfiguredAlertData(data.preconfigured_data)
: undefined,
region: data.region,
rule: data.rule,
state: data.state ? data.state : undefined,
Expand Down Expand Up @@ -514,6 +536,14 @@ export const marshalRegionalApiDisableAlertManagerRequest = (
project_id: request.projectId ?? defaults.defaultProjectId,
})

export const marshalRegionalApiDisableAlertRulesRequest = (
request: RegionalApiDisableAlertRulesRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
project_id: request.projectId ?? defaults.defaultProjectId,
rule_ids: request.ruleIds,
})

export const marshalRegionalApiDisableManagedAlertsRequest = (
request: RegionalApiDisableManagedAlertsRequest,
defaults: DefaultValues,
Expand All @@ -528,6 +558,14 @@ export const marshalRegionalApiEnableAlertManagerRequest = (
project_id: request.projectId ?? defaults.defaultProjectId,
})

export const marshalRegionalApiEnableAlertRulesRequest = (
request: RegionalApiEnableAlertRulesRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
project_id: request.projectId ?? defaults.defaultProjectId,
rule_ids: request.ruleIds,
})

export const marshalRegionalApiEnableManagedAlertsRequest = (
request: RegionalApiEnableManagedAlertsRequest,
defaults: DefaultValues,
Expand Down
68 changes: 66 additions & 2 deletions packages/clients/src/api/cockpit/v1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ export type TokenScope =

export type UsageUnit = 'unknown_unit' | 'bytes' | 'samples'

/**
* Structure for additional data relative to preconfigured alerts.
*/
export interface PreconfiguredAlertData {
/**
* ID of the preconfigured rule if the alert is preconfigured.
*/
preconfiguredRuleId: string
/**
* Human readable name of the alert.
*/
displayName: string
/**
* Human readable description of the alert.
*/
displayDescription: string
}

export interface ContactPointEmail {
to: string
}
Expand All @@ -58,18 +76,46 @@ export interface GetConfigResponseRetention {
defaultDays: number
}

/**
* Structure representing an alert.
*/
export interface Alert {
/**
* Region to target. If none is passed will use default region from the config.
* The region in which the alert is defined.
*/
region: ScwRegion
/**
* Indicates if the alert is preconfigured or custom.
*/
preconfigured: boolean
/**
* Name of the alert.
*/
name: string
/**
* Rule defining the alert condition.
*/
rule: string
/**
* Duration for which the alert must be active before firing. The format of this duration follows the prometheus duration format.
*/
duration: string
/**
* Indicates if the alert is enabled or disabled. Only preconfigured alerts can be disabled.
*/
enabled: boolean
/**
* Current state of the alert. Possible states are `inactive`, `pending`, and `firing`.
*/
state?: AlertState
/**
* Annotations for the alert, used to provide additional information about the alert.
*/
annotations: Record<string, string>
/**
* Contains additional data for preconfigured alerts, such as the rule ID, display name, and description. Only present if the alert is preconfigured.
*/
preconfiguredData?: PreconfiguredAlertData
}

/**
Expand Down Expand Up @@ -765,6 +811,15 @@ export type RegionalApiDisableAlertManagerRequest = {
projectId?: string
}

export type RegionalApiDisableAlertRulesRequest = {
/**
* Region to target. If none is passed will use default region from the config.
*/
region?: ScwRegion
projectId?: string
ruleIds?: string[]
}

/**
* Disable the sending of managed alerts.
*/
Expand Down Expand Up @@ -793,6 +848,15 @@ export type RegionalApiEnableAlertManagerRequest = {
projectId?: string
}

export type RegionalApiEnableAlertRulesRequest = {
/**
* Region to target. If none is passed will use default region from the config.
*/
region?: ScwRegion
projectId?: string
ruleIds?: string[]
}

/**
* Enable the sending of managed alerts.
*/
Expand Down Expand Up @@ -889,7 +953,7 @@ export type RegionalApiListAlertsRequest = {
*/
isPreconfigured?: boolean
/**
* Valid values to filter on are `disabled`, `enabled`, `pending` and `firing`. If omitted, no filtering is applied on alert states. Other filters may still apply.
* Valid values to filter on are `inactive`, `pending` and `firing`. If omitted, no filtering is applied on alert states. Other filters may still apply.
*/
state?: AlertState
}
Expand Down
Loading