Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix query on PV info change #111

Merged
merged 2 commits into from Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
81 changes: 81 additions & 0 deletions pkg/db/seeds/promtest/appuio_cloud_persistent_storage.jsonnet
@@ -0,0 +1,81 @@
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 {
pvInfo+: {
values: '1x10 _x10 stale',
},
bastjan marked this conversation as resolved.
Show resolved Hide resolved
pvInfoUpdated: self.pvInfo {
_labels+:: {
csi_volume_handle: '672004be-a86b-44e0-b446-1255a1f8b340',
},
values: '_x5 1x15',
bastjan marked this conversation as resolved.
Show resolved Hide resolved
},
},
query,
{
labels: c.formatLabels(baseCalculatedLabels),
value: 10,
}),
],
}