From 4d82c640df5864c001b5ce3d48e109b4dff5482f Mon Sep 17 00:00:00 2001 From: Sebastian Widmer Date: Fri, 23 Dec 2022 16:13:03 +0100 Subject: [PATCH 1/2] Add namespace label fix to subqueries too --- pkg/db/seeds/appuio_cloud_memory_sub_cpu.promql | 16 +++++++++++----- .../seeds/appuio_cloud_memory_sub_memory.promql | 16 +++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/pkg/db/seeds/appuio_cloud_memory_sub_cpu.promql b/pkg/db/seeds/appuio_cloud_memory_sub_cpu.promql index aaa5f21..e53f6e6 100644 --- a/pkg/db/seeds/appuio_cloud_memory_sub_cpu.promql +++ b/pkg/db/seeds/appuio_cloud_memory_sub_cpu.promql @@ -33,11 +33,17 @@ sum_over_time( # Join namespace label `label_appuio_io_organization` as `tenant_id`. on(cluster_id, namespace) group_left(tenant_id) - label_replace( - kube_namespace_labels{label_appuio_io_organization=~".+"}, - "tenant_id", - "$1", - "label_appuio_io_organization", "(.*)" + ( + bottomk(1, + min by (cluster_id, namespace, tenant_id) ( + label_replace( + kube_namespace_labels{label_appuio_io_organization=~".+"}, + "tenant_id", + "$1", + "label_appuio_io_organization", "(.*)" + ) + ) + ) by(cluster_id, namespace) ), # At least return 0 0 diff --git a/pkg/db/seeds/appuio_cloud_memory_sub_memory.promql b/pkg/db/seeds/appuio_cloud_memory_sub_memory.promql index 85f80bb..effae88 100644 --- a/pkg/db/seeds/appuio_cloud_memory_sub_memory.promql +++ b/pkg/db/seeds/appuio_cloud_memory_sub_memory.promql @@ -28,11 +28,17 @@ sum_over_time( # Join namespace label `label_appuio_io_organization` as `tenant_id`. on(cluster_id, namespace) group_left(tenant_id) - label_replace( - kube_namespace_labels{label_appuio_io_organization=~".+"}, - "tenant_id", - "$1", - "label_appuio_io_organization", "(.*)" + ( + bottomk(1, + min by (cluster_id, namespace, tenant_id) ( + label_replace( + kube_namespace_labels{label_appuio_io_organization=~".+"}, + "tenant_id", + "$1", + "label_appuio_io_organization", "(.*)" + ) + ) + ) by(cluster_id, namespace) ), "product", "appuio_cloud_memory", From 9cd3cfc3657a30736f2cee7b6ec2bd53b0ce3a9c Mon Sep 17 00:00:00 2001 From: Sebastian Widmer Date: Fri, 23 Dec 2022 16:13:29 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Make=20queries=20easier=20to=20insert=20by?= =?UTF-8?q?=20hand=20=F0=9F=99=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/db/seeds/appuio_cloud_memory.promql | 2 +- pkg/db/seeds/appuio_cloud_memory_sub_cpu.promql | 2 +- pkg/db/seeds/appuio_cloud_memory_sub_memory.promql | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/db/seeds/appuio_cloud_memory.promql b/pkg/db/seeds/appuio_cloud_memory.promql index de4f598..112a36d 100644 --- a/pkg/db/seeds/appuio_cloud_memory.promql +++ b/pkg/db/seeds/appuio_cloud_memory.promql @@ -1,7 +1,7 @@ # Sum values over one hour. sum_over_time( # Average over a one-minute time frame. - # NOTE: This is a sliding window. Results vary based on the queries' execution time. + # NOTE: This is a sliding window. Results vary based on the queries execution time. avg_over_time( # Add the final product label by joining the base product with the cluster ID, the tenant and the namespace. label_join( diff --git a/pkg/db/seeds/appuio_cloud_memory_sub_cpu.promql b/pkg/db/seeds/appuio_cloud_memory_sub_cpu.promql index e53f6e6..7e1d425 100644 --- a/pkg/db/seeds/appuio_cloud_memory_sub_cpu.promql +++ b/pkg/db/seeds/appuio_cloud_memory_sub_cpu.promql @@ -3,7 +3,7 @@ # Sum values over one hour. sum_over_time( # Average over a one-minute time frame. - # NOTE: This is a sliding window. Results vary based on the queries' execution time. + # NOTE: This is a sliding window. Results vary based on the queries execution time. avg_over_time( # Add the final product label by joining the base product with the cluster ID, the tenant and the namespace. label_join( diff --git a/pkg/db/seeds/appuio_cloud_memory_sub_memory.promql b/pkg/db/seeds/appuio_cloud_memory_sub_memory.promql index effae88..c83e3ca 100644 --- a/pkg/db/seeds/appuio_cloud_memory_sub_memory.promql +++ b/pkg/db/seeds/appuio_cloud_memory_sub_memory.promql @@ -3,7 +3,7 @@ # Sum values over one hour. sum_over_time( # Average over a one-minute time frame. - # NOTE: This is a sliding window. Results vary based on the queries' execution time. + # NOTE: This is a sliding window. Results vary based on the queries execution time. avg_over_time( # Add the final product label by joining the base product with the cluster ID, the tenant and the namespace. label_join(