diff --git a/metrics/internal/collectors/ceph-block-pool.go b/metrics/internal/collectors/ceph-block-pool.go index 758e700b39..a126c87cde 100644 --- a/metrics/internal/collectors/ceph-block-pool.go +++ b/metrics/internal/collectors/ceph-block-pool.go @@ -205,10 +205,9 @@ func (c *CephBlockPoolCollector) collectMirroringImageHealthRadosNamespace(rados for _, radosNamespace := range radosNamespace { var imageHealth string - if !(radosNamespace.Spec.Mirroring.Mode == cephv1.RadosNamespaceMirroringModePool || radosNamespace.Spec.Mirroring.Mode == cephv1.RadosNamespaceMirroringModeImage) { + if radosNamespace.Spec.Mirroring == nil { continue } - mirroringStatus := radosNamespace.Status.MirroringStatus if mirroringStatus == nil || mirroringStatus.Summary == nil || len(strings.TrimSpace(mirroringStatus.Summary.ImageHealth)) == 0 { klog.Errorf("Mirroring is enabled on CephBlockPoolRadosNamespace %q but image health status is not available.", radosNamespace.Name) @@ -244,19 +243,17 @@ func (c *CephBlockPoolCollector) collectMirroringImageHealthRadosNamespace(rados func (c *CephBlockPoolCollector) collectMirroringStatusRadosNamespace(radosNamespace []*cephv1.CephBlockPoolRadosNamespace, ch chan<- prometheus.Metric) { for _, cephBlockPool := range radosNamespace { - switch cephBlockPool.Spec.Mirroring.Mode { - case cephv1.RadosNamespaceMirroringModePool: - fallthrough - case cephv1.RadosNamespaceMirroringModeImage: + if cephBlockPool.Spec.Mirroring != nil { ch <- prometheus.MustNewConstMetric(c.MirroringStatus, prometheus.GaugeValue, 1, cephBlockPool.Spec.BlockPoolName, cephBlockPool.Namespace, cephBlockPool.Name) - default: + } else { ch <- prometheus.MustNewConstMetric(c.MirroringStatus, prometheus.GaugeValue, 0, cephBlockPool.Spec.BlockPoolName, cephBlockPool.Namespace, cephBlockPool.Name) + } } } diff --git a/metrics/internal/collectors/ceph-block-pool_test.go b/metrics/internal/collectors/ceph-block-pool_test.go index cbe9d266a4..e655c8ea87 100644 --- a/metrics/internal/collectors/ceph-block-pool_test.go +++ b/metrics/internal/collectors/ceph-block-pool_test.go @@ -52,6 +52,16 @@ var ( }, Status: &cephv1.CephBlockPoolRadosNamespaceStatus{}, } + mockCephBlockPoolRadosNamespace2 = cephv1.CephBlockPoolRadosNamespace{ + ObjectMeta: metav1.ObjectMeta{ + Name: "mockCephBlockPoolRadosNamespace", + Namespace: "openshift-storage", + }, + Spec: cephv1.CephBlockPoolRadosNamespaceSpec{ + BlockPoolName: "mockCephBlockPool-1", + }, + Status: &cephv1.CephBlockPoolRadosNamespaceStatus{}, + } ) func (c *CephBlockPoolCollector) GetInformer() cache.SharedIndexInformer { @@ -375,6 +385,9 @@ func TestCollectRadosNamespaceMirroringImageHealth(t *testing.T) { }, } + objNil := mockCephBlockPoolRadosNamespace2.DeepCopy() + objNil.Name = objError.Name + "nil" + tests := Tests{ { name: "Collect RadosNamespace mirroring image health metrics", @@ -384,6 +397,7 @@ func TestCollectRadosNamespaceMirroringImageHealth(t *testing.T) { objUnknown, objWarning, objError, + objNil, }, }, }, @@ -455,13 +469,9 @@ func TestCollectRadosNamespaceMirroringStatus(t *testing.T) { Mode: cephv1.RadosNamespaceMirroringModeImage, }, } - objDisabled := mockCephBlockPoolRadosNamespace1.DeepCopy() + objDisabled := mockCephBlockPoolRadosNamespace2.DeepCopy() objDisabled.Name = objDisabled.Name + "disabled" - objDisabled.Spec = cephv1.CephBlockPoolRadosNamespaceSpec{ - Mirroring: &cephv1.RadosNamespaceMirroring{ - Mode: "", - }, - } + objDisabled.Spec = cephv1.CephBlockPoolRadosNamespaceSpec{Mirroring: nil} tests := Tests{ { name: "Collect RadosNamespace mirroring status",