Skip to content

Commit

Permalink
Merge pull request #2919 from weirdwiz/main
Browse files Browse the repository at this point in the history
DFBUGS-976: monitoring: mark mirroring enabled if spec.Mirroring is !nil
  • Loading branch information
openshift-merge-bot[bot] authored Dec 5, 2024
2 parents f3c1b94 + 2d1bce6 commit a8aa21c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
11 changes: 4 additions & 7 deletions metrics/internal/collectors/ceph-block-pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

}
}
}
22 changes: 16 additions & 6 deletions metrics/internal/collectors/ceph-block-pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
Expand All @@ -384,6 +397,7 @@ func TestCollectRadosNamespaceMirroringImageHealth(t *testing.T) {
objUnknown,
objWarning,
objError,
objNil,
},
},
},
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit a8aa21c

Please sign in to comment.