From 62c70b8b3888344a2b3814dc8752038893b8b938 Mon Sep 17 00:00:00 2001 From: Sebastian Widmer Date: Wed, 8 Mar 2023 15:40:31 +0100 Subject: [PATCH] Tests and query unification --- pkg/db/seeds.go | 19 ++---- ...l => appuio_managed_openshift_vcpu.promql} | 16 +++-- ...puio_managed_openshift_vcpu_storage.promql | 36 ----------- .../appuio_managed_openshift_vcpu.jsonnet | 64 +++++++++++++++++++ 4 files changed, 79 insertions(+), 56 deletions(-) rename pkg/db/seeds/{appuio_managed_openshift_vcpu_app.promql => appuio_managed_openshift_vcpu.promql} (74%) delete mode 100644 pkg/db/seeds/appuio_managed_openshift_vcpu_storage.promql create mode 100644 pkg/db/seeds/promtest/appuio_managed_openshift_vcpu.jsonnet diff --git a/pkg/db/seeds.go b/pkg/db/seeds.go index a0a55be..ea1e470 100644 --- a/pkg/db/seeds.go +++ b/pkg/db/seeds.go @@ -24,11 +24,8 @@ var appuioCloudLoadbalancerQuery string //go:embed seeds/appuio_cloud_persistent_storage.promql var appuioCloudPersistentStorageQuery string -//go:embed seeds/appuio_managed_openshift_vcpu_app.promql -var appuioManagedOpenShiftvCPUAppQuery string - -//go:embed seeds/appuio_managed_openshift_vcpu_storage.promql -var appuioManagedOpenShiftvCPUStorageQuery string +//go:embed seeds/appuio_managed_openshift_vcpu.promql +var appuioManagedOpenShiftvCPUQuery string //go:embed seeds/appcat_postgresql_vshn_standalone.promql var appcatPostgresqlVSHNStandalone string @@ -67,15 +64,9 @@ var DefaultQueries = []Query{ Unit: "GiB", }, { - Name: "appuio_managed_openshift_vcpu_app", - Description: "vCPU aggregated by cluster and service level for app nodes", - Query: appuioManagedOpenShiftvCPUAppQuery, - Unit: "vCPU", - }, - { - Name: "appuio_managed_openshift_vcpu_app", - Description: "vCPU aggregated by cluster and service level for storage nodes", - Query: appuioManagedOpenShiftvCPUStorageQuery, + Name: "appuio_managed_openshift_vcpu", + Description: "vCPU aggregated by cluster, node (app, storage), and service level", + Query: appuioManagedOpenShiftvCPUQuery, Unit: "vCPU", }, { diff --git a/pkg/db/seeds/appuio_managed_openshift_vcpu_app.promql b/pkg/db/seeds/appuio_managed_openshift_vcpu.promql similarity index 74% rename from pkg/db/seeds/appuio_managed_openshift_vcpu_app.promql rename to pkg/db/seeds/appuio_managed_openshift_vcpu.promql index abebfd5..dc4c888 100644 --- a/pkg/db/seeds/appuio_managed_openshift_vcpu_app.promql +++ b/pkg/db/seeds/appuio_managed_openshift_vcpu.promql @@ -8,17 +8,21 @@ max_over_time( label_replace( # Add the base product identifier. label_replace( - sum by(cluster_id, vshn_service_level, tenant_id) ( + sum by(cluster_id, vshn_service_level, tenant_id, role) ( sum by (tenant_id, cluster_id, instance, vshn_service_level) ( min without(prometheus_replica) (node_cpu_info) - ) * on (tenant_id, cluster_id, instance, vshn_service_level) + ) * on (tenant_id, cluster_id, instance, vshn_service_level) group_left(role) label_join( - (group without(prometheus_replica) (kube_node_role{role="app"})), "instance", "", "node") + (group without(prometheus_replica) (kube_node_role{role=~"app|storage"})), + "instance", + "", + "node" + ) ), "product", - "appuio_managed_openshift_vcpu_app", - "product", - ".*" + "appuio_managed_openshift_vcpu_$1", + "role", + "(.*)" ), "class", "$1", diff --git a/pkg/db/seeds/appuio_managed_openshift_vcpu_storage.promql b/pkg/db/seeds/appuio_managed_openshift_vcpu_storage.promql deleted file mode 100644 index 05d5e5e..0000000 --- a/pkg/db/seeds/appuio_managed_openshift_vcpu_storage.promql +++ /dev/null @@ -1,36 +0,0 @@ -# Calculates vCPUs for storage 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_replace( - # Add the base product identifier. - label_replace( - sum by(cluster_id, vshn_service_level, tenant_id) ( - sum by (tenant_id, cluster_id, instance, vshn_service_level) ( - min without(prometheus_replica) (node_cpu_info) - ) * on (tenant_id, cluster_id, instance, vshn_service_level) - label_join( - (group without(prometheus_replica) (kube_node_role{role="storage"})), "instance", "", "node") - ), - "product", - "appuio_managed_openshift_vcpu_storage", - "product", - ".*" - ), - "class", - "$1", - "vshn_service_level", - "(.*)" - ), - "product", - ":", - "product", - "cluster_id", - "tenant_id", - "empty", # empty namespace - "class" - )[59m:1m] -) diff --git a/pkg/db/seeds/promtest/appuio_managed_openshift_vcpu.jsonnet b/pkg/db/seeds/promtest/appuio_managed_openshift_vcpu.jsonnet new file mode 100644 index 0000000..0ddf8d4 --- /dev/null +++ b/pkg/db/seeds/promtest/appuio_managed_openshift_vcpu.jsonnet @@ -0,0 +1,64 @@ +local c = import 'common.libsonnet'; + +local query = importstr '../appuio_managed_openshift_vcpu.promql'; + +local commonLabels = { + cluster_id: 'c-managed-openshift', + tenant_id: 't-managed-openshift', + vshn_service_level: 'ondemand', +}; + +local baseSeries = { + appNodeRoleLabel: c.series('kube_node_role', commonLabels { + node: 'app-test', + role: 'app', + }, '1x120'), + + appNodeCPUInfoLabel0: c.series('node_cpu_info', commonLabels { + instance: 'app-test', + core: '0', + }, '1x120'), + appNodeCPUInfoLabel1: c.series('node_cpu_info', commonLabels { + instance: 'app-test', + core: '1', + }, '1x120'), + + storageNodeRoleLabel: c.series('kube_node_role', commonLabels { + node: 'storage-test', + role: 'storage', + }, '1x120'), + + storageNodeCPUInfoLabel0: c.series('node_cpu_info', commonLabels { + instance: 'storage-test', + core: '0', + }, '1x120'), +}; + +{ + tests: [ + c.test( + 'two app CPUs and one storage CPU', + baseSeries, + query, + [ + { + labels: c.formatLabels(commonLabels { + class: super.vshn_service_level, + role: 'app', + product: 'appuio_managed_openshift_vcpu_app:c-managed-openshift:t-managed-openshift::ondemand', + }), + value: 2, + }, + { + labels: c.formatLabels(commonLabels { + class: super.vshn_service_level, + role: 'storage', + product: 'appuio_managed_openshift_vcpu_storage:c-managed-openshift:t-managed-openshift::ondemand', + }), + value: 1, + }, + ] + ), + + ], +}