Skip to content

Commit

Permalink
Merge pull request #135 from appuio/add/appuio-managed-kubernetes
Browse files Browse the repository at this point in the history
Add vCPU query for APPUiO Managed Kubernetes
  • Loading branch information
CLNRMN authored Apr 25, 2023
2 parents 4486f57 + defa77f commit 9c88303
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
9 changes: 9 additions & 0 deletions pkg/db/seeds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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{
Expand Down
36 changes: 36 additions & 0 deletions pkg/db/seeds/appuio_managed_kubernetes_vcpu.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_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]
)
48 changes: 48 additions & 0 deletions pkg/db/seeds/promtest/appuio_managed_kubernetes_vcpu.jsonnet
Original file line number Diff line number Diff line change
@@ -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,
},
]
),

],
}
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 := 8
expQueryNum := 9

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

0 comments on commit 9c88303

Please sign in to comment.