Skip to content

Commit

Permalink
Add vCPU query for APPUiO Managed OpenShift
Browse files Browse the repository at this point in the history
  • Loading branch information
anothertobi authored and bastjan committed Mar 8, 2023
1 parent 562ae0e commit 536cdf2
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 1 deletion.
18 changes: 18 additions & 0 deletions pkg/db/seeds.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ 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/appcat_postgresql_vshn_standalone.promql
var appcatPostgresqlVSHNStandalone string

Expand Down Expand Up @@ -60,6 +66,18 @@ var DefaultQueries = []Query{
Query: appuioCloudPersistentStorageQuery,
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,
Unit: "vCPU",
},
{
Name: "appcat_postgresql_vshn_standalone",
Description: "Number of VSHN managed standalone postgres instances",
Expand Down
36 changes: 36 additions & 0 deletions pkg/db/seeds/appuio_managed_openshift_vcpu_app.promql
Original file line number Diff line number Diff line change
@@ -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_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="app"})), "instance", "", "node")
),
"product",
"appuio_managed_openshift_vcpu_app",
"product",
".*"
),
"class",
"$1",
"vshn_service_level",
"(.*)"
),
"product",
":",
"product",
"cluster_id",
"tenant_id",
"empty", # empty namespace
"class"
)[59m:1m]
)
36 changes: 36 additions & 0 deletions pkg/db/seeds/appuio_managed_openshift_vcpu_storage.promql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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]
)
2 changes: 1 addition & 1 deletion pkg/db/seeds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (s *SeedsTestSuite) TestSeedDefaultQueries() {
_, err := d.Exec("DELETE FROM queries")
require.NoError(t, err)

expQueryNum := 6
expQueryNum := 7

count := "SELECT COUNT(*) FROM queries"
requireQueryEqual(t, d, 0, count)
Expand Down

0 comments on commit 536cdf2

Please sign in to comment.