From 850556eac90691d418b9295204644dd4e81ada40 Mon Sep 17 00:00:00 2001 From: clnrmn Date: Tue, 18 Apr 2023 15:49:37 +0200 Subject: [PATCH 1/3] Add APPUiO Managed Kubernetes --- pkg/db/seeds.go | 9 ++++ .../appuio_managed_kubernetes_vcpu.promql | 35 ++++++++++++++ .../appuio_managed_kubernetes_vcpu.jsonnet | 48 +++++++++++++++++++ .../appuio_managed_openshift_vcpu.jsonnet | 2 +- pkg/db/seeds_test.go | 2 +- 5 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 pkg/db/seeds/appuio_managed_kubernetes_vcpu.promql create mode 100644 pkg/db/seeds/promtest/appuio_managed_kubernetes_vcpu.jsonnet diff --git a/pkg/db/seeds.go b/pkg/db/seeds.go index 3bbab55..b75c431 100644 --- a/pkg/db/seeds.go +++ b/pkg/db/seeds.go @@ -29,6 +29,9 @@ var appuioCloudPersistentStorageQuery string //go:embed seeds/appuio_managed_openshift_vcpu.promql var appuioManagedOpenShiftvCPUQuery string +//go:embed seeds/appuio_managed_kubernetes_vcpu.promql +var appuioManagedKubernetesvCPUQuery string + //go:embed seeds/appcat_vshn.promql.tmpl var appcatVSHNTemplate string @@ -71,6 +74,12 @@ var DefaultQueries = []Query{ Query: appuioManagedOpenShiftvCPUQuery, Unit: "vCPU", }, + { + Name: "appuio_managed_kubernetes_vcpu", + Description: "vCPU aggregated by cluster, node (app, storage), and service level", + Query: appuioManagedKubernetesvCPUQuery, + Unit: "vCPU", + }, } var renderedQueries = []RenderedQuery{ diff --git a/pkg/db/seeds/appuio_managed_kubernetes_vcpu.promql b/pkg/db/seeds/appuio_managed_kubernetes_vcpu.promql new file mode 100644 index 0000000..6972445 --- /dev/null +++ b/pkg/db/seeds/appuio_managed_kubernetes_vcpu.promql @@ -0,0 +1,35 @@ +# Calculates vCPUs for app nodes of a cluster +# Structure of resulting product label "query:cluster:tenant::class" + +# Max values over one hour. +max_over_time( + # Add the final product label by joining the base product with the cluster ID, the tenant, and the service class. + label_join( + label_join( + label_replace( + # Add the base product identifier. + label_replace( + sum by (cluster_id, vshn_service_level, tenant_id) (min without(prometheus_replica) (node_cpu_info)), + "product", + "appuio_managed_kubernetes_vcpu", + "", + ".*" + ), + "class", + "$1", + "vshn_service_level", + "(.*)" + ), + "product", + ":", + "product", + "cluster_id", + "tenant_id", + "class" + ), + "category", + ":", + "tenant_id", + "cluster_id" + )[59m:1m] +) diff --git a/pkg/db/seeds/promtest/appuio_managed_kubernetes_vcpu.jsonnet b/pkg/db/seeds/promtest/appuio_managed_kubernetes_vcpu.jsonnet new file mode 100644 index 0000000..83df9a6 --- /dev/null +++ b/pkg/db/seeds/promtest/appuio_managed_kubernetes_vcpu.jsonnet @@ -0,0 +1,48 @@ +local c = import 'common.libsonnet'; + +local query = importstr '../appuio_managed_kubernetes_vcpu.promql'; + +local commonLabels = { + cluster_id: 'c-managed-kubernetes', + tenant_id: 't-managed-kubernetes', + vshn_service_level: 'standard', +}; + +local baseSeries = { + appNodeCPUInfoLabel0: c.series('node_cpu_info', commonLabels { + instance: 'app-test', + cpu: '0', + }, '1x120'), + appNodeCPUInfoLabel1: c.series('node_cpu_info', commonLabels { + instance: 'app-test', + cpu: '1', + }, '1x120'), + appNodeCPUInfoLabel2: c.series('node_cpu_info', commonLabels { + instance: 'app-test2', + cpu: '0', + }, '1x120'), +}; + +local baseCalculatedLabels = commonLabels { + class: super.vshn_service_level, + category: super.tenant_id + ':' + super.cluster_id, +}; + +{ + tests: [ + c.test( + 'two app CPUs and one storage CPU', + baseSeries, + query, + [ + { + labels: c.formatLabels(baseCalculatedLabels { + product: 'appuio_managed_kubernetes_vcpu:c-managed-kubernetes:t-managed-kubernetes:standard', + }), + value: 3, + }, + ] + ), + + ], +} diff --git a/pkg/db/seeds/promtest/appuio_managed_openshift_vcpu.jsonnet b/pkg/db/seeds/promtest/appuio_managed_openshift_vcpu.jsonnet index 1b7daae..82d6b1d 100644 --- a/pkg/db/seeds/promtest/appuio_managed_openshift_vcpu.jsonnet +++ b/pkg/db/seeds/promtest/appuio_managed_openshift_vcpu.jsonnet @@ -20,7 +20,7 @@ local baseSeries = { }, '1x120'), appNodeCPUInfoLabel1: c.series('node_cpu_info', commonLabels { instance: 'app-test', - core: '1', + core: '2', }, '1x120'), storageNodeRoleLabel: c.series('kube_node_role', commonLabels { diff --git a/pkg/db/seeds_test.go b/pkg/db/seeds_test.go index a6c7191..0d55dda 100644 --- a/pkg/db/seeds_test.go +++ b/pkg/db/seeds_test.go @@ -22,7 +22,7 @@ func (s *SeedsTestSuite) TestSeedDefaultQueries() { _, err := d.Exec("DELETE FROM queries") require.NoError(t, err) - expQueryNum := 8 + expQueryNum := 9 count := "SELECT COUNT(*) FROM queries" requireQueryEqual(t, d, 0, count) From e317208194960575e6f897b3bbd25509e778be8a Mon Sep 17 00:00:00 2001 From: clnrmn Date: Wed, 19 Apr 2023 09:03:07 +0200 Subject: [PATCH 2/3] revert core changes --- pkg/db/seeds/promtest/appuio_managed_openshift_vcpu.jsonnet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/db/seeds/promtest/appuio_managed_openshift_vcpu.jsonnet b/pkg/db/seeds/promtest/appuio_managed_openshift_vcpu.jsonnet index 82d6b1d..1b7daae 100644 --- a/pkg/db/seeds/promtest/appuio_managed_openshift_vcpu.jsonnet +++ b/pkg/db/seeds/promtest/appuio_managed_openshift_vcpu.jsonnet @@ -20,7 +20,7 @@ local baseSeries = { }, '1x120'), appNodeCPUInfoLabel1: c.series('node_cpu_info', commonLabels { instance: 'app-test', - core: '2', + core: '1', }, '1x120'), storageNodeRoleLabel: c.series('kube_node_role', commonLabels { From defa77f92de9948f8473f2bbdddff5aa1f0e3134 Mon Sep 17 00:00:00 2001 From: clnrmn Date: Mon, 24 Apr 2023 16:11:14 +0200 Subject: [PATCH 3/3] Adjust PromQL to have the correct product format --- pkg/db/seeds/appuio_managed_kubernetes_vcpu.promql | 1 + pkg/db/seeds/promtest/appuio_managed_kubernetes_vcpu.jsonnet | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/db/seeds/appuio_managed_kubernetes_vcpu.promql b/pkg/db/seeds/appuio_managed_kubernetes_vcpu.promql index 6972445..22c0fdb 100644 --- a/pkg/db/seeds/appuio_managed_kubernetes_vcpu.promql +++ b/pkg/db/seeds/appuio_managed_kubernetes_vcpu.promql @@ -25,6 +25,7 @@ max_over_time( "product", "cluster_id", "tenant_id", + "place_holder", "class" ), "category", diff --git a/pkg/db/seeds/promtest/appuio_managed_kubernetes_vcpu.jsonnet b/pkg/db/seeds/promtest/appuio_managed_kubernetes_vcpu.jsonnet index 83df9a6..700405c 100644 --- a/pkg/db/seeds/promtest/appuio_managed_kubernetes_vcpu.jsonnet +++ b/pkg/db/seeds/promtest/appuio_managed_kubernetes_vcpu.jsonnet @@ -37,7 +37,7 @@ local baseCalculatedLabels = commonLabels { [ { labels: c.formatLabels(baseCalculatedLabels { - product: 'appuio_managed_kubernetes_vcpu:c-managed-kubernetes:t-managed-kubernetes:standard', + product: 'appuio_managed_kubernetes_vcpu:c-managed-kubernetes:t-managed-kubernetes::standard', }), value: 3, },