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..22c0fdb --- /dev/null +++ b/pkg/db/seeds/appuio_managed_kubernetes_vcpu.promql @@ -0,0 +1,36 @@ +# 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", + "place_holder", + "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..700405c --- /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_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)