Skip to content

Commit

Permalink
Merge pull request #2134 from machadovilaca/add-volume-mod-to-pvc-inf…
Browse files Browse the repository at this point in the history
…o-metric

feat: add volumemode to PVC info metric
  • Loading branch information
k8s-ci-robot authored Aug 17, 2023
2 parents a9bdda0 + 0d45f1a commit aff4d97
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
22 changes: 11 additions & 11 deletions docs/persistentvolumeclaim-metrics.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# PersistentVolumeClaim Metrics

| Metric name | Metric type | Description | Unit (where applicable) | Labels/tags | Status |
| ----------- | ------------- | ----------- | ----------- | ----------- | ----------- |
| kube_persistentvolumeclaim_annotations | Gauge | | | `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; <br> `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `annotation_PERSISTENTVOLUMECLAIM_ANNOTATION`=&lt;PERSISTENTVOLUMECLAIM_ANNOATION&gt; | EXPERIMENTAL |
| kube_persistentvolumeclaim_access_mode | Gauge | | | `access_mode`=&lt;persistentvolumeclaim-access-mode&gt; <br>`namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; | STABLE |
| kube_persistentvolumeclaim_info | Gauge | | | `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; <br> `storageclass`=&lt;persistentvolumeclaim-storageclassname&gt;<br>`volumename`=&lt;volumename&gt; | STABLE |
| kube_persistentvolumeclaim_labels | Gauge | | | `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; <br> `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `label_PERSISTENTVOLUMECLAIM_LABEL`=&lt;PERSISTENTVOLUMECLAIM_LABEL&gt; | STABLE |
| kube_persistentvolumeclaim_resource_requests_storage_bytes | Gauge | | | `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; | STABLE |
| kube_persistentvolumeclaim_status_condition | Gauge | | | `namespace` =&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; <br> `type`=&lt;persistentvolumeclaim-condition-type&gt; <br> `status`=&lt;true\false\unknown&gt; | EXPERIMENTAL |
| kube_persistentvolumeclaim_status_phase | Gauge | | | `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; <br> `phase`=&lt;Pending\Bound\Lost&gt; | STABLE |
| kube_persistentvolumeclaim_created | Gauge | Unix creation timestamp | seconds | `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; | EXPERIMENTAL |
| kube_persistentvolumeclaim_deletion_timestamp | Gauge | Unix deletion timestamp | seconds | `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; | EXPERIMENTAL |
| Metric name | Metric type | Description | Unit (where applicable) | Labels/tags | Status |
| ----------- | ------------- | ----------- | ----------- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ----------- |
| kube_persistentvolumeclaim_annotations | Gauge | | | `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; <br> `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `annotation_PERSISTENTVOLUMECLAIM_ANNOTATION`=&lt;PERSISTENTVOLUMECLAIM_ANNOATION&gt; | EXPERIMENTAL |
| kube_persistentvolumeclaim_access_mode | Gauge | | | `access_mode`=&lt;persistentvolumeclaim-access-mode&gt; <br>`namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; | STABLE |
| kube_persistentvolumeclaim_info | Gauge | | | `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; <br> `storageclass`=&lt;persistentvolumeclaim-storageclassname&gt;<br>`volumename`=&lt;volumename&gt;<br>`volumemode`=&lt;volumemode&gt; | STABLE |
| kube_persistentvolumeclaim_labels | Gauge | | | `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; <br> `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `label_PERSISTENTVOLUMECLAIM_LABEL`=&lt;PERSISTENTVOLUMECLAIM_LABEL&gt; | STABLE |
| kube_persistentvolumeclaim_resource_requests_storage_bytes | Gauge | | | `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; | STABLE |
| kube_persistentvolumeclaim_status_condition | Gauge | | | `namespace` =&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; <br> `type`=&lt;persistentvolumeclaim-condition-type&gt; <br> `status`=&lt;true\false\unknown&gt; | EXPERIMENTAL |
| kube_persistentvolumeclaim_status_phase | Gauge | | | `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; <br> `phase`=&lt;Pending\Bound\Lost&gt; | STABLE |
| kube_persistentvolumeclaim_created | Gauge | Unix creation timestamp | seconds | `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; | EXPERIMENTAL |
| kube_persistentvolumeclaim_deletion_timestamp | Gauge | Unix deletion timestamp | seconds | `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; | EXPERIMENTAL |

Note:

Expand Down
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

0 comments on commit aff4d97

Please sign in to comment.