Skip to content

Commit

Permalink
metrics: set metrics if not nil
Browse files Browse the repository at this point in the history
Signed-off-by: rakeshgm <[email protected]>
(cherry picked from commit e024cce)
  • Loading branch information
rakeshgm authored and ShyamsundarR committed Aug 28, 2023
1 parent 761ba6b commit b9b064f
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions controllers/drplacementcontrol_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,20 +778,7 @@ func (r *DRPlacementControlReconciler) createDRPCInstance(
return nil, fmt.Errorf("configmap get: %w", err)
}

syncMetricLabels := SyncMetricLabels(drPolicy, drpc)
syncMetrics := NewSyncMetrics(syncMetricLabels)

syncDurationMetricLabels := SyncDurationMetricLabels(drPolicy, drpc)
syncDurationMetrics := NewSyncDurationMetric(syncDurationMetricLabels)

syncDataBytesLabels := SyncDataBytesMetricLabels(drPolicy, drpc)
syncDataMetrics := NewSyncDataBytesMetric(syncDataBytesLabels)

drpcMetrics := DRPCMetrics{
SyncMetrics: syncMetrics,
SyncDurationMetrics: syncDurationMetrics,
SyncDataBytesMetrics: syncDataMetrics,
}
drpcMetrics := r.createDRPCMetrics(drPolicy, drpc)

d := &DRPCInstance{
reconciler: r,
Expand All @@ -804,7 +791,7 @@ func (r *DRPlacementControlReconciler) createDRPCInstance(
vrgs: vrgs,
vrgNamespace: vrgNamespace,
volSyncDisabled: ramenConfig.VolSync.Disabled,
metrics: &drpcMetrics,
metrics: drpcMetrics,
mwu: rmnutil.MWUtil{
Client: r.Client,
APIReader: r.APIReader,
Expand All @@ -828,6 +815,25 @@ func (r *DRPlacementControlReconciler) createDRPCInstance(
return d, nil
}

func (r *DRPlacementControlReconciler) createDRPCMetrics(
drPolicy *rmn.DRPolicy, drpc *rmn.DRPlacementControl,
) *DRPCMetrics {
syncMetricLabels := SyncMetricLabels(drPolicy, drpc)
syncMetrics := NewSyncMetrics(syncMetricLabels)

syncDurationMetricLabels := SyncDurationMetricLabels(drPolicy, drpc)
syncDurationMetrics := NewSyncDurationMetric(syncDurationMetricLabels)

syncDataBytesLabels := SyncDataBytesMetricLabels(drPolicy, drpc)
syncDataMetrics := NewSyncDataBytesMetric(syncDataBytesLabels)

return &DRPCMetrics{
SyncMetrics: syncMetrics,
SyncDurationMetrics: syncDurationMetrics,
SyncDataBytesMetrics: syncDataMetrics,
}
}

// isBeingDeleted returns true if either DRPC, user placement, or both are being deleted
func isBeingDeleted(drpc *rmn.DRPlacementControl, usrPl client.Object) bool {
return !drpc.GetDeletionTimestamp().IsZero() ||
Expand Down Expand Up @@ -1568,9 +1574,11 @@ func (r *DRPlacementControlReconciler) updateResourceCondition(
drpc.Status.LastGroupSyncDuration = nil
drpc.Status.LastGroupSyncBytes = nil

r.setLastSyncTimeMetric(&drpcMetrics.SyncMetrics, nil, log)
r.setLastSyncDurationMetric(&drpcMetrics.SyncDurationMetrics, nil, log)
r.setLastSyncBytesMetric(&drpcMetrics.SyncDataBytesMetrics, nil, log)
if drpcMetrics != nil {
r.setLastSyncTimeMetric(&drpcMetrics.SyncMetrics, nil, log)
r.setLastSyncDurationMetric(&drpcMetrics.SyncDurationMetrics, nil, log)
r.setLastSyncBytesMetric(&drpcMetrics.SyncDataBytesMetrics, nil, log)
}
} else {
drpc.Status.ResourceConditions.ResourceMeta.Kind = vrg.Kind
drpc.Status.ResourceConditions.ResourceMeta.Name = vrg.Name
Expand All @@ -1588,9 +1596,11 @@ func (r *DRPlacementControlReconciler) updateResourceCondition(
drpc.Status.LastGroupSyncDuration = vrg.Status.LastGroupSyncDuration
drpc.Status.LastGroupSyncBytes = vrg.Status.LastGroupSyncBytes

r.setLastSyncTimeMetric(&drpcMetrics.SyncMetrics, vrg.Status.LastGroupSyncTime, log)
r.setLastSyncDurationMetric(&drpcMetrics.SyncDurationMetrics, vrg.Status.LastGroupSyncDuration, log)
r.setLastSyncBytesMetric(&drpcMetrics.SyncDataBytesMetrics, vrg.Status.LastGroupSyncBytes, log)
if drpcMetrics != nil {
r.setLastSyncTimeMetric(&drpcMetrics.SyncMetrics, vrg.Status.LastGroupSyncTime, log)
r.setLastSyncDurationMetric(&drpcMetrics.SyncDurationMetrics, vrg.Status.LastGroupSyncDuration, log)
r.setLastSyncBytesMetric(&drpcMetrics.SyncDataBytesMetrics, vrg.Status.LastGroupSyncBytes, log)
}
}
}

Expand Down

0 comments on commit b9b064f

Please sign in to comment.