Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update lagtime based on lasttransfersize #2091

Merged
merged 2 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cmd/collectors/commonutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,22 @@ func SetNameservice(nsDB, nsSource, nisDomain string, instance *matrix.Instance)
func IsTimestampOlderThanDuration(timestamp float64, duration time.Duration) bool {
return time.Since(time.UnixMicro(int64(timestamp))) > duration
}

func UpdateLagTime(instance *matrix.Instance, lastTransferSize *matrix.Metric, lagTime *matrix.Metric, logger *logging.Logger) {
healthy := instance.GetLabel("healthy")
schedule := instance.GetLabel("schedule")
lastError := instance.GetLabel("last_transfer_error")
relationshipID := instance.GetLabel("relationship_id")

// If SM relationship is healthy, has a schedule, last_transfer_error is empty, and last_transfer_bytes is 0, Then we are setting lag_time to 0
// Otherwise, report the lag_time which ONTAP has originally reported.
if lastBytes, ok := lastTransferSize.GetValueFloat64(instance); ok {
if healthy == "true" && schedule != "" && lastError == "" && lastBytes == 0 {
lag, _ := lagTime.GetValueFloat64(instance)
if err := lagTime.SetValueFloat64(instance, 0); err != nil {
logger.Error().Err(err).Str("metric", lagTime.GetName()).Msg("Unable to set value on metric")
}
logger.Debug().Msgf("lagTime value set from %f to 0 for %s. Healthy: %s, Schedule: %s, LastBytes: %f, LastError:%s", lag, relationshipID, healthy, schedule, lastBytes, lastError)
}
}
}
62 changes: 62 additions & 0 deletions cmd/collectors/commonutils_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package collectors

import (
"github.com/netapp/harvest/v2/pkg/logging"
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/tree/node"
"testing"
Expand Down Expand Up @@ -297,3 +298,64 @@ func generateScheduleParam(duration string) *node.Node {
param.NewChildS("data", duration)
return root
}

func TestLagTimeBasedOnLastTransferSize(t *testing.T) {
type test struct {
name string
instance string
healthy string
schedule string
lastTransferError string
relationshipID string
lastBytesValue float64
lagTimeValue float64
want float64
}
tests := []test{
{name: "TestBytesNonZero", instance: "InstanceA", healthy: "true", schedule: "5min", lastTransferError: "", relationshipID: "4885136b-4c31-11ec-95a6-00a09865cd13", lastBytesValue: 3479, lagTimeValue: 172652, want: 172652},
{name: "TestLastErrorNonEmpty", instance: "InstanceB", healthy: "true", schedule: "my_daily", lastTransferError: "The specified Snapshot copy is older than the base Snapshot copy on source volume", relationshipID: "7c4d92e1-6828-11ea-893b-00a09865cd13", lastBytesValue: 0, lagTimeValue: 172223, want: 172223},
{name: "TestScheduleEmpty", instance: "InstanceC", healthy: "true", schedule: "", lastTransferError: "", relationshipID: "62422099-9c61-11e8-b2ff-00a09865fe59", lastBytesValue: 0, lagTimeValue: 738, want: 738},
{name: "TestNonHealthy", instance: "InstanceD", healthy: "false", schedule: "daily", lastTransferError: "", relationshipID: "31421f02-7703-11e9-b59e-00a09865cd13", lastBytesValue: 0, lagTimeValue: 892, want: 892},
{name: "TestLagTimeChangedTo0", instance: "InstanceE", healthy: "true", schedule: "hourly", lastTransferError: "", relationshipID: "b4da7644-76e0-11e9-b59e-00a09865cd13", lastBytesValue: 0, lagTimeValue: 2736, want: 0},
}

data := matrix.New("SnapMirrorTest", "SnapMirror", "SnapMirror")
lastTransferSizeMetric, err := data.NewMetricUint8("last_transfer_size")
if err != nil {
panic(err)
}
lagTimeMetric, err := data.NewMetricUint8("lag_time")
if err != nil {
panic(err)
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
instance := populateInstance(data, tt.instance, tt.healthy, tt.schedule, tt.lastTransferError, tt.relationshipID, lastTransferSizeMetric, tt.lastBytesValue, lagTimeMetric, tt.lagTimeValue)
UpdateLagTime(instance, lastTransferSizeMetric, lagTimeMetric, logging.Get())
actualValue, _ := lagTimeMetric.GetValueFloat64(instance)
if actualValue != tt.want {
t.Errorf("expected %f got %f", tt.want, actualValue)
}
})
}
}

func populateInstance(data *matrix.Matrix, instanceName, healthy, schedule, lastError, relationshipID string, lastTransferSizeMetric *matrix.Metric, bytesData float64, lagTimeMetric *matrix.Metric, lagTime float64) *matrix.Instance {
instance, err := data.NewInstance(instanceName)
if err != nil {
panic(err)
}
instance.SetLabel("healthy", healthy)
instance.SetLabel("schedule", schedule)
instance.SetLabel("last_transfer_error", lastError)
instance.SetLabel("relationship_id", relationshipID)

if err = lastTransferSizeMetric.SetValueFloat64(instance, bytesData); err != nil {
panic(err)
}
if err = lagTimeMetric.SetValueFloat64(instance, lagTime); err != nil {
panic(err)
}
return instance
}
12 changes: 12 additions & 0 deletions cmd/collectors/rest/plugins/snapmirror/snapmirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ func (my *SnapMirror) updateSMLabels(data *matrix.Matrix) {
var keys []string
cluster, _ := data.GetGlobalLabels().GetHas("cluster")

lastTransferSizeMetric := data.GetMetric("last_transfer_size")
lagTimeMetric := data.GetMetric("lag_time")
if lastTransferSizeMetric == nil {
return
}
if lagTimeMetric == nil {
return
}

for key, instance := range data.GetInstances() {
if instance.GetLabel("group_type") == "consistencygroup" {
keys = append(keys, key)
Expand All @@ -156,6 +165,9 @@ func (my *SnapMirror) updateSMLabels(data *matrix.Matrix) {

// update the protectedBy and protectionSourceType fields and derivedRelationshipType in snapmirror_labels
collectors.UpdateProtectedFields(instance)

// Update lag time based on checks
collectors.UpdateLagTime(instance, lastTransferSizeMetric, lagTimeMetric, my.Logger)
}

// handle CG relationships
Expand Down
13 changes: 13 additions & 0 deletions cmd/collectors/zapi/plugins/snapmirror/snapmirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/netapp/harvest/v2/pkg/api/ontapi/zapi"
"github.com/netapp/harvest/v2/pkg/conf"
"github.com/netapp/harvest/v2/pkg/dict"
"github.com/netapp/harvest/v2/pkg/errs"
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/tree/node"
"regexp"
Expand Down Expand Up @@ -81,6 +82,15 @@ func (my *SnapMirror) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix,
my.Logger.Debug().Msg("updated svm peer detail")
}

lastTransferSizeMetric := data.GetMetric("snapmirror-info.last-transfer-size")
lagTimeMetric := data.GetMetric("snapmirror-info.lag-time")
if lastTransferSizeMetric == nil {
return nil, errs.New(errs.ErrNoMetric, "last_transfer_size")
}
if lagTimeMetric == nil {
return nil, errs.New(errs.ErrNoMetric, "lag_time")
}

for _, instance := range data.GetInstances() {
// Zapi call with `expand=true` returns all the constituent's relationships. We do not want to export them.
if match := flexgroupConstituentName.FindStringSubmatch(instance.GetLabel("destination_volume")); len(match) == 3 {
Expand All @@ -104,6 +114,9 @@ func (my *SnapMirror) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix,

// update the protectedBy and protectionSourceType fields and derivedRelationshipType in snapmirror_labels
collectors.UpdateProtectedFields(instance)

// Update lag time based on checks
collectors.UpdateLagTime(instance, lastTransferSizeMetric, lagTimeMetric, my.Logger)
} else {
// 7 Mode
// source / destination nodes can be something like:
Expand Down
2 changes: 2 additions & 0 deletions conf/rest/9.12.0/snapmirror.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ endpoints:
- ^^destination.path => destination_location
- ^^uuid => relationship_id
- ^source.cluster.name => source_cluster
- ^unhealthy_reason.#.message => last_transfer_error

plugins:
- Snapmirror
Expand All @@ -61,6 +62,7 @@ export_options:
- derived_relationship_type
- group_type
- healthy
- last_transfer_error
- last_transfer_type
- local
- policy_type
Expand Down
2 changes: 2 additions & 0 deletions conf/zapi/cdot/9.8.0/snapmirror.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ counters:
- ^destination-volume-node => destination_node
- ^destination-vserver
- ^is-healthy => healthy
- ^last-transfer-error
- ^last-transfer-type
- ^policy-type
- ^relationship-group-type => group_type
Expand Down Expand Up @@ -51,6 +52,7 @@ export_options:
- destination_node_limit
- group_type
- healthy
- last_transfer_error
- last_transfer_type
- local
- policy_type
Expand Down