From 356f7f722251b91535fd08d32fc121e9aaac66cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Ho=C3=9F?= Date: Tue, 14 Nov 2023 06:23:58 +0100 Subject: [PATCH] add slok/sloth MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sebastian Hoß --- .reuse/dep5 | 4 + code-generator/src/catalog.rs | 7 + .../v1/prometheusservicelevels.yaml | 218 ++++++++++++++++++ kube-custom-resources-rs/Cargo.toml | 1 + kube-custom-resources-rs/src/lib.rs | 9 + .../src/sloth_slok_dev_v1/mod.rs | 1 + .../prometheusservicelevels.rs | 154 +++++++++++++ 7 files changed, 394 insertions(+) create mode 100644 crd-catalog/slok/sloth/sloth.slok.dev/v1/prometheusservicelevels.yaml create mode 100644 kube-custom-resources-rs/src/sloth_slok_dev_v1/mod.rs create mode 100644 kube-custom-resources-rs/src/sloth_slok_dev_v1/prometheusservicelevels.rs diff --git a/.reuse/dep5 b/.reuse/dep5 index b7581937b..95e597190 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -751,6 +751,10 @@ Files: crd-catalog/sigstore/sigstore-helm-operator/* Copyright: The sigstore/sigstore-helm-operator Authors License: Apache-2.0 +Files: crd-catalog/slok/sloth/* +Copyright: The slok/sloth Authors +License: Apache-2.0 + Files: crd-catalog/smartxworks/virtink/* Copyright: The smartxworks/virtink Authors License: Apache-2.0 diff --git a/code-generator/src/catalog.rs b/code-generator/src/catalog.rs index 74c183bab..cb44f0a95 100644 --- a/code-generator/src/catalog.rs +++ b/code-generator/src/catalog.rs @@ -1929,6 +1929,13 @@ pub const CRD_V1_SOURCES: &'static [UpstreamSource] = &[ "https://github.com/sigstore/sigstore-helm-operator/blob/main/config/crd/bases/helm.sigstore.dev_rekors.yaml", ], }, + UpstreamSource { + project_name: "slok/sloth", + license: APACHE_V2, + urls: &[ + "https://github.com/slok/sloth/blob/main/pkg/kubernetes/gen/crd/sloth.slok.dev_prometheusservicelevels.yaml", + ], + }, UpstreamSource { project_name: "smartxworks/virtink", license: APACHE_V2, diff --git a/crd-catalog/slok/sloth/sloth.slok.dev/v1/prometheusservicelevels.yaml b/crd-catalog/slok/sloth/sloth.slok.dev/v1/prometheusservicelevels.yaml new file mode 100644 index 000000000..50ae1f0aa --- /dev/null +++ b/crd-catalog/slok/sloth/sloth.slok.dev/v1/prometheusservicelevels.yaml @@ -0,0 +1,218 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: (devel) + name: prometheusservicelevels.sloth.slok.dev +spec: + group: sloth.slok.dev + names: + categories: + - slo + - slos + - sli + - slis + kind: PrometheusServiceLevel + listKind: PrometheusServiceLevelList + plural: prometheusservicelevels + shortNames: + - psl + - pslo + singular: prometheusservicelevel + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .spec.service + name: SERVICE + type: string + - jsonPath: .status.processedSLOs + name: DESIRED SLOs + type: integer + - jsonPath: .status.promOpRulesGeneratedSLOs + name: READY SLOs + type: integer + - jsonPath: .status.promOpRulesGenerated + name: GEN OK + type: boolean + - jsonPath: .status.lastPromOpRulesSuccessfulGenerated + name: GEN AGE + type: date + - jsonPath: .metadata.creationTimestamp + name: AGE + type: date + name: v1 + schema: + openAPIV3Schema: + description: PrometheusServiceLevel is the expected service quality level using Prometheus as the backend used by Sloth. + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: ServiceLevelSpec is the spec for a PrometheusServiceLevel. + properties: + labels: + additionalProperties: + type: string + description: Labels are the Prometheus labels that will have all the recording and alerting rules generated for the service SLOs. + type: object + service: + description: Service is the application of the SLOs. + type: string + slos: + description: SLOs are the SLOs of the service. + items: + description: SLO is the configuration/declaration of the service level objective of a service. + properties: + alerting: + description: Alerting is the configuration with all the things related with the SLO alerts. + properties: + annotations: + additionalProperties: + type: string + description: Annotations are the Prometheus annotations that will have all the alerts generated by this SLO. + type: object + labels: + additionalProperties: + type: string + description: Labels are the Prometheus labels that will have all the alerts generated by this SLO. + type: object + name: + description: Name is the name used by the alerts generated for this SLO. + type: string + pageAlert: + description: Page alert refers to the critical alert (check multiwindow-multiburn alerts). + properties: + annotations: + additionalProperties: + type: string + description: Annotations are the Prometheus annotations for the specific alert. + type: object + disable: + description: Disable disables the alert and makes Sloth not generating this alert. This can be helpful for example to disable ticket(warning) alerts. + type: boolean + labels: + additionalProperties: + type: string + description: Labels are the Prometheus labels for the specific alert. For example can be useful to route the Page alert to specific Slack channel. + type: object + type: object + ticketAlert: + description: TicketAlert alert refers to the warning alert (check multiwindow-multiburn alerts). + properties: + annotations: + additionalProperties: + type: string + description: Annotations are the Prometheus annotations for the specific alert. + type: object + disable: + description: Disable disables the alert and makes Sloth not generating this alert. This can be helpful for example to disable ticket(warning) alerts. + type: boolean + labels: + additionalProperties: + type: string + description: Labels are the Prometheus labels for the specific alert. For example can be useful to route the Page alert to specific Slack channel. + type: object + type: object + type: object + description: + description: Description is the description of the SLO. + type: string + labels: + additionalProperties: + type: string + description: Labels are the Prometheus labels that will have all the recording and alerting rules for this specific SLO. These labels are merged with the previous level labels. + type: object + name: + description: Name is the name of the SLO. + maxLength: 128 + type: string + objective: + description: Objective is target of the SLO the percentage (0, 100] (e.g 99.9). + type: number + sli: + description: SLI is the indicator (service level indicator) for this specific SLO. + properties: + events: + description: Events is the events SLI type. + properties: + errorQuery: + description: ErrorQuery is a Prometheus query that will get the number/count of events that we consider that are bad for the SLO (e.g "http 5xx", "latency > 250ms"...). Requires the usage of `{{.window}}` template variable. + type: string + totalQuery: + description: TotalQuery is a Prometheus query that will get the total number/count of events for the SLO (e.g "all http requests"...). Requires the usage of `{{.window}}` template variable. + type: string + required: + - errorQuery + - totalQuery + type: object + plugin: + description: Plugin is the pluggable SLI type. + properties: + id: + description: Name is the name of the plugin that needs to load. + type: string + options: + additionalProperties: + type: string + description: Options are the options used for the plugin. + type: object + required: + - id + type: object + raw: + description: Raw is the raw SLI type. + properties: + errorRatioQuery: + description: ErrorRatioQuery is a Prometheus query that will get the raw error ratio (0-1) for the SLO. + type: string + required: + - errorRatioQuery + type: object + type: object + required: + - alerting + - name + - objective + - sli + type: object + minItems: 1 + type: array + required: + - service + type: object + status: + properties: + lastPromOpRulesSuccessfulGenerated: + description: LastPromOpRulesGeneration tells the last atemp made for a successful SLO rules generate. + format: date-time + type: string + observedGeneration: + description: ObservedGeneration tells the generation was acted on, normally this is required to stop an infinite loop when the status is updated because it sends a watch updated event to the watchers of the K8s object. + format: int64 + type: integer + processedSLOs: + description: ProcessedSLOs tells how many SLOs haven been processed for Prometheus operator. + type: integer + promOpRulesGenerated: + description: PromOpRulesGenerated tells if the rules for prometheus operator CRD have been generated. + type: boolean + promOpRulesGeneratedSLOs: + description: PromOpRulesGeneratedSLOs tells how many SLOs have been processed and generated for Prometheus operator successfully. + type: integer + required: + - observedGeneration + - processedSLOs + - promOpRulesGenerated + - promOpRulesGeneratedSLOs + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/kube-custom-resources-rs/Cargo.toml b/kube-custom-resources-rs/Cargo.toml index c909586ce..1326a6905 100644 --- a/kube-custom-resources-rs/Cargo.toml +++ b/kube-custom-resources-rs/Cargo.toml @@ -301,6 +301,7 @@ serving_kubedl_io_v1alpha1 = [] sfn_services_k8s_aws_v1alpha1 = [] site_superedge_io_v1alpha1 = [] slo_koordinator_sh_v1alpha1 = [] +sloth_slok_dev_v1 = [] sonataflow_org_v1alpha08 = [] source_toolkit_fluxcd_io_v1beta1 = [] source_toolkit_fluxcd_io_v1beta2 = [] diff --git a/kube-custom-resources-rs/src/lib.rs b/kube-custom-resources-rs/src/lib.rs index 51e6d7185..10d094de2 100644 --- a/kube-custom-resources-rs/src/lib.rs +++ b/kube-custom-resources-rs/src/lib.rs @@ -2552,6 +2552,13 @@ kinds: - `NodeMetric` - `NodeSLO` +## sloth_slok_dev_v1 + +apiVersion: `sloth.slok.dev/v1` + +kinds: +- `PrometheusServiceLevel` + ## sonataflow_org_v1alpha08 apiVersion: `sonataflow.org/v1alpha08` @@ -3352,6 +3359,8 @@ pub mod sfn_services_k8s_aws_v1alpha1; pub mod site_superedge_io_v1alpha1; #[cfg(feature = "slo_koordinator_sh_v1alpha1")] pub mod slo_koordinator_sh_v1alpha1; +#[cfg(feature = "sloth_slok_dev_v1")] +pub mod sloth_slok_dev_v1; #[cfg(feature = "sonataflow_org_v1alpha08")] pub mod sonataflow_org_v1alpha08; #[cfg(feature = "source_toolkit_fluxcd_io_v1beta1")] diff --git a/kube-custom-resources-rs/src/sloth_slok_dev_v1/mod.rs b/kube-custom-resources-rs/src/sloth_slok_dev_v1/mod.rs new file mode 100644 index 000000000..6b01648d5 --- /dev/null +++ b/kube-custom-resources-rs/src/sloth_slok_dev_v1/mod.rs @@ -0,0 +1 @@ +pub mod prometheusservicelevels; diff --git a/kube-custom-resources-rs/src/sloth_slok_dev_v1/prometheusservicelevels.rs b/kube-custom-resources-rs/src/sloth_slok_dev_v1/prometheusservicelevels.rs new file mode 100644 index 000000000..2cc7e7ad6 --- /dev/null +++ b/kube-custom-resources-rs/src/sloth_slok_dev_v1/prometheusservicelevels.rs @@ -0,0 +1,154 @@ +// WARNING: generated by kopium - manual changes will be overwritten +// kopium command: kopium --docs --filename=./crd-catalog/slok/sloth/sloth.slok.dev/v1/prometheusservicelevels.yaml --derive=Default --derive=PartialEq +// kopium version: 0.16.2 + +use kube::CustomResource; +use serde::{Serialize, Deserialize}; +use std::collections::BTreeMap; + +/// ServiceLevelSpec is the spec for a PrometheusServiceLevel. +#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, Default, PartialEq)] +#[kube(group = "sloth.slok.dev", version = "v1", kind = "PrometheusServiceLevel", plural = "prometheusservicelevels")] +#[kube(namespaced)] +#[kube(status = "PrometheusServiceLevelStatus")] +#[kube(schema = "disabled")] +pub struct PrometheusServiceLevelSpec { + /// Labels are the Prometheus labels that will have all the recording and alerting rules generated for the service SLOs. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub labels: Option>, + /// Service is the application of the SLOs. + pub service: String, + /// SLOs are the SLOs of the service. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub slos: Option>, +} + +/// SLO is the configuration/declaration of the service level objective of a service. +#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)] +pub struct PrometheusServiceLevelSlos { + /// Alerting is the configuration with all the things related with the SLO alerts. + pub alerting: PrometheusServiceLevelSlosAlerting, + /// Description is the description of the SLO. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub description: Option, + /// Labels are the Prometheus labels that will have all the recording and alerting rules for this specific SLO. These labels are merged with the previous level labels. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub labels: Option>, + /// Name is the name of the SLO. + pub name: String, + /// Objective is target of the SLO the percentage (0, 100] (e.g 99.9). + pub objective: f64, + /// SLI is the indicator (service level indicator) for this specific SLO. + pub sli: PrometheusServiceLevelSlosSli, +} + +/// Alerting is the configuration with all the things related with the SLO alerts. +#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)] +pub struct PrometheusServiceLevelSlosAlerting { + /// Annotations are the Prometheus annotations that will have all the alerts generated by this SLO. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub annotations: Option>, + /// Labels are the Prometheus labels that will have all the alerts generated by this SLO. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub labels: Option>, + /// Name is the name used by the alerts generated for this SLO. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub name: Option, + /// Page alert refers to the critical alert (check multiwindow-multiburn alerts). + #[serde(default, skip_serializing_if = "Option::is_none", rename = "pageAlert")] + pub page_alert: Option, + /// TicketAlert alert refers to the warning alert (check multiwindow-multiburn alerts). + #[serde(default, skip_serializing_if = "Option::is_none", rename = "ticketAlert")] + pub ticket_alert: Option, +} + +/// Page alert refers to the critical alert (check multiwindow-multiburn alerts). +#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)] +pub struct PrometheusServiceLevelSlosAlertingPageAlert { + /// Annotations are the Prometheus annotations for the specific alert. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub annotations: Option>, + /// Disable disables the alert and makes Sloth not generating this alert. This can be helpful for example to disable ticket(warning) alerts. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub disable: Option, + /// Labels are the Prometheus labels for the specific alert. For example can be useful to route the Page alert to specific Slack channel. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub labels: Option>, +} + +/// TicketAlert alert refers to the warning alert (check multiwindow-multiburn alerts). +#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)] +pub struct PrometheusServiceLevelSlosAlertingTicketAlert { + /// Annotations are the Prometheus annotations for the specific alert. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub annotations: Option>, + /// Disable disables the alert and makes Sloth not generating this alert. This can be helpful for example to disable ticket(warning) alerts. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub disable: Option, + /// Labels are the Prometheus labels for the specific alert. For example can be useful to route the Page alert to specific Slack channel. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub labels: Option>, +} + +/// SLI is the indicator (service level indicator) for this specific SLO. +#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)] +pub struct PrometheusServiceLevelSlosSli { + /// Events is the events SLI type. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub events: Option, + /// Plugin is the pluggable SLI type. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub plugin: Option, + /// Raw is the raw SLI type. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub raw: Option, +} + +/// Events is the events SLI type. +#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)] +pub struct PrometheusServiceLevelSlosSliEvents { + /// ErrorQuery is a Prometheus query that will get the number/count of events that we consider that are bad for the SLO (e.g "http 5xx", "latency > 250ms"...). Requires the usage of `{{.window}}` template variable. + #[serde(rename = "errorQuery")] + pub error_query: String, + /// TotalQuery is a Prometheus query that will get the total number/count of events for the SLO (e.g "all http requests"...). Requires the usage of `{{.window}}` template variable. + #[serde(rename = "totalQuery")] + pub total_query: String, +} + +/// Plugin is the pluggable SLI type. +#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)] +pub struct PrometheusServiceLevelSlosSliPlugin { + /// Name is the name of the plugin that needs to load. + pub id: String, + /// Options are the options used for the plugin. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub options: Option>, +} + +/// Raw is the raw SLI type. +#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)] +pub struct PrometheusServiceLevelSlosSliRaw { + /// ErrorRatioQuery is a Prometheus query that will get the raw error ratio (0-1) for the SLO. + #[serde(rename = "errorRatioQuery")] + pub error_ratio_query: String, +} + +#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)] +pub struct PrometheusServiceLevelStatus { + /// LastPromOpRulesGeneration tells the last atemp made for a successful SLO rules generate. + #[serde(default, skip_serializing_if = "Option::is_none", rename = "lastPromOpRulesSuccessfulGenerated")] + pub last_prom_op_rules_successful_generated: Option, + /// ObservedGeneration tells the generation was acted on, normally this is required to stop an infinite loop when the status is updated because it sends a watch updated event to the watchers of the K8s object. + #[serde(rename = "observedGeneration")] + pub observed_generation: i64, + /// ProcessedSLOs tells how many SLOs haven been processed for Prometheus operator. + #[serde(rename = "processedSLOs")] + pub processed_sl_os: i64, + /// PromOpRulesGenerated tells if the rules for prometheus operator CRD have been generated. + #[serde(rename = "promOpRulesGenerated")] + pub prom_op_rules_generated: bool, + /// PromOpRulesGeneratedSLOs tells how many SLOs have been processed and generated for Prometheus operator successfully. + #[serde(rename = "promOpRulesGeneratedSLOs")] + pub prom_op_rules_generated_sl_os: i64, +} +