Skip to content

Commit

Permalink
Fix query on PV info change (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastjan committed Dec 22, 2022
1 parent ef013b3 commit 3b62d22
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pkg/db/seeds/appuio_cloud_persistent_storage.promql
Expand Up @@ -26,12 +26,14 @@ sum_over_time(
on (cluster_id,persistentvolume)
group_left(storageclass)
# Do not differantiate between regular and encrypted storage class versions.
label_replace(
kube_persistentvolume_info,
"storageclass",
"$1",
"storageclass",
"([^-]+)-encrypted"
min by (cluster_id, persistentvolume, storageclass) (
label_replace(
kube_persistentvolume_info,
"storageclass",
"$1",
"storageclass",
"([^-]+)-encrypted"
)
)
*
# Join the namespace label to get the tenant
Expand Down
78 changes: 78 additions & 0 deletions pkg/db/seeds/promtest/appuio_cloud_persistent_storage.jsonnet
@@ -0,0 +1,78 @@
local c = import 'common.libsonnet';

local query = importstr '../appuio_cloud_persistent_storage.promql';

local commonLabels = {
cluster_id: 'c-appuio-cloudscale-lpg-2',
tenant_id: 'c-appuio-cloudscale-lpg-2',
};

// One pvc, minimal (=1 byte) request
// 10 samples
local baseSeries = {
testprojectNamespaceOrgLabel: c.series('kube_namespace_labels', commonLabels {
namespace: 'testproject',
label_appuio_io_organization: 'cherry-pickers-inc',
}, '1x10'),

local pvcID = 'pvc-da01b12d-2e31-44da-8312-f91169256221',
pvCapacity: c.series('kube_persistentvolume_capacity_bytes', commonLabels {
persistentvolume: pvcID,
}, '1x10'),
pvInfo: c.series('kube_persistentvolume_info', commonLabels {
persistentvolume: pvcID,
storageclass: 'ssd',
}, '1x10'),
pvcRef: c.series('kube_persistentvolume_claim_ref', commonLabels {
claim_namespace: 'testproject',
name: 'important-database',
persistentvolume: pvcID,
}, '1x10'),
};

local baseCalculatedLabels = {
category: 'c-appuio-cloudscale-lpg-2:testproject',
cluster_id: 'c-appuio-cloudscale-lpg-2',
namespace: 'testproject',
product: 'appuio_cloud_persistent_storage:c-appuio-cloudscale-lpg-2:cherry-pickers-inc:testproject:ssd',
storageclass: 'ssd',
tenant_id: 'cherry-pickers-inc',
};

{
tests: [
c.test('minimal PVC',
baseSeries,
query,
{
labels: c.formatLabels(baseCalculatedLabels),
value: 10,
}),
c.test('higher than 1GiB request',
baseSeries {
pvCapacity+: {
values: '%sx10' % (5 * 1024 * 1024 * 1024),
},
},
query,
{
labels: c.formatLabels(baseCalculatedLabels),
value: 5 * 10,
}),

c.test('unrelated kube_persistentvolume_info changes do not throw errors - there is an overlap since series go stale only after a few missed scrapes',
baseSeries {
pvInfoUpdated: self.pvInfo {
_labels+:: {
csi_volume_handle: '672004be-a86b-44e0-b446-1255a1f8b340',
},
values: '_x5 1x5',
},
},
query,
{
labels: c.formatLabels(baseCalculatedLabels),
value: 10,
}),
],
}

0 comments on commit 3b62d22

Please sign in to comment.