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

feat: add volumemode to PVC info metric #2134

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions internal/store/persistentvolumeclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,17 @@ func persistentVolumeClaimMetricFamilies(allowAnnotationsList, allowLabelsList [
wrapPersistentVolumeClaimFunc(func(p *v1.PersistentVolumeClaim) *metric.Family {
storageClassName := getPersistentVolumeClaimClass(p)
volumeName := p.Spec.VolumeName

volumeMode := ""
if p.Spec.VolumeMode != nil {
volumeMode = string(*p.Spec.VolumeMode)
}

return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: []string{"storageclass", "volumename"},
LabelValues: []string{storageClassName, volumeName},
LabelKeys: []string{"storageclass", "volumename", "volumemode"},
LabelValues: []string{storageClassName, volumeName, volumeMode},
Value: 1,
},
},
Expand Down
14 changes: 10 additions & 4 deletions internal/store/persistentvolumeclaim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

func TestPersistentVolumeClaimStore(t *testing.T) {
storageClassName := "rbd"
volumeMode := v1.PersistentVolumeBlock
cases := []generateMetricsTestCase{
// Verify phase enumerations.
{
Expand Down Expand Up @@ -56,6 +57,7 @@ func TestPersistentVolumeClaimStore(t *testing.T) {
},
},
VolumeName: "pvc-mysql-data",
VolumeMode: &volumeMode,
},
Status: v1.PersistentVolumeClaimStatus{
Phase: v1.ClaimBound,
Expand Down Expand Up @@ -84,7 +86,7 @@ func TestPersistentVolumeClaimStore(t *testing.T) {
# TYPE kube_persistentvolumeclaim_status_phase gauge
# TYPE kube_persistentvolumeclaim_status_condition gauge
kube_persistentvolumeclaim_created{namespace="default",persistentvolumeclaim="mysql-data"} 1.5e+09
kube_persistentvolumeclaim_info{namespace="default",persistentvolumeclaim="mysql-data",storageclass="rbd",volumename="pvc-mysql-data"} 1
kube_persistentvolumeclaim_info{namespace="default",persistentvolumeclaim="mysql-data",storageclass="rbd",volumename="pvc-mysql-data",volumemode="Block"} 1
kube_persistentvolumeclaim_status_phase{namespace="default",persistentvolumeclaim="mysql-data",phase="Bound"} 1
kube_persistentvolumeclaim_status_phase{namespace="default",persistentvolumeclaim="mysql-data",phase="Lost"} 0
kube_persistentvolumeclaim_status_phase{namespace="default",persistentvolumeclaim="mysql-data",phase="Pending"} 0
Expand Down Expand Up @@ -128,6 +130,7 @@ func TestPersistentVolumeClaimStore(t *testing.T) {
},
},
VolumeName: "pvc-mysql-data",
VolumeMode: &volumeMode,
},
Status: v1.PersistentVolumeClaimStatus{
Phase: v1.ClaimBound,
Expand Down Expand Up @@ -156,7 +159,7 @@ func TestPersistentVolumeClaimStore(t *testing.T) {
# TYPE kube_persistentvolumeclaim_status_phase gauge
# TYPE kube_persistentvolumeclaim_status_condition gauge
kube_persistentvolumeclaim_created{namespace="default",persistentvolumeclaim="mysql-data"} 1.5e+09
kube_persistentvolumeclaim_info{namespace="default",persistentvolumeclaim="mysql-data",storageclass="rbd",volumename="pvc-mysql-data"} 1
kube_persistentvolumeclaim_info{namespace="default",persistentvolumeclaim="mysql-data",storageclass="rbd",volumename="pvc-mysql-data",volumemode="Block"} 1
kube_persistentvolumeclaim_status_phase{namespace="default",persistentvolumeclaim="mysql-data",phase="Bound"} 1
kube_persistentvolumeclaim_status_phase{namespace="default",persistentvolumeclaim="mysql-data",phase="Lost"} 0
kube_persistentvolumeclaim_status_phase{namespace="default",persistentvolumeclaim="mysql-data",phase="Pending"} 0
Expand Down Expand Up @@ -189,6 +192,7 @@ func TestPersistentVolumeClaimStore(t *testing.T) {
},
StorageClassName: &storageClassName,
VolumeName: "pvc-prometheus-data",
VolumeMode: &volumeMode,
},
Status: v1.PersistentVolumeClaimStatus{
Phase: v1.ClaimPending,
Expand All @@ -210,7 +214,7 @@ func TestPersistentVolumeClaimStore(t *testing.T) {
# TYPE kube_persistentvolumeclaim_status_phase gauge
# TYPE kube_persistentvolumeclaim_status_condition gauge
kube_persistentvolumeclaim_created{namespace="default",persistentvolumeclaim="prometheus-data"} 1.5e+09
kube_persistentvolumeclaim_info{namespace="default",persistentvolumeclaim="prometheus-data",storageclass="rbd",volumename="pvc-prometheus-data"} 1
kube_persistentvolumeclaim_info{namespace="default",persistentvolumeclaim="prometheus-data",storageclass="rbd",volumename="pvc-prometheus-data",volumemode="Block"} 1
kube_persistentvolumeclaim_status_phase{namespace="default",persistentvolumeclaim="prometheus-data",phase="Bound"} 0
kube_persistentvolumeclaim_status_phase{namespace="default",persistentvolumeclaim="prometheus-data",phase="Lost"} 0
kube_persistentvolumeclaim_status_phase{namespace="default",persistentvolumeclaim="prometheus-data",phase="Pending"} 1
Expand All @@ -229,6 +233,7 @@ func TestPersistentVolumeClaimStore(t *testing.T) {
AccessModes: []v1.PersistentVolumeAccessMode{
v1.ReadWriteOnce,
},
VolumeMode: &volumeMode,
},
Status: v1.PersistentVolumeClaimStatus{
Phase: v1.ClaimLost,
Expand Down Expand Up @@ -257,7 +262,7 @@ func TestPersistentVolumeClaimStore(t *testing.T) {
# TYPE kube_persistentvolumeclaim_status_phase gauge
# TYPE kube_persistentvolumeclaim_status_condition gauge
kube_persistentvolumeclaim_created{namespace="",persistentvolumeclaim="mongo-data"} 1.5e+09
kube_persistentvolumeclaim_info{namespace="",persistentvolumeclaim="mongo-data",storageclass="",volumename=""} 1
kube_persistentvolumeclaim_info{namespace="",persistentvolumeclaim="mongo-data",storageclass="",volumename="",volumemode="Block"} 1
kube_persistentvolumeclaim_status_phase{namespace="",persistentvolumeclaim="mongo-data",phase="Bound"} 0
kube_persistentvolumeclaim_status_phase{namespace="",persistentvolumeclaim="mongo-data",phase="Lost"} 1
kube_persistentvolumeclaim_status_phase{namespace="",persistentvolumeclaim="mongo-data",phase="Pending"} 0
Expand Down Expand Up @@ -293,6 +298,7 @@ func TestPersistentVolumeClaimStore(t *testing.T) {
},
},
VolumeName: "pvc-postgresql-data",
VolumeMode: &volumeMode,
},
Status: v1.PersistentVolumeClaimStatus{
Phase: v1.ClaimBound,
Expand Down
Loading