From 328b98d4839771934ab034676521755ee8d6fe2a Mon Sep 17 00:00:00 2001 From: rahulguptajss Date: Fri, 25 Oct 2024 17:54:38 +0530 Subject: [PATCH 1/4] style: add debug logs for volume plugin --- cmd/collectors/rest/plugins/volume/volume.go | 21 +++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/cmd/collectors/rest/plugins/volume/volume.go b/cmd/collectors/rest/plugins/volume/volume.go index e13792870..22a69c57e 100644 --- a/cmd/collectors/rest/plugins/volume/volume.go +++ b/cmd/collectors/rest/plugins/volume/volume.go @@ -17,6 +17,7 @@ import ( "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" "log/slog" + "os" "strconv" "time" ) @@ -117,11 +118,11 @@ func (v *Volume) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util volumeMap, err := v.getVolumeInfo() if err != nil { v.SLogger.Error("Failed to collect volume info data", slogx.Err(err)) + } else { + // update volume instance labels + v.updateVolumeLabels(data, volumeMap) } - // update volume instance labels - v.updateVolumeLabels(data, volumeMap) - // parse anti_ransomware_start_time, antiRansomwareState for all volumes and export at cluster level v.handleARWProtection(data) @@ -131,6 +132,11 @@ func (v *Volume) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util func (v *Volume) updateVolumeLabels(data *matrix.Matrix, volumeMap map[string]volumeInfo) { var err error + + if os.Getenv("ENABLE_VOLUME_LOGGING") == "true" { + v.SLogger.Info("Size of volumeMap", slog.Int("size", len(volumeMap))) + } + cloneSplitEstimateMetric := data.GetMetric("clone_split_estimate") if cloneSplitEstimateMetric == nil { if cloneSplitEstimateMetric, err = data.NewMetricFloat64("clone_split_estimate"); err != nil { @@ -144,6 +150,9 @@ func (v *Volume) updateVolumeLabels(data *matrix.Matrix, volumeMap map[string]vo } if volume.GetLabel("style") == "flexgroup_constituent" { + if os.Getenv("ENABLE_VOLUME_LOGGING") == "true" { + v.SLogger.Warn("Setting exportable for flexgroup constituent", slog.String("volume", volume.GetLabel("volume")), slog.Bool("exportable", v.includeConstituents)) + } volume.SetExportable(v.includeConstituents) } @@ -151,6 +160,9 @@ func (v *Volume) updateVolumeLabels(data *matrix.Matrix, volumeMap map[string]vo if vInfo, ok := volumeMap[volume.GetLabel("volume")+volume.GetLabel("svm")]; ok { if vInfo.isObjectStoreVolume { + if os.Getenv("ENABLE_VOLUME_LOGGING") == "true" { + v.SLogger.Warn("Setting exportable for object store volume", slog.String("volume", volume.GetLabel("volume")), slog.Bool("exportable", false)) + } volume.SetExportable(false) continue } @@ -168,6 +180,9 @@ func (v *Volume) updateVolumeLabels(data *matrix.Matrix, volumeMap map[string]vo } } else { // The public API does not include node root and temp volumes, while the private CLI does include them. Harvest will exclude them the same as the public API by not exporting them. + if os.Getenv("ENABLE_VOLUME_LOGGING") == "true" { + v.SLogger.Warn("Setting exportable for excluded volume", slog.String("volume", volume.GetLabel("volume")), slog.Bool("exportable", false)) + } volume.SetExportable(false) } } From fb5920edbae1aed58cc0be96c6d0c70ea3dfbdea Mon Sep 17 00:00:00 2001 From: rahulguptajss Date: Fri, 25 Oct 2024 18:00:20 +0530 Subject: [PATCH 2/4] style: add debug logs for volume plugin --- cmd/collectors/rest/plugins/volume/volume.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/collectors/rest/plugins/volume/volume.go b/cmd/collectors/rest/plugins/volume/volume.go index 22a69c57e..e3965f1fd 100644 --- a/cmd/collectors/rest/plugins/volume/volume.go +++ b/cmd/collectors/rest/plugins/volume/volume.go @@ -25,6 +25,8 @@ import ( const HoursInMonth = 24 * 30 const ARWSupportedVersion = "9.10.0" +var enableVolumeLogging bool + type Volume struct { *plugin.AbstractPlugin currentVal int @@ -92,6 +94,7 @@ func (v *Volume) Init() error { if err != nil { return fmt.Errorf("unable to get version %w", err) } + enableVolumeLogging = os.Getenv("ENABLE_VOLUME_LOGGING") == "true" return nil } @@ -133,8 +136,8 @@ func (v *Volume) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util func (v *Volume) updateVolumeLabels(data *matrix.Matrix, volumeMap map[string]volumeInfo) { var err error - if os.Getenv("ENABLE_VOLUME_LOGGING") == "true" { - v.SLogger.Info("Size of volumeMap", slog.Int("size", len(volumeMap))) + if enableVolumeLogging { + v.SLogger.Info("Size of volumeMap", slog.Int("size", len(volumeMap)), slog.Any("volumeMap", volumeMap)) } cloneSplitEstimateMetric := data.GetMetric("clone_split_estimate") @@ -150,7 +153,7 @@ func (v *Volume) updateVolumeLabels(data *matrix.Matrix, volumeMap map[string]vo } if volume.GetLabel("style") == "flexgroup_constituent" { - if os.Getenv("ENABLE_VOLUME_LOGGING") == "true" { + if enableVolumeLogging { v.SLogger.Warn("Setting exportable for flexgroup constituent", slog.String("volume", volume.GetLabel("volume")), slog.Bool("exportable", v.includeConstituents)) } volume.SetExportable(v.includeConstituents) @@ -180,7 +183,7 @@ func (v *Volume) updateVolumeLabels(data *matrix.Matrix, volumeMap map[string]vo } } else { // The public API does not include node root and temp volumes, while the private CLI does include them. Harvest will exclude them the same as the public API by not exporting them. - if os.Getenv("ENABLE_VOLUME_LOGGING") == "true" { + if enableVolumeLogging { v.SLogger.Warn("Setting exportable for excluded volume", slog.String("volume", volume.GetLabel("volume")), slog.Bool("exportable", false)) } volume.SetExportable(false) From 2bc48761ded1b18ac74eb16e3d18c575b36b5175 Mon Sep 17 00:00:00 2001 From: rahulguptajss Date: Fri, 25 Oct 2024 18:01:02 +0530 Subject: [PATCH 3/4] style: add debug logs for volume plugin --- cmd/collectors/rest/plugins/volume/volume.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/collectors/rest/plugins/volume/volume.go b/cmd/collectors/rest/plugins/volume/volume.go index e3965f1fd..e64daaf1a 100644 --- a/cmd/collectors/rest/plugins/volume/volume.go +++ b/cmd/collectors/rest/plugins/volume/volume.go @@ -163,7 +163,7 @@ func (v *Volume) updateVolumeLabels(data *matrix.Matrix, volumeMap map[string]vo if vInfo, ok := volumeMap[volume.GetLabel("volume")+volume.GetLabel("svm")]; ok { if vInfo.isObjectStoreVolume { - if os.Getenv("ENABLE_VOLUME_LOGGING") == "true" { + if enableVolumeLogging { v.SLogger.Warn("Setting exportable for object store volume", slog.String("volume", volume.GetLabel("volume")), slog.Bool("exportable", false)) } volume.SetExportable(false) From 9234d7c73f2b212e0ef46266ea1f7c49858ff7d3 Mon Sep 17 00:00:00 2001 From: rahulguptajss Date: Fri, 25 Oct 2024 18:02:28 +0530 Subject: [PATCH 4/4] style: add debug logs for volume plugin --- cmd/collectors/rest/plugins/volume/volume.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/collectors/rest/plugins/volume/volume.go b/cmd/collectors/rest/plugins/volume/volume.go index e64daaf1a..6b1832cdf 100644 --- a/cmd/collectors/rest/plugins/volume/volume.go +++ b/cmd/collectors/rest/plugins/volume/volume.go @@ -94,7 +94,7 @@ func (v *Volume) Init() error { if err != nil { return fmt.Errorf("unable to get version %w", err) } - enableVolumeLogging = os.Getenv("ENABLE_VOLUME_LOGGING") == "true" + enableVolumeLogging = os.Getenv("ENABLE_VOLUME_LOGGING") != "" return nil }