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

style: add debug logs for volume plugin #3233

Merged
merged 4 commits into from
Oct 25, 2024
Merged
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
24 changes: 21 additions & 3 deletions cmd/collectors/rest/plugins/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ import (
"github.com/netapp/harvest/v2/pkg/util"
"github.com/tidwall/gjson"
"log/slog"
"os"
"strconv"
"time"
)

const HoursInMonth = 24 * 30
const ARWSupportedVersion = "9.10.0"

var enableVolumeLogging bool

type Volume struct {
*plugin.AbstractPlugin
currentVal int
Expand Down Expand Up @@ -91,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") != ""
return nil
}

Expand All @@ -117,11 +121,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)

Expand All @@ -131,6 +135,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 enableVolumeLogging {
v.SLogger.Info("Size of volumeMap", slog.Int("size", len(volumeMap)), slog.Any("volumeMap", volumeMap))
}

cloneSplitEstimateMetric := data.GetMetric("clone_split_estimate")
if cloneSplitEstimateMetric == nil {
if cloneSplitEstimateMetric, err = data.NewMetricFloat64("clone_split_estimate"); err != nil {
Expand All @@ -144,13 +153,19 @@ func (v *Volume) updateVolumeLabels(data *matrix.Matrix, volumeMap map[string]vo
}

if volume.GetLabel("style") == "flexgroup_constituent" {
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)
}

volume.SetLabel("isHardwareEncrypted", strconv.FormatBool(v.aggrsMap[volume.GetLabel("aggr")]))

if vInfo, ok := volumeMap[volume.GetLabel("volume")+volume.GetLabel("svm")]; ok {
if vInfo.isObjectStoreVolume {
if enableVolumeLogging {
v.SLogger.Warn("Setting exportable for object store volume", slog.String("volume", volume.GetLabel("volume")), slog.Bool("exportable", false))
}
volume.SetExportable(false)
continue
}
Expand All @@ -168,6 +183,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 enableVolumeLogging {
v.SLogger.Warn("Setting exportable for excluded volume", slog.String("volume", volume.GetLabel("volume")), slog.Bool("exportable", false))
}
volume.SetExportable(false)
}
}
Expand Down