From 8f0c9ca2ec677ee04a33e938b64cc72c059a6df2 Mon Sep 17 00:00:00 2001 From: odubajDT <93584209+odubajDT@users.noreply.github.com> Date: Tue, 2 Apr 2024 14:10:53 +0200 Subject: [PATCH] feat(metrics-operator): support Cortex metrics provider (#3361) Signed-off-by: odubajDT --- .github/actions/spelling/expect.txt | 1 + .github/scripts/.helm-tests/default/result.yaml | 4 ++-- .../.helm-tests/local-global-precedence/result.yaml | 4 ++-- .../result.yaml | 4 ++-- .../scripts/.helm-tests/metrics-only/result.yaml | 4 ++-- .../.helm-tests/metrics-with-certs/result.yaml | 4 ++-- docs/docs/assets/crd/examples/yaml-synopsis.yaml | 2 +- docs/docs/components/metrics-operator.md | 2 +- .../contribute/software/add-new-metric-provider.md | 2 +- docs/docs/core-concepts/index.md | 2 +- docs/docs/getting-started/metrics.md | 2 +- docs/docs/installation/k8s.md | 1 + docs/docs/migrate/keptn/strategy.md | 2 +- .../reference/api-reference/metrics/v1/index.md | 2 +- .../crd-reference/analysisvaluetemplate.md | 2 +- .../reference/crd-reference/evaluationdefinition.md | 4 ++-- .../docs/reference/crd-reference/metricsprovider.md | 8 ++++---- docs/docs/use-cases/non-k8s.md | 4 ++-- .../api/v1/keptnmetricsprovider_types.go | 4 ++-- .../api/v1/keptnmetricsprovider_types_test.go | 13 +++++++++++++ .../chart/templates/keptnmetricsprovider-crd.yaml | 4 ++-- .../metrics.keptn.sh_keptnmetricsproviders.yaml | 4 ++-- .../controllers/analysis/provider_selector_test.go | 4 ++-- .../controllers/common/providers/common.go | 3 +++ .../controllers/common/providers/provider.go | 2 +- .../controllers/common/providers/provider_test.go | 5 +++++ 26 files changed, 58 insertions(+), 35 deletions(-) diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index 4a5f3dd6a4..c6cd093058 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -104,6 +104,7 @@ controlleroptions controllerutil coredns CORS +cortex coverpkg coverprofile cowsay diff --git a/.github/scripts/.helm-tests/default/result.yaml b/.github/scripts/.helm-tests/default/result.yaml index 30d989618e..e21fafa074 100644 --- a/.github/scripts/.helm-tests/default/result.yaml +++ b/.github/scripts/.helm-tests/default/result.yaml @@ -13614,8 +13614,8 @@ spec: type: string type: description: Type represents the provider type. This can be one of - prometheus, thanos, dynatrace, datadog, dql. - pattern: prometheus|thanos|dynatrace|datadog|dql + cortex, datadog, dql, dynatrace, prometheus or thanos. + pattern: cortex|datadog|dql|dynatrace|prometheus|thanos type: string required: - targetServer diff --git a/.github/scripts/.helm-tests/local-global-precedence/result.yaml b/.github/scripts/.helm-tests/local-global-precedence/result.yaml index de18970d6e..64bf02ec7b 100644 --- a/.github/scripts/.helm-tests/local-global-precedence/result.yaml +++ b/.github/scripts/.helm-tests/local-global-precedence/result.yaml @@ -13750,8 +13750,8 @@ spec: type: string type: description: Type represents the provider type. This can be one of - prometheus, thanos, dynatrace, datadog, dql. - pattern: prometheus|thanos|dynatrace|datadog|dql + cortex, datadog, dql, dynatrace, prometheus or thanos. + pattern: cortex|datadog|dql|dynatrace|prometheus|thanos type: string required: - targetServer diff --git a/.github/scripts/.helm-tests/metrics-only-with-apiservice-disabled/result.yaml b/.github/scripts/.helm-tests/metrics-only-with-apiservice-disabled/result.yaml index c8f07926fd..056994d8ad 100644 --- a/.github/scripts/.helm-tests/metrics-only-with-apiservice-disabled/result.yaml +++ b/.github/scripts/.helm-tests/metrics-only-with-apiservice-disabled/result.yaml @@ -2589,8 +2589,8 @@ spec: type: string type: description: Type represents the provider type. This can be one of - prometheus, thanos, dynatrace, datadog, dql. - pattern: prometheus|thanos|dynatrace|datadog|dql + cortex, datadog, dql, dynatrace, prometheus or thanos. + pattern: cortex|datadog|dql|dynatrace|prometheus|thanos type: string required: - targetServer diff --git a/.github/scripts/.helm-tests/metrics-only/result.yaml b/.github/scripts/.helm-tests/metrics-only/result.yaml index fda474e8df..9991950741 100644 --- a/.github/scripts/.helm-tests/metrics-only/result.yaml +++ b/.github/scripts/.helm-tests/metrics-only/result.yaml @@ -2589,8 +2589,8 @@ spec: type: string type: description: Type represents the provider type. This can be one of - prometheus, thanos, dynatrace, datadog, dql. - pattern: prometheus|thanos|dynatrace|datadog|dql + cortex, datadog, dql, dynatrace, prometheus or thanos. + pattern: cortex|datadog|dql|dynatrace|prometheus|thanos type: string required: - targetServer diff --git a/.github/scripts/.helm-tests/metrics-with-certs/result.yaml b/.github/scripts/.helm-tests/metrics-with-certs/result.yaml index 68ac633150..563f59d59f 100644 --- a/.github/scripts/.helm-tests/metrics-with-certs/result.yaml +++ b/.github/scripts/.helm-tests/metrics-with-certs/result.yaml @@ -2604,8 +2604,8 @@ spec: type: string type: description: Type represents the provider type. This can be one of - prometheus, thanos, dynatrace, datadog, dql. - pattern: prometheus|thanos|dynatrace|datadog|dql + cortex, datadog, dql, dynatrace, prometheus or thanos. + pattern: cortex|datadog|dql|dynatrace|prometheus|thanos type: string required: - targetServer diff --git a/docs/docs/assets/crd/examples/yaml-synopsis.yaml b/docs/docs/assets/crd/examples/yaml-synopsis.yaml index 030c1b20ea..96d659af15 100644 --- a/docs/docs/assets/crd/examples/yaml-synopsis.yaml +++ b/docs/docs/assets/crd/examples/yaml-synopsis.yaml @@ -4,7 +4,7 @@ metadata: name: namespace: spec: - type: prometheus | thanos | dynatrace | dql | datadog + type: cortex | datadog | dql | dynatrace | prometheus | thanos targetServer: "" secretKeyRef: name: diff --git a/docs/docs/components/metrics-operator.md b/docs/docs/components/metrics-operator.md index 37bcc98543..2f37cb5424 100644 --- a/docs/docs/components/metrics-operator.md +++ b/docs/docs/components/metrics-operator.md @@ -13,7 +13,7 @@ of the application and infrastructure. While Kubernetes has ways to extend its metrics APIs, there are limitations, especially that they allow you to use only a single observability platform -such as Prometheus, Thanos, Dynatrace or Datadog. +such as Prometheus, Thanos, Cortex, Dynatrace or Datadog. The Keptn Metrics Operator solves this problem by providing a single entry point for all your metrics data, regardless of its source. diff --git a/docs/docs/contribute/software/add-new-metric-provider.md b/docs/docs/contribute/software/add-new-metric-provider.md index 8dc2f6e86e..14a1732eb2 100644 --- a/docs/docs/contribute/software/add-new-metric-provider.md +++ b/docs/docs/contribute/software/add-new-metric-provider.md @@ -95,7 +95,7 @@ The steps to create your own metrics provider are: [line](https://github.com/keptn/lifecycle-toolkit/blob/main/metrics-operator/api/v1/keptnmetricsprovider_types.go#L29) to look like this - `// +kubebuilder:validation:Pattern:=prometheus|thanos|dynatrace|datadog|dql|placeholder`. + `// +kubebuilder:validation:Pattern:=cortex|datadog|dql|dynatrace|prometheus|thanos|placeholder`. In the metric-operator directory run `make generate manifests` to update the metrics-operator crd config Then modify the helm chart and the helm chart crd validation to match the update in the metrics-operator crd config diff --git a/docs/docs/core-concepts/index.md b/docs/docs/core-concepts/index.md index dfc7670b4a..88598917ef 100644 --- a/docs/docs/core-concepts/index.md +++ b/docs/docs/core-concepts/index.md @@ -33,7 +33,7 @@ The Keptn metrics feature extends the functionality of * Handles observability data from multiple instances of multiple observability solutions - – Prometheus, Thanos, Dynatrace, Datadog and others – + – Prometheus, Thanos, Cortex, Dynatrace, Datadog and others – as well as data that comes directly from your cloud provider such as AWS, Google, or Azure. diff --git a/docs/docs/getting-started/metrics.md b/docs/docs/getting-started/metrics.md index df6e272b76..976fec7b54 100644 --- a/docs/docs/getting-started/metrics.md +++ b/docs/docs/getting-started/metrics.md @@ -14,7 +14,7 @@ such as whether a rollout is good, or whether to scale up or down. Your observability data may come from multiple observability solutions -- -Prometheus, Thanos, Dynatrace, Datadog and others -- +Prometheus, Thanos, Cortex, Dynatrace, Datadog and others -- or may be data that comes directly from your cloud provider such as AWS, Google, or Azure. The Keptn Metrics Server unifies and standardizes access to all this data. diff --git a/docs/docs/installation/k8s.md b/docs/docs/installation/k8s.md index de18ebf234..5168b251b4 100644 --- a/docs/docs/installation/k8s.md +++ b/docs/docs/installation/k8s.md @@ -79,6 +79,7 @@ Your cluster should include the following: * At least one observability data provider such as [Prometheus](https://prometheus.io/), [Thanos](https://thanos.io/), + [Cortex](https://cortexmetrics.io/), [Dynatrace](https://www.dynatrace.com/), or [Datadog](https://www.datadoghq.com/); you can use multiple instances of different data providers. diff --git a/docs/docs/migrate/keptn/strategy.md b/docs/docs/migrate/keptn/strategy.md index 8c54a218ad..ad7441a352 100644 --- a/docs/docs/migrate/keptn/strategy.md +++ b/docs/docs/migrate/keptn/strategy.md @@ -269,7 +269,7 @@ Keptn v1 [SLIs](https://v1.keptn.sh/docs/1.0.x/reference/files/sli/) (Service Level Indicators) represent queries from the data provider -such as Prometheus, Thanos, Dynatrace, or Datadog, +such as Prometheus, Thanos, Cortex, Dynatrace, or Datadog, which is configured as a Keptn integration. When migrating to Keptn, you need to define a diff --git a/docs/docs/reference/api-reference/metrics/v1/index.md b/docs/docs/reference/api-reference/metrics/v1/index.md index 81bc85cbdc..aa2481fed2 100644 --- a/docs/docs/reference/api-reference/metrics/v1/index.md +++ b/docs/docs/reference/api-reference/metrics/v1/index.md @@ -373,7 +373,7 @@ _Appears in:_ | Field | Description | Default | Optional |Validation | | --- | --- | --- | --- | --- | -| `type` _string_ | Type represents the provider type. This can be one of prometheus, thanos, dynatrace, datadog, dql. || x | Optional: {}
Pattern: `prometheus|thanos|dynatrace|datadog|dql`
| +| `type` _string_ | Type represents the provider type. This can be one of cortex, datadog, dql, dynatrace, prometheus or thanos. || x | Optional: {}
Pattern: `cortex|datadog|dql|dynatrace|prometheus|thanos`
| | `targetServer` _string_ | TargetServer defines URL (including port and protocol) at which the metrics provider is reachable. || x | | | `secretKeyRef` _[SecretKeySelector](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#secretkeyselector-v1-core)_ | SecretKeyRef defines an optional secret for access credentials to the metrics provider. || ✓ | Optional: {}
| diff --git a/docs/docs/reference/crd-reference/analysisvaluetemplate.md b/docs/docs/reference/crd-reference/analysisvaluetemplate.md index 5284d38631..ffeee309ae 100644 --- a/docs/docs/reference/crd-reference/analysisvaluetemplate.md +++ b/docs/docs/reference/crd-reference/analysisvaluetemplate.md @@ -20,7 +20,7 @@ metadata: namespace: spec: provider: - name: prometheus | thanos | dynatrace | dql | datadog + name: cortex | datadog | dql | dynatrace | prometheus | thanos query: ``` diff --git a/docs/docs/reference/crd-reference/evaluationdefinition.md b/docs/docs/reference/crd-reference/evaluationdefinition.md index f8d8c222a4..bd2d8ea3b5 100644 --- a/docs/docs/reference/crd-reference/evaluationdefinition.md +++ b/docs/docs/reference/crd-reference/evaluationdefinition.md @@ -116,12 +116,12 @@ that are now taken from the specified [KeptnMetric](metric.md) CRD. The synopsis was: ```yaml -apiVersion: lifecycle.keptn.sh/v1 +apiVersion: lifecycle.keptn.sh/v1alpha2 kind: KeptnEvaluationDefinition metadata: name: spec: - source: prometheus | dynatrace | datadog | thanos + source: datadog | dynatrace | prometheus objectives: - name: query-1 query: "xxxx" diff --git a/docs/docs/reference/crd-reference/metricsprovider.md b/docs/docs/reference/crd-reference/metricsprovider.md index f8a35a3b77..d61fb52874 100644 --- a/docs/docs/reference/crd-reference/metricsprovider.md +++ b/docs/docs/reference/crd-reference/metricsprovider.md @@ -5,7 +5,7 @@ comments: true # KeptnMetricsProvider A `KeptnMetricsProvider` resource defines an instance of a data provider -(such as Prometheus, Thanos, Dynatrace, or Datadog) +(such as Prometheus, Thanos, Cortex, Dynatrace, or Datadog) that is used by one or more [KeptnMetric](metric.md) resources. One Keptn application can perform @@ -90,9 +90,9 @@ For detailed information please look at the [Examples section](#examples). -=== "Prometheus and Thanos" +=== "Prometheus, Cortex and Thanos" - An example of Prometheus as a metrics provider with a Secret holding + An example of Prometheus, Thanos or Cortex as a metrics provider with a Secret holding the authentication data looks like the following: ```yaml @@ -129,7 +129,7 @@ For detailed information please look at the [Examples section](#examples). > **Note** When using Dynatrace as metrics provider you can define the key name of your DT token stored in a secret, - which is not possible for Datadog, Prometheus or Thanos. + which is not possible for Datadog, Prometheus, Cortex or Thanos. For this example `myCustomTokenKey` was used. diff --git a/docs/docs/use-cases/non-k8s.md b/docs/docs/use-cases/non-k8s.md index 76fd136643..cddcfd40be 100644 --- a/docs/docs/use-cases/non-k8s.md +++ b/docs/docs/use-cases/non-k8s.md @@ -179,13 +179,13 @@ similar to what the metrics evaluations of the Keptn v1 quality gates feature provided. The data used can come from multiple instances of multiple data providers -(such as Prometheus, Thanos, Dynatrace, and DataDog). +(such as Prometheus, Thanos, Cortex, Dynatrace, and DataDog). A Keptn analysis can be run for any application running anywhere as long Keptn can access a monitoring provider endpoint that serves metrics for the application. You can point to multiple instances of the supported monitoring providers -(Prometheus, Thanos, Dynatrace, Datadog, and dql) +(Prometheus, Thanos, Cortex, Dynatrace, Datadog, and dql) so the application itself can run anywhere. To implement a Keptn analysis for your deployment: diff --git a/metrics-operator/api/v1/keptnmetricsprovider_types.go b/metrics-operator/api/v1/keptnmetricsprovider_types.go index 3ea2eb91ab..ad2537cd48 100644 --- a/metrics-operator/api/v1/keptnmetricsprovider_types.go +++ b/metrics-operator/api/v1/keptnmetricsprovider_types.go @@ -26,8 +26,8 @@ import ( // KeptnMetricsProviderSpec defines the desired state of KeptnMetricsProvider type KeptnMetricsProviderSpec struct { // +kubebuilder:validation:Optional - // +kubebuilder:validation:Pattern:=prometheus|thanos|dynatrace|datadog|dql - // Type represents the provider type. This can be one of prometheus, thanos, dynatrace, datadog, dql. + // +kubebuilder:validation:Pattern:=cortex|datadog|dql|dynatrace|prometheus|thanos + // Type represents the provider type. This can be one of cortex, datadog, dql, dynatrace, prometheus or thanos. Type string `json:"type"` // TargetServer defines URL (including port and protocol) at which the metrics provider is reachable. TargetServer string `json:"targetServer"` diff --git a/metrics-operator/api/v1/keptnmetricsprovider_types_test.go b/metrics-operator/api/v1/keptnmetricsprovider_types_test.go index d799e25496..f7e8909246 100644 --- a/metrics-operator/api/v1/keptnmetricsprovider_types_test.go +++ b/metrics-operator/api/v1/keptnmetricsprovider_types_test.go @@ -44,6 +44,19 @@ func TestKeptnMetricsProvider_GetType(t *testing.T) { }, want: "thanos", }, + { + name: "cortex provider type set", + fields: fields{ + ObjectMeta: metav1.ObjectMeta{ + Name: "provider1", + }, + Spec: KeptnMetricsProviderSpec{ + Type: "cortex", + TargetServer: "", + }, + }, + want: "cortex", + }, { name: "provider type not set, should return name", fields: fields{ diff --git a/metrics-operator/chart/templates/keptnmetricsprovider-crd.yaml b/metrics-operator/chart/templates/keptnmetricsprovider-crd.yaml index 7f5d5e220b..4ce5b9db54 100644 --- a/metrics-operator/chart/templates/keptnmetricsprovider-crd.yaml +++ b/metrics-operator/chart/templates/keptnmetricsprovider-crd.yaml @@ -77,8 +77,8 @@ spec: type: string type: description: Type represents the provider type. This can be one of - prometheus, thanos, dynatrace, datadog, dql. - pattern: prometheus|thanos|dynatrace|datadog|dql + cortex, datadog, dql, dynatrace, prometheus or thanos. + pattern: cortex|datadog|dql|dynatrace|prometheus|thanos type: string required: - targetServer diff --git a/metrics-operator/config/crd/bases/metrics.keptn.sh_keptnmetricsproviders.yaml b/metrics-operator/config/crd/bases/metrics.keptn.sh_keptnmetricsproviders.yaml index 8fdbe0aba0..31b8677afc 100644 --- a/metrics-operator/config/crd/bases/metrics.keptn.sh_keptnmetricsproviders.yaml +++ b/metrics-operator/config/crd/bases/metrics.keptn.sh_keptnmetricsproviders.yaml @@ -69,8 +69,8 @@ spec: type: string type: description: Type represents the provider type. This can be one of - prometheus, thanos, dynatrace, datadog, dql. - pattern: prometheus|thanos|dynatrace|datadog|dql + cortex, datadog, dql, dynatrace, prometheus or thanos. + pattern: cortex|datadog|dql|dynatrace|prometheus|thanos type: string required: - targetServer diff --git a/metrics-operator/controllers/analysis/provider_selector_test.go b/metrics-operator/controllers/analysis/provider_selector_test.go index 46736eb5cd..d246595dd5 100644 --- a/metrics-operator/controllers/analysis/provider_selector_test.go +++ b/metrics-operator/controllers/analysis/provider_selector_test.go @@ -246,7 +246,7 @@ func TestProvidersPool(t *testing.T) { func TestProvidersPool_StartProviders(t *testing.T) { - numJobs := 4 + numJobs := 6 ctx, cancel := context.WithCancel(context.Background()) resChan := make(chan metricsapi.ProviderResult) // Create a mock IObjectivesEvaluator, Client, and Logger for testing @@ -273,7 +273,7 @@ func TestProvidersPool_StartProviders(t *testing.T) { time.Sleep(time.Millisecond * 100) // Assert the expected number of workers (goroutines) were started - require.Equal(t, 4, len(pool.providers)) + require.Equal(t, 6, len(pool.providers)) require.Equal(t, numJobs, cap(pool.providers["prometheus"])) // Stop the providers after testing pool.StopProviders() diff --git a/metrics-operator/controllers/common/providers/common.go b/metrics-operator/controllers/common/providers/common.go index 978a3e4a1f..d59e381c12 100644 --- a/metrics-operator/controllers/common/providers/common.go +++ b/metrics-operator/controllers/common/providers/common.go @@ -4,6 +4,7 @@ const DynatraceProviderType = "dynatrace" const DynatraceDQLProviderType = "dql" const PrometheusProviderType = "prometheus" const ThanosProviderType = "thanos" +const CortexProviderType = "cortex" const DataDogProviderType = "datadog" var SupportedProviders = []string{ @@ -11,4 +12,6 @@ var SupportedProviders = []string{ DynatraceDQLProviderType, PrometheusProviderType, DataDogProviderType, + CortexProviderType, + ThanosProviderType, } diff --git a/metrics-operator/controllers/common/providers/provider.go b/metrics-operator/controllers/common/providers/provider.go index 3055dc4df5..f2164aec0f 100644 --- a/metrics-operator/controllers/common/providers/provider.go +++ b/metrics-operator/controllers/common/providers/provider.go @@ -29,7 +29,7 @@ type ProviderFactory func(providerType string, log logr.Logger, k8sClient client func NewProvider(providerType string, log logr.Logger, k8sClient client.Client) (KeptnSLIProvider, error) { switch strings.ToLower(providerType) { - case PrometheusProviderType, ThanosProviderType: + case PrometheusProviderType, ThanosProviderType, CortexProviderType: return prometheus.NewPrometheusProvider(log, k8sClient), nil case DynatraceProviderType: return &dynatrace.KeptnDynatraceProvider{ diff --git a/metrics-operator/controllers/common/providers/provider_test.go b/metrics-operator/controllers/common/providers/provider_test.go index 6a714094df..08f2aac738 100644 --- a/metrics-operator/controllers/common/providers/provider_test.go +++ b/metrics-operator/controllers/common/providers/provider_test.go @@ -27,6 +27,11 @@ func TestFactory(t *testing.T) { provider: &prometheus.KeptnPrometheusProvider{}, err: false, }, + { + providerType: CortexProviderType, + provider: &prometheus.KeptnPrometheusProvider{}, + err: false, + }, { providerType: DynatraceProviderType, provider: &dynatrace.KeptnDynatraceProvider{},