Skip to content

Commit

Permalink
feat(metrics): add volume filesystem read only state metrics
Browse files Browse the repository at this point in the history
ref: longhorn/longhorn 8508

Signed-off-by: Jack Lin <jack.lin@suse.com>
  • Loading branch information
ChanYiLin committed Aug 23, 2024
1 parent 19ba220 commit 4e0765f
Showing 1 changed file with 46 additions and 5 deletions.
51 changes: 46 additions & 5 deletions metrics_collector/volume_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package metricscollector

import (
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"

"github.com/prometheus/client_golang/prometheus"
apierrors "k8s.io/apimachinery/pkg/api/errors"

imtypes "github.com/longhorn/longhorn-instance-manager/pkg/types"

"github.com/longhorn/longhorn-manager/controller"
"github.com/longhorn/longhorn-manager/datastore"
"github.com/longhorn/longhorn-manager/engineapi"
"github.com/longhorn/longhorn-manager/types"
"github.com/longhorn/longhorn-manager/util"

longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
Expand All @@ -19,10 +23,11 @@ type VolumeCollector struct {

proxyConnCounter util.Counter

capacityMetric metricInfo
sizeMetric metricInfo
stateMetric metricInfo
robustnessMetric metricInfo
capacityMetric metricInfo
sizeMetric metricInfo
stateMetric metricInfo
robustnessMetric metricInfo
fileSystemReadOnlyMetric metricInfo

volumePerfMetrics
}
Expand All @@ -48,6 +53,16 @@ func NewVolumeCollector(
proxyConnCounter: util.NewAtomicCounter(),
}

vc.fileSystemReadOnlyMetric = metricInfo{
Desc: prometheus.NewDesc(
prometheus.BuildFQName(longhornName, subsystemVolume, "file_system_read_only"),
"Volume whose mount point is in read-only mode",
[]string{nodeLabel, volumeLabel, pvcLabel, pvcNamespaceLabel},
nil,
),
Type: prometheus.GaugeValue,
}

vc.capacityMetric = metricInfo{
Desc: prometheus.NewDesc(
prometheus.BuildFQName(longhornName, subsystemVolume, "capacity_bytes"),
Expand Down Expand Up @@ -156,6 +171,7 @@ func (vc *VolumeCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- vc.sizeMetric.Desc
ch <- vc.stateMetric.Desc
ch <- vc.robustnessMetric.Desc
ch <- vc.fileSystemReadOnlyMetric.Desc
}

func (vc *VolumeCollector) Collect(ch chan<- prometheus.Metric) {
Expand Down Expand Up @@ -214,6 +230,31 @@ func (vc *VolumeCollector) collectMetrics(ch chan<- prometheus.Metric, v *longho
ch <- prometheus.MustNewConstMetric(vc.volumePerfMetrics.iopsMetrics.write.Desc, vc.volumePerfMetrics.iopsMetrics.write.Type, float64(vc.getVolumeWriteIOPS(metrics)), vc.currentNodeID, v.Name, v.Status.KubernetesStatus.PVCName, v.Status.KubernetesStatus.Namespace)
ch <- prometheus.MustNewConstMetric(vc.volumePerfMetrics.latencyMetrics.read.Desc, vc.volumePerfMetrics.latencyMetrics.read.Type, float64(vc.getVolumeReadLatency(metrics)), vc.currentNodeID, v.Name, v.Status.KubernetesStatus.PVCName, v.Status.KubernetesStatus.Namespace)
ch <- prometheus.MustNewConstMetric(vc.volumePerfMetrics.latencyMetrics.write.Desc, vc.volumePerfMetrics.latencyMetrics.write.Type, float64(vc.getVolumeWriteLatency(metrics)), vc.currentNodeID, v.Name, v.Status.KubernetesStatus.PVCName, v.Status.KubernetesStatus.Namespace)

fileSystemReadOnlyCondition := types.GetCondition(e.Status.Conditions, imtypes.EngineConditionFilesystemReadOnly)
isPVMountOptionReadOnly := false
kubeStatus := v.Status.KubernetesStatus
if kubeStatus.PVName != "" {
pv, err := vc.ds.GetPersistentVolumeRO(kubeStatus.PVName)
if err != nil {
if !apierrors.IsNotFound(err) {
vc.logger.WithError(err).Warnf("Failed to get PV when checking the mount option of the volume")
return
}
}
if pv != nil {
for _, opt := range pv.Spec.MountOptions {
if opt == "ro" {
isPVMountOptionReadOnly = true
break
}
}
}
}
if fileSystemReadOnlyCondition.Status == longhorn.ConditionStatusTrue && !isPVMountOptionReadOnly {
ch <- prometheus.MustNewConstMetric(vc.fileSystemReadOnlyMetric.Desc, vc.fileSystemReadOnlyMetric.Type, float64(1), vc.currentNodeID, v.Name, v.Status.KubernetesStatus.PVCName, v.Status.KubernetesStatus.Namespace)
}

}

func (vc *VolumeCollector) getEngineClientProxy(engine *longhorn.Engine) (c engineapi.EngineClientProxy, err error) {
Expand Down

0 comments on commit 4e0765f

Please sign in to comment.