From d2307601525d7f0efc95eaf38937b82930fc4861 Mon Sep 17 00:00:00 2001 From: Chris Grindstaff Date: Tue, 8 Oct 2024 06:00:56 -0400 Subject: [PATCH] refactor: improve slog error logging (#3198) * refactor: improve slog error logging * refactor: improve slog error logging --- cmd/admin/admin.go | 13 ++-- cmd/collectors/commonutils.go | 25 +++---- cmd/collectors/ems/ems.go | 17 ++--- cmd/collectors/ems/ems_test.go | 3 +- cmd/collectors/fabricpool.go | 9 +-- cmd/collectors/keyperf/keyperf.go | 11 ++-- cmd/collectors/power.go | 5 +- cmd/collectors/qosCommon.go | 3 +- .../rest/plugins/aggregate/aggregate.go | 9 +-- .../rest/plugins/certificate/certificate.go | 13 ++-- cmd/collectors/rest/plugins/health/health.go | 65 ++++++++++--------- .../metroclustercheck/metroclustercheck.go | 7 +- .../rest/plugins/netroute/netroute.go | 3 +- .../plugins/ontaps3service/ontaps3service.go | 3 +- .../qospolicyadaptive/qospolicyadaptive.go | 5 +- .../plugins/qospolicyfixed/qospolicyfixed.go | 7 +- cmd/collectors/rest/plugins/quota/quota.go | 11 ++-- .../rest/plugins/snapmirror/snapmirror.go | 9 +-- cmd/collectors/rest/plugins/svm/svm.go | 24 +++---- cmd/collectors/rest/plugins/volume/volume.go | 21 +++--- .../volumeanalytics/volumeanalytics.go | 29 +++++---- .../rest/plugins/workload/workload.go | 3 +- cmd/collectors/rest/rest.go | 15 +++-- cmd/collectors/restperf/plugins/disk/disk.go | 43 ++++++------ cmd/collectors/restperf/plugins/fcp/fcp.go | 7 +- cmd/collectors/restperf/plugins/fcvi/fcvi.go | 5 +- cmd/collectors/restperf/plugins/nic/nic.go | 11 ++-- .../restperf/plugins/volumetag/volumetag.go | 5 +- .../volumetopclients/volumetopclients.go | 9 +-- .../restperf/plugins/vscan/vscan.go | 3 +- cmd/collectors/restperf/restperf.go | 43 ++++++------ cmd/collectors/simple/simple.go | 5 +- .../storagegrid/plugins/bucket/bucket.go | 7 +- .../storagegrid/plugins/joinrest/joinrest.go | 5 +- cmd/collectors/storagegrid/storagegrid.go | 15 +++-- cmd/collectors/storagegrid/tenant.go | 5 +- cmd/collectors/unix/main.go | 25 +++---- cmd/collectors/volume.go | 17 ++--- cmd/collectors/zapi/collector/parsers.go | 3 +- cmd/collectors/zapi/collector/zapi.go | 7 +- .../zapi/plugins/aggregate/aggregate.go | 15 +++-- .../zapi/plugins/certificate/certificate.go | 13 ++-- .../qospolicyadaptive/qospolicyadaptive.go | 3 +- .../plugins/qospolicyfixed/qospolicyfixed.go | 3 +- cmd/collectors/zapi/plugins/qtree/qtree.go | 9 +-- .../zapi/plugins/security/security.go | 8 +-- cmd/collectors/zapi/plugins/shelf/shelf.go | 17 ++--- .../zapi/plugins/snapmirror/snapmirror.go | 3 +- cmd/collectors/zapi/plugins/svm/svm.go | 27 ++++---- .../zapi/plugins/systemnode/systemnode.go | 8 +-- cmd/collectors/zapi/plugins/volume/volume.go | 19 +++--- .../zapi/plugins/workload/workload.go | 3 +- cmd/collectors/zapiperf/plugins/disk/disk.go | 37 ++++++----- cmd/collectors/zapiperf/plugins/fcp/fcp.go | 7 +- cmd/collectors/zapiperf/plugins/fcvi/fcvi.go | 3 +- .../zapiperf/plugins/flexcache/flexcache.go | 4 +- cmd/collectors/zapiperf/plugins/nic/nic.go | 13 ++-- .../zapiperf/plugins/volumetag/volumetag.go | 4 +- .../zapiperf/plugins/vscan/vscan.go | 3 +- cmd/collectors/zapiperf/zapiperf.go | 45 ++++++------- cmd/collectors/zapiperf/zapiperf_test.go | 3 +- cmd/exporters/influxdb/influxdb.go | 11 ++-- cmd/exporters/prometheus/httpd.go | 17 ++--- cmd/exporters/prometheus/prometheus.go | 13 ++-- cmd/poller/collector/asup.go | 11 ++-- cmd/poller/collector/collector.go | 19 +++--- cmd/poller/collector/helpers.go | 3 +- cmd/poller/plugin/aggregator/aggregator.go | 9 +-- .../plugin/changelog/changelog_helper.go | 5 +- cmd/poller/plugin/labelagent/label_agent.go | 5 +- cmd/poller/plugin/labelagent/parse_rules.go | 17 ++--- cmd/poller/plugin/max/max.go | 5 +- cmd/poller/plugin/metricagent/metric_agent.go | 5 +- cmd/poller/poller.go | 61 ++++++++--------- integration/certer/main.go | 19 +++--- integration/go.mod | 6 +- integration/go.sum | 12 ++-- integration/test/copy_logs_test.go | 3 +- integration/test/counter_test.go | 15 +++-- integration/test/grafana/grafana_mgr.go | 3 +- integration/test/installer/harvest.go | 7 +- integration/test/installer/installer.go | 5 +- integration/test/installer/native.go | 3 +- integration/test/installer/rpm.go | 5 +- integration/test/metric_test.go | 3 +- integration/test/utils/http_utils.go | 5 +- integration/test/utils/utils.go | 23 +------ pkg/auth/auth.go | 13 ++-- pkg/slogx/logs.go | 7 ++ pkg/util/util.go | 3 +- 90 files changed, 577 insertions(+), 508 deletions(-) create mode 100644 pkg/slogx/logs.go diff --git a/cmd/admin/admin.go b/cmd/admin/admin.go index 00e032396..c4ba5e26f 100644 --- a/cmd/admin/admin.go +++ b/cmd/admin/admin.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "github.com/netapp/harvest/v2/pkg/conf" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "github.com/spf13/cobra" "github.com/zekroTJA/timedmap/v2" @@ -55,7 +56,7 @@ func (a *Admin) startServer() { defer cancel() if err := server.Shutdown(ctx); err != nil { - a.logger.Error("Could not gracefully shutdown the admin node", slog.Any("err", err)) + a.logger.Error("Could not gracefully shutdown the admin node", slogx.Err(err)) os.Exit(1) } close(done) @@ -72,7 +73,7 @@ func (a *Admin) startServer() { if err := server.ListenAndServeTLS(a.httpSD.TLS.CertFile, a.httpSD.TLS.KeyFile); err != nil && !errors.Is(err, http.ErrServerClosed) { a.logger.Error( "Admin node could not listen", - slog.Any("err", err), + slogx.Err(err), slog.String("listen", a.listen), slog.String("ssl_cert", a.httpSD.TLS.CertFile), slog.String("ssl_key", a.httpSD.TLS.KeyFile), @@ -84,7 +85,7 @@ func (a *Admin) startServer() { if err := server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { a.logger.Error( "Admin node could not listen", - slog.Any("err", err), + slogx.Err(err), slog.String("listen", a.listen), ) os.Exit(1) @@ -144,7 +145,7 @@ func (a *Admin) apiPublish(w http.ResponseWriter, r *http.Request) { var publish pollerDetails err := decoder.Decode(&publish) if err != nil { - a.logger.Error("Unable to parse publish json", slog.Any("err", err)) + a.logger.Error("Unable to parse publish json", slogx.Err(err)) w.WriteHeader(http.StatusBadRequest) return } @@ -174,7 +175,7 @@ func (a *Admin) makeTargets() []byte { a.logger.Debug("makeTargets", slog.Int("size", len(targets))) j, err := json.Marshal(targets) if err != nil { - a.logger.Error("Failed to marshal targets", slog.Any("err", err)) + a.logger.Error("Failed to marshal targets", slogx.Err(err)) return []byte{} } return j @@ -282,7 +283,7 @@ func (a *Admin) setDuration(every string, defaultDur time.Duration, name string) if err != nil { a.logger.Warn( "Failed to parse name", - slog.Any("err", err), + slogx.Err(err), slog.String(name, every), slog.String("defaultDur", defaultDur.String()), ) diff --git a/cmd/collectors/commonutils.go b/cmd/collectors/commonutils.go index 59b1a117c..672c1ee89 100644 --- a/cmd/collectors/commonutils.go +++ b/cmd/collectors/commonutils.go @@ -4,6 +4,7 @@ import ( "github.com/netapp/harvest/v2/cmd/tools/rest" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" @@ -76,7 +77,7 @@ func InvokeRestCall(client *rest.Client, href string, logger *slog.Logger) ([]gj if err != nil { logger.Error( "Failed to fetch data", - slog.Any("err", err), + slogx.Err(err), slog.String("href", href), slog.Int("hrefLength", len(href)), ) @@ -121,7 +122,7 @@ func GetClusterTime(client *rest.Client, returnTimeOut *int, logger *slog.Logger if err != nil { logger.Error( "Failed to load cluster date", - slog.Any("err", err), + slogx.Err(err), slog.String("date", currentClusterDate.String()), ) continue @@ -259,7 +260,7 @@ func UpdateLagTime(instance *matrix.Instance, lastTransferSize *matrix.Metric, l if lastBytes, ok := lastTransferSize.GetValueFloat64(instance); ok { if healthy == "true" && schedule != "" && lastError == "" && lastBytes == 0 { if err := lagTime.SetValueFloat64(instance, 0); err != nil { - logger.Error("Unable to set value on metric", slog.Any("err", err), slog.String("metric", lagTime.GetName())) + logger.Error("Unable to set value on metric", slogx.Err(err), slog.String("metric", lagTime.GetName())) } } } @@ -402,12 +403,12 @@ func AggregatePerScanner(logger *slog.Logger, data *matrix.Matrix, latencyKey st if value != 0 { err = tempOps.SetValueFloat64(ps, tempOpsV+opsValue) if err != nil { - logger.Error("error", slog.Any("err", err)) + logger.Error("error", slogx.Err(err)) } } err = psm.SetValueFloat64(ps, fv+prod) if err != nil { - logger.Error("error", slog.Any("err", err)) + logger.Error("error", slogx.Err(err)) } } } @@ -421,7 +422,7 @@ func AggregatePerScanner(logger *slog.Logger, data *matrix.Matrix, latencyKey st if err != nil { logger.Error( "Error setting metric value", - slog.Any("err", err), + slogx.Err(err), slog.String("metric", "scan_request_dispatched_rate"), ) } @@ -434,7 +435,7 @@ func AggregatePerScanner(logger *slog.Logger, data *matrix.Matrix, latencyKey st value, _ := m.GetValueFloat64(ps) err := psm.SetValueFloat64(ps, runningTotal+value) if err != nil { - logger.Error("Failed to set value", slog.Any("err", err), slog.String("mKey", mKey)) + logger.Error("Failed to set value", slogx.Err(err), slog.String("mKey", mKey)) } } } @@ -456,7 +457,7 @@ func AggregatePerScanner(logger *slog.Logger, data *matrix.Matrix, latencyKey st if err := m.SetValueFloat64(i, value/float64(count)); err != nil { logger.Error( "Unable to set average", - slog.Any("err", err), + slogx.Err(err), slog.String("mKey", mKey), slog.String("name", m.GetName()), ) @@ -469,7 +470,7 @@ func AggregatePerScanner(logger *slog.Logger, data *matrix.Matrix, latencyKey st if opsValue, ok := ops.GetValueFloat64(i); ok && opsValue != 0 { err := m.SetValueFloat64(i, value/opsValue) if err != nil { - logger.Error("error", slog.Any("err", err)) + logger.Error("error", slogx.Err(err)) } } else { m.SetValueNAN(i) @@ -503,7 +504,7 @@ func PopulateIfgroupMetrics(portIfgroupMap map[string]string, portDataMap map[st if err != nil { logger.Debug( "Failed to add instance", - slog.Any("err", err), + slogx.Err(err), slog.String("ifgrpupInstanceKey", ifgrpupInstanceKey), ) return err @@ -525,13 +526,13 @@ func PopulateIfgroupMetrics(portIfgroupMap map[string]string, portDataMap map[st rx := nData.GetMetric("rx_bytes") rxv, _ := rx.GetValueFloat64(ifgroupInstance) if err = rx.SetValueFloat64(ifgroupInstance, readBytes+rxv); err != nil { - logger.Debug("Failed to parse value", slog.Any("value", readBytes), slog.Any("err", err)) + logger.Debug("Failed to parse value", slog.Any("value", readBytes), slogx.Err(err)) } tx := nData.GetMetric("tx_bytes") txv, _ := tx.GetValueFloat64(ifgroupInstance) if err = tx.SetValueFloat64(ifgroupInstance, writeBytes+txv); err != nil { - logger.Debug("Failed to parse value", slog.Any("value", writeBytes), slog.Any("err", err)) + logger.Debug("Failed to parse value", slog.Any("value", writeBytes), slogx.Err(err)) } } return nil diff --git a/cmd/collectors/ems/ems.go b/cmd/collectors/ems/ems.go index d210e6c2f..b394a4a78 100644 --- a/cmd/collectors/ems/ems.go +++ b/cmd/collectors/ems/ems.go @@ -10,6 +10,7 @@ import ( "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" "github.com/netapp/harvest/v2/pkg/set" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" @@ -235,7 +236,7 @@ func (e *Ems) InitCache() error { } if line1.GetNameS() == "plugins" { if err := e.LoadPlugins(line1, e, prop.Name); err != nil { - e.Logger.Error("Failed to load plugin", slog.Any("err", err)) + e.Logger.Error("Failed to load plugin", slogx.Err(err)) } } if line1.GetNameS() == "resolve_when_ems" { @@ -259,7 +260,7 @@ func (e *Ems) getTimeStampFilter(clusterTime time.Time) string { if err != nil { e.Logger.Warn( "Failed to parse duration. using default", - slog.Any("err", err), + slogx.Err(err), slog.String("defaultDataPollDuration", defaultDataPollDuration.String()), ) } @@ -528,7 +529,7 @@ func (e *Ems) HandleResults(result []gjson.Result, prop map[string][]*emsProp) ( if err = metr.SetValueFloat64(instance, 0); err != nil { e.Logger.Error( "Unable to set float key on metric", - slog.Any("err", err), + slogx.Err(err), slog.String("key", "events"), ) continue @@ -576,7 +577,7 @@ func (e *Ems) HandleResults(result []gjson.Result, prop map[string][]*emsProp) ( if instance == nil { if instance, err = mx.NewInstance(instanceKey); err != nil { - e.Logger.Error("", slog.Any("err", err), slog.String("instanceKey", instanceKey)) + e.Logger.Error("", slogx.Err(err), slog.String("instanceKey", instanceKey)) continue } } @@ -646,7 +647,7 @@ func (e *Ems) HandleResults(result []gjson.Result, prop map[string][]*emsProp) ( if !ok { if metr, err = mx.NewMetricFloat64(metric.Name); err != nil { e.Logger.Error("failed to get metric", - slog.Any("err", err), + slogx.Err(err), slog.String("name", metric.Name), ) continue @@ -657,7 +658,7 @@ func (e *Ems) HandleResults(result []gjson.Result, prop map[string][]*emsProp) ( case metric.Name == "events": if err = metr.SetValueFloat64(instance, 1); err != nil { e.Logger.Error("Unable to set float key on metric", - slog.Any("err", err), + slogx.Err(err), slog.String("key", metric.Name), slog.String("metric", metric.Label), ) @@ -665,7 +666,7 @@ func (e *Ems) HandleResults(result []gjson.Result, prop map[string][]*emsProp) ( case metric.Name == "timestamp": if err = metr.SetValueFloat64(instance, float64(time.Now().UnixMicro())); err != nil { e.Logger.Error("Unable to set timestamp on metric", - slog.Any("err", err), + slogx.Err(err), slog.String("key", metric.Name), slog.String("metric", metric.Label), ) @@ -767,7 +768,7 @@ func (e *Ems) updateMatrix(begin time.Time) { if err := eventMetric.SetValueFloat64(instance, 0); err != nil { e.Logger.Error( "Unable to set float key on metric", - slog.Any("err", err), + slogx.Err(err), slog.String("key", "events"), ) continue diff --git a/cmd/collectors/ems/ems_test.go b/cmd/collectors/ems/ems_test.go index 783633c8d..10fb84a2b 100644 --- a/cmd/collectors/ems/ems_test.go +++ b/cmd/collectors/ems/ems_test.go @@ -5,6 +5,7 @@ import ( "github.com/netapp/harvest/v2/cmd/poller/collector" "github.com/netapp/harvest/v2/cmd/poller/options" "github.com/netapp/harvest/v2/pkg/conf" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree" "github.com/netapp/harvest/v2/pkg/tree/node" "log/slog" @@ -56,7 +57,7 @@ func NewEms() *Ems { ac := collector.New("Ems", "Ems", opts, emsParams(emsConfigPath), nil) e := &Ems{} if err := e.Init(ac); err != nil { - slog.Error("", slog.Any("err", err)) + slog.Error("", slogx.Err(err)) os.Exit(1) } // Changed the resolve_after for 2 issuing ems for auto resolve testing diff --git a/cmd/collectors/fabricpool.go b/cmd/collectors/fabricpool.go index 2a72e14ae..49b793dea 100644 --- a/cmd/collectors/fabricpool.go +++ b/cmd/collectors/fabricpool.go @@ -2,6 +2,7 @@ package collectors import ( "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "log/slog" "maps" "regexp" @@ -86,7 +87,7 @@ func GetFlexGroupFabricPoolMetrics(dataMap map[string]*matrix.Matrix, object str if !strings.HasPrefix(mkey, "cloud_bin_op_latency_average") { err := fgm.SetValueFloat64(fg, fgv+value) if err != nil { - l.Error("error", slog.Any("err", err)) + l.Error("error", slogx.Err(err)) } continue } @@ -113,12 +114,12 @@ func GetFlexGroupFabricPoolMetrics(dataMap map[string]*matrix.Matrix, object str if value != 0 { err = tempOps.SetValueFloat64(fg, tempOpsV+opsValue) if err != nil { - l.Error("error", slog.Any("err", err)) + l.Error("error", slogx.Err(err)) } } err = fgm.SetValueFloat64(fg, fgv+prod) if err != nil { - l.Error("error", slog.Any("err", err)) + l.Error("error", slogx.Err(err)) } } } @@ -142,7 +143,7 @@ func GetFlexGroupFabricPoolMetrics(dataMap map[string]*matrix.Matrix, object str if opsValue, ok := ops.GetValueFloat64(i); ok && opsValue != 0 { err := m.SetValueFloat64(i, value/opsValue) if err != nil { - l.Error("error", slog.Any("err", err)) + l.Error("error", slogx.Err(err)) } } else { m.SetValueNAN(i) diff --git a/cmd/collectors/keyperf/keyperf.go b/cmd/collectors/keyperf/keyperf.go index 1dd92db86..191dd9f77 100644 --- a/cmd/collectors/keyperf/keyperf.go +++ b/cmd/collectors/keyperf/keyperf.go @@ -7,6 +7,7 @@ import ( "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/tidwall/gjson" "log/slog" "strconv" @@ -329,7 +330,7 @@ func (kp *KeyPerf) pollData( key := orderedKeys[i] counter := counterMap[key] if counter == nil { - kp.Logger.Error("Missing counter", slog.Any("err", err), slog.String("counter", metric.GetName())) + kp.Logger.Error("Missing counter", slogx.Err(err), slog.String("counter", metric.GetName())) continue } property := counter.counterType @@ -345,7 +346,7 @@ func (kp *KeyPerf) pollData( // all other properties - first calculate delta if skips, err = curMat.Delta(key, prevMat, kp.Logger); err != nil { - kp.Logger.Error("Calculate delta", slog.Any("err", err), slog.String("key", key)) + kp.Logger.Error("Calculate delta", slogx.Err(err), slog.String("key", key)) continue } totalSkips += skips @@ -392,7 +393,7 @@ func (kp *KeyPerf) pollData( } if err != nil { - kp.Logger.Error("Division by base", slog.Any("err", err), slog.String("key", key)) + kp.Logger.Error("Division by base", slogx.Err(err), slog.String("key", key)) continue } totalSkips += skips @@ -404,7 +405,7 @@ func (kp *KeyPerf) pollData( if property == "percent" { if skips, err = curMat.MultiplyByScalar(key, 100); err != nil { - kp.Logger.Error("Multiply by scalar", slog.Any("err", err), slog.String("key", key)) + kp.Logger.Error("Multiply by scalar", slogx.Err(err), slog.String("key", key)) } else { totalSkips += skips } @@ -432,7 +433,7 @@ func (kp *KeyPerf) pollData( if skips, err = curMat.Divide(orderedKeys[i], timestampMetricName); err != nil { kp.Logger.Error( "Calculate rate", - slog.Any("err", err), + slogx.Err(err), slog.Int("i", i), slog.String("key", key), slog.Int("instIndex", instIndex), diff --git a/cmd/collectors/power.go b/cmd/collectors/power.go index 20d616c69..82628bd22 100644 --- a/cmd/collectors/power.go +++ b/cmd/collectors/power.go @@ -8,6 +8,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" "net/http" @@ -448,7 +449,7 @@ func (s *Sensor) Init() error { timeout, _ := time.ParseDuration(rest.DefaultTimeout) if s.client, err = rest.New(conf.ZapiPoller(s.ParentParams), timeout, s.Auth); err != nil { - s.SLogger.Error("connecting", slog.Any("err", err)) + s.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -473,7 +474,7 @@ func (s *Sensor) Init() error { for _, k := range eMetrics { err := matrix.CreateMetric(k, s.data) if err != nil { - s.SLogger.Warn("error while creating metric", slog.Any("err", err), slog.String("key", k)) + s.SLogger.Warn("error while creating metric", slogx.Err(err), slog.String("key", k)) } } return nil diff --git a/cmd/collectors/qosCommon.go b/cmd/collectors/qosCommon.go index 0a4824b83..8af534070 100644 --- a/cmd/collectors/qosCommon.go +++ b/cmd/collectors/qosCommon.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "log/slog" "regexp" "strconv" @@ -50,7 +51,7 @@ func QosSetLabel(labelName string, data *matrix.Matrix, instance *matrix.Instanc if m != nil { err := m.SetValueString(instance, value) if err != nil { - logger.Error("Unable to set metric", slog.String(labelName, value), slog.Any("err", err)) + logger.Error("Unable to set metric", slog.String(labelName, value), slogx.Err(err)) } } } diff --git a/cmd/collectors/rest/plugins/aggregate/aggregate.go b/cmd/collectors/rest/plugins/aggregate/aggregate.go index 8ede0b186..3912045b3 100644 --- a/cmd/collectors/rest/plugins/aggregate/aggregate.go +++ b/cmd/collectors/rest/plugins/aggregate/aggregate.go @@ -2,6 +2,7 @@ package aggregate import ( "fmt" + "github.com/netapp/harvest/v2/pkg/slogx" "log/slog" "time" @@ -101,9 +102,9 @@ func (a *Aggregate) collectObjectStoreData(aggrSpaceMat, data *matrix.Matrix) { records, err := a.getObjectStoreData() if err != nil { if errs.IsRestErr(err, errs.APINotFound) { - a.SLogger.Debug("API not found", slog.Any("err", err)) + a.SLogger.Debug("API not found", slogx.Err(err)) } else { - a.SLogger.Error("Failed to collect object store data", slog.Any("err", err)) + a.SLogger.Error("Failed to collect object store data", slogx.Err(err)) } return } @@ -149,7 +150,7 @@ func (a *Aggregate) collectObjectStoreData(aggrSpaceMat, data *matrix.Matrix) { if err := aggrSpaceMat.GetMetric("logical_used").SetValueString(instance, logicalUsed); err != nil { a.SLogger.Error( "Unable to set value on metric", - slog.Any("err", err), + slogx.Err(err), slog.String("metric", "logical_used"), ) } @@ -159,7 +160,7 @@ func (a *Aggregate) collectObjectStoreData(aggrSpaceMat, data *matrix.Matrix) { if err := aggrSpaceMat.GetMetric("physical_used").SetValueString(instance, physicalUsed); err != nil { a.SLogger.Error( "Unable to set value on metric", - slog.Any("err", err), + slogx.Err(err), slog.String("metric", "physical_used"), ) } diff --git a/cmd/collectors/rest/plugins/certificate/certificate.go b/cmd/collectors/rest/plugins/certificate/certificate.go index 9e17a8b05..0681f08f1 100644 --- a/cmd/collectors/rest/plugins/certificate/certificate.go +++ b/cmd/collectors/rest/plugins/certificate/certificate.go @@ -13,6 +13,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" ontap "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" "log/slog" @@ -39,7 +40,7 @@ func (c *Certificate) Init() error { timeout, _ := time.ParseDuration(rest.DefaultTimeout) if c.client, err = rest.New(conf.ZapiPoller(c.ParentParams), timeout, c.Auth); err != nil { - c.SLogger.Error("connecting", slog.Any("err", err)) + c.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -71,9 +72,9 @@ func (c *Certificate) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, // invoke private vserver cli rest and get admin vserver name if adminVserver, err = c.GetAdminVserver(); err != nil { if ontap.IsRestErr(err, ontap.APINotFound) { - c.SLogger.Debug("Failed to collect admin SVM", slog.Any("err", err)) + c.SLogger.Debug("Failed to collect admin SVM", slogx.Err(err)) } else { - c.SLogger.Error("Failed to collect admin SVM", slog.Any("err", err)) + c.SLogger.Error("Failed to collect admin SVM", slogx.Err(err)) } return nil, nil, nil } @@ -81,9 +82,9 @@ func (c *Certificate) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, // invoke private ssl cli rest and get the admin SVM's serial number if adminVserverSerial, err = c.GetSecuritySsl(adminVserver); err != nil { if ontap.IsRestErr(err, ontap.APINotFound) { - c.SLogger.Debug("Failed to collect admin SVM's serial number", slog.Any("err", err)) + c.SLogger.Debug("Failed to collect admin SVM's serial number", slogx.Err(err)) } else { - c.SLogger.Error("Failed to collect admin SVM's serial number", slog.Any("err", err)) + c.SLogger.Error("Failed to collect admin SVM's serial number", slogx.Err(err)) } return nil, nil, nil } @@ -145,7 +146,7 @@ func (c *Certificate) setCertificateIssuerType(instance *matrix.Instance) { if cert, err = x509.ParseCertificate(certDecoded.Bytes); err != nil { c.SLogger.Warn( "PEM formatted object is not an X.509 certificate. Only PEM formatted X.509 certificate input is allowed", - slog.Any("err", err), + slogx.Err(err), ) instance.SetLabel("certificateIssuerType", "unknown") return diff --git a/cmd/collectors/rest/plugins/health/health.go b/cmd/collectors/rest/plugins/health/health.go index 2c641b46f..c612a96bd 100644 --- a/cmd/collectors/rest/plugins/health/health.go +++ b/cmd/collectors/rest/plugins/health/health.go @@ -8,6 +8,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" goversion "github.com/netapp/harvest/v2/third_party/go-version" "github.com/tidwall/gjson" @@ -98,7 +99,7 @@ func (h *Health) initMatrix(name string, prefix string, inputMat map[string]*mat for _, k := range metrics { err := matrix.CreateMetric(k, inputMat[name]) if err != nil { - h.SLogger.Warn("error while creating metric", slog.Any("err", err), slog.String("key", k)) + h.SLogger.Warn("error while creating metric", slogx.Err(err), slog.String("key", k)) return err } } @@ -113,7 +114,7 @@ func (h *Health) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util if err != nil { h.SLogger.Error( "Failed to parse version", - slog.Any("err", err), + slogx.Err(err), slog.String("version", clusterVersion), ) return nil, nil, nil @@ -123,7 +124,7 @@ func (h *Health) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util if err != nil { h.SLogger.Error( "Failed to parse version", - slog.Any("err", err), + slogx.Err(err), slog.String("version", version96), ) return nil, nil, nil @@ -137,7 +138,7 @@ func (h *Health) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util // remove all metrics as analytics label may change over time err = h.InitAllMatrix() if err != nil { - h.SLogger.Warn("error while init matrix", slog.Any("err", err)) + h.SLogger.Warn("error while init matrix", slogx.Err(err)) return nil, nil, err } for k := range h.data { @@ -200,9 +201,9 @@ func (h *Health) collectLicenseAlerts() int { records, err := h.getNonCompliantLicense() if err != nil { if errs.IsRestErr(err, errs.APINotFound) { - h.SLogger.Debug("API not found", slog.Any("err", err)) + h.SLogger.Debug("API not found", slogx.Err(err)) } else { - h.SLogger.Error("Failed to collect analytic data", slog.Any("err", err)) + h.SLogger.Error("Failed to collect analytic data", slogx.Err(err)) } return 0 } @@ -236,9 +237,9 @@ func (h *Health) collectVolumeMoveAlerts() int { records, err := h.getMoveFailedVolumes() if err != nil { if errs.IsRestErr(err, errs.APINotFound) { - h.SLogger.Debug("API not found", slog.Any("err", err)) + h.SLogger.Debug("API not found", slogx.Err(err)) } else { - h.SLogger.Error("Failed to collect analytic data", slog.Any("err", err)) + h.SLogger.Error("Failed to collect analytic data", slogx.Err(err)) } return 0 } @@ -272,13 +273,13 @@ func (h *Health) collectVolumeRansomwareAlerts() int { clusterVersion := h.client.Cluster().GetVersion() ontapVersion, err := goversion.NewVersion(clusterVersion) if err != nil { - h.SLogger.Error("Failed to parse version", slog.Any("err", err), slog.String("version", clusterVersion)) + h.SLogger.Error("Failed to parse version", slogx.Err(err), slog.String("version", clusterVersion)) return 0 } version910 := "9.10" version910After, err := goversion.NewVersion(version910) if err != nil { - h.SLogger.Error("Failed to parse version", slog.Any("err", err), slog.String("version", version910)) + h.SLogger.Error("Failed to parse version", slogx.Err(err), slog.String("version", version910)) return 0 } @@ -288,9 +289,9 @@ func (h *Health) collectVolumeRansomwareAlerts() int { records, err := h.getRansomwareVolumes() if err != nil { if errs.IsRestErr(err, errs.APINotFound) { - h.SLogger.Debug("API not found", slog.Any("err", err)) + h.SLogger.Debug("API not found", slogx.Err(err)) } else { - h.SLogger.Error("Failed to collect analytic data", slog.Any("err", err)) + h.SLogger.Error("Failed to collect analytic data", slogx.Err(err)) } return 0 } @@ -323,9 +324,9 @@ func (h *Health) collectNetworkInterfacesAlerts() int { records, err := h.getNonHomeLIFs() if err != nil { if errs.IsRestErr(err, errs.APINotFound) { - h.SLogger.Debug("API not found", slog.Any("err", err)) + h.SLogger.Debug("API not found", slogx.Err(err)) } else { - h.SLogger.Error("Failed to collect analytic data", slog.Any("err", err)) + h.SLogger.Error("Failed to collect analytic data", slogx.Err(err)) } return 0 } @@ -359,9 +360,9 @@ func (h *Health) collectNetworkFCPortAlerts() int { records, err := h.getFCPorts() if err != nil { if errs.IsRestErr(err, errs.APINotFound) { - h.SLogger.Debug("API not found", slog.Any("err", err)) + h.SLogger.Debug("API not found", slogx.Err(err)) } else { - h.SLogger.Error("Failed to collect analytic data", slog.Any("err", err)) + h.SLogger.Error("Failed to collect analytic data", slogx.Err(err)) } return 0 } @@ -395,9 +396,9 @@ func (h *Health) collectNetworkEthernetPortAlerts() int { records, err := h.getEthernetPorts() if err != nil { if errs.IsRestErr(err, errs.APINotFound) { - h.SLogger.Debug("API not found", slog.Any("err", err)) + h.SLogger.Debug("API not found", slogx.Err(err)) } else { - h.SLogger.Error("Failed to collect analytic data", slog.Any("err", err)) + h.SLogger.Error("Failed to collect analytic data", slogx.Err(err)) } return 0 } @@ -433,9 +434,9 @@ func (h *Health) collectNodeAlerts() int { records, err := h.getNodes() if err != nil { if errs.IsRestErr(err, errs.APINotFound) { - h.SLogger.Debug("API not found", slog.Any("err", err)) + h.SLogger.Debug("API not found", slogx.Err(err)) } else { - h.SLogger.Error("Failed to collect analytic data", slog.Any("err", err)) + h.SLogger.Error("Failed to collect analytic data", slogx.Err(err)) } return 0 } @@ -466,9 +467,9 @@ func (h *Health) collectHAAlerts() int { records, err := h.getHADown() if err != nil { if errs.IsRestErr(err, errs.APINotFound) { - h.SLogger.Debug("API not found", slog.Any("err", err)) + h.SLogger.Debug("API not found", slogx.Err(err)) } else { - h.SLogger.Error("Failed to collect analytic data", slog.Any("err", err)) + h.SLogger.Error("Failed to collect analytic data", slogx.Err(err)) } return 0 } @@ -509,9 +510,9 @@ func (h *Health) collectShelfAlerts() int { records, err := h.getShelves() if err != nil { if errs.IsRestErr(err, errs.APINotFound) { - h.SLogger.Debug("API not found", slog.Any("err", err)) + h.SLogger.Debug("API not found", slogx.Err(err)) } else { - h.SLogger.Error("Failed to collect analytic data", slog.Any("err", err)) + h.SLogger.Error("Failed to collect analytic data", slogx.Err(err)) } return 0 } @@ -552,7 +553,7 @@ func (h *Health) collectSupportAlerts() int { supportAlertCount := 0 clusterTime, err := collectors.GetClusterTime(h.client, nil, h.SLogger) if err != nil { - h.SLogger.Error("Failed to collect cluster time", slog.Any("err", err)) + h.SLogger.Error("Failed to collect cluster time", slogx.Err(err)) return 0 } toTime := clusterTime.Unix() @@ -562,9 +563,9 @@ func (h *Health) collectSupportAlerts() int { records, err := h.getSupportAlerts(filter) if err != nil { if errs.IsRestErr(err, errs.APINotFound) { - h.SLogger.Debug("API not found", slog.Any("err", err)) + h.SLogger.Debug("API not found", slogx.Err(err)) } else { - h.SLogger.Error("Failed to collect analytic data", slog.Any("err", err)) + h.SLogger.Error("Failed to collect analytic data", slogx.Err(err)) } return 0 } @@ -605,9 +606,9 @@ func (h *Health) collectDiskAlerts() int { records, err := h.getDisks() if err != nil { if errs.IsRestErr(err, errs.APINotFound) { - h.SLogger.Debug("API not found", slog.Any("err", err)) + h.SLogger.Debug("API not found", slogx.Err(err)) } else { - h.SLogger.Error("Failed to collect analytic data", slog.Any("err", err)) + h.SLogger.Error("Failed to collect analytic data", slogx.Err(err)) } return 0 } @@ -781,7 +782,7 @@ func (h *Health) getTimeStampFilter(clusterTime time.Time) string { if err != nil { h.SLogger.Warn( "Failed to parse duration. using default", - slog.Any("err", err), + slogx.Err(err), slog.String("defaultDataPollDuration", defaultDataPollDuration.String()), ) } @@ -797,7 +798,7 @@ func (h *Health) setAlertMetric(mat *matrix.Matrix, instance *matrix.Instance, v if m, err = mat.NewMetricFloat64("alerts"); err != nil { h.SLogger.Warn( "error while creating metric", - slog.Any("err", err), + slogx.Err(err), slog.String("key", "alerts"), ) return @@ -806,7 +807,7 @@ func (h *Health) setAlertMetric(mat *matrix.Matrix, instance *matrix.Instance, v if err = m.SetValueFloat64(instance, value); err != nil { h.SLogger.Error( "Unable to set value on metric", - slog.Any("err", err), + slogx.Err(err), slog.String("metric", "alerts"), ) } diff --git a/cmd/collectors/rest/plugins/metroclustercheck/metroclustercheck.go b/cmd/collectors/rest/plugins/metroclustercheck/metroclustercheck.go index 102de9cd6..5f4cc41bf 100644 --- a/cmd/collectors/rest/plugins/metroclustercheck/metroclustercheck.go +++ b/cmd/collectors/rest/plugins/metroclustercheck/metroclustercheck.go @@ -3,6 +3,7 @@ package metroclustercheck import ( "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" @@ -95,7 +96,7 @@ func (m *MetroclusterCheck) update(objectInfo string, object string) { } if newDetailInstance, err = m.data.NewInstance(key); err != nil { - m.SLogger.Error("Failed to create instance", slog.Any("err", err), slog.String("key", key)) + m.SLogger.Error("Failed to create instance", slogx.Err(err), slog.String("key", key)) continue } newDetailInstance.SetLabel("name", name) @@ -120,7 +121,7 @@ func (m *MetroclusterCheck) update(objectInfo string, object string) { func (m *MetroclusterCheck) createMetric(metricName string) error { if _, err := m.data.NewMetricFloat64(metricName, metricName); err != nil { - m.SLogger.Error("Failed to create metric", slog.Any("err", err), slog.String("metric", metricName)) + m.SLogger.Error("Failed to create metric", slogx.Err(err), slog.String("metric", metricName)) return err } return nil @@ -134,7 +135,7 @@ func (m *MetroclusterCheck) setValue(metricName string, newDetailInstance *matri met := m.data.GetMetric(metricName) if err := met.SetValueFloat64(newDetailInstance, value); err != nil { - m.SLogger.Error("Failed to parse value", slog.Any("err", err), slog.Float64("value", value)) + m.SLogger.Error("Failed to parse value", slogx.Err(err), slog.Float64("value", value)) } else { m.SLogger.Debug("added value", slog.Float64("value", value)) } diff --git a/cmd/collectors/rest/plugins/netroute/netroute.go b/cmd/collectors/rest/plugins/netroute/netroute.go index 5bcc46c60..093aa890c 100644 --- a/cmd/collectors/rest/plugins/netroute/netroute.go +++ b/cmd/collectors/rest/plugins/netroute/netroute.go @@ -7,6 +7,7 @@ package netroute import ( "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" @@ -81,7 +82,7 @@ func (n *NetRoute) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *ut index := cluster + "_" + strconv.Itoa(count) interfaceInstance, err := n.data.NewInstance(index) if err != nil { - n.SLogger.Error("add instance failed", slog.Any("err", err), slog.String("key", key)) + n.SLogger.Error("add instance failed", slogx.Err(err), slog.String("key", key)) return nil, nil, err } diff --git a/cmd/collectors/rest/plugins/ontaps3service/ontaps3service.go b/cmd/collectors/rest/plugins/ontaps3service/ontaps3service.go index 691119dfd..18884de95 100644 --- a/cmd/collectors/rest/plugins/ontaps3service/ontaps3service.go +++ b/cmd/collectors/rest/plugins/ontaps3service/ontaps3service.go @@ -11,6 +11,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" "log/slog" @@ -44,7 +45,7 @@ func (o *OntapS3Service) Init() error { o.SLogger.Debug("Using default timeout", slog.String("timeout", timeout.String())) } if o.client, err = rest.New(conf.ZapiPoller(o.ParentParams), timeout, o.Auth); err != nil { - o.SLogger.Error("connecting", slog.Any("err", err)) + o.SLogger.Error("connecting", slogx.Err(err)) return err } diff --git a/cmd/collectors/rest/plugins/qospolicyadaptive/qospolicyadaptive.go b/cmd/collectors/rest/plugins/qospolicyadaptive/qospolicyadaptive.go index 89b8e8d8e..efefdd0f1 100644 --- a/cmd/collectors/rest/plugins/qospolicyadaptive/qospolicyadaptive.go +++ b/cmd/collectors/rest/plugins/qospolicyadaptive/qospolicyadaptive.go @@ -4,6 +4,7 @@ import ( "github.com/netapp/harvest/v2/cmd/collectors" "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" ) @@ -29,7 +30,7 @@ func (p *QosPolicyAdaptive) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Ma for _, k := range metrics { err := matrix.CreateMetric(k, data) if err != nil { - p.SLogger.Error("error while creating metric", slog.Any("err", err), slog.String("key", k)) + p.SLogger.Error("error while creating metric", slogx.Err(err), slog.String("key", k)) } } @@ -55,7 +56,7 @@ func (p *QosPolicyAdaptive) setIOPs(data *matrix.Matrix, instance *matrix.Instan if m != nil { err = m.SetValueString(instance, xput.IOPS) if err != nil { - p.SLogger.Error("Unable to set metric", slog.Any("err", err), slog.String(labelName, xput.IOPS)) + p.SLogger.Error("Unable to set metric", slogx.Err(err), slog.String(labelName, xput.IOPS)) } } } diff --git a/cmd/collectors/rest/plugins/qospolicyfixed/qospolicyfixed.go b/cmd/collectors/rest/plugins/qospolicyfixed/qospolicyfixed.go index 6c215f64c..7e48672fa 100644 --- a/cmd/collectors/rest/plugins/qospolicyfixed/qospolicyfixed.go +++ b/cmd/collectors/rest/plugins/qospolicyfixed/qospolicyfixed.go @@ -4,6 +4,7 @@ import ( "github.com/netapp/harvest/v2/cmd/collectors" "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" "strings" @@ -31,7 +32,7 @@ func (q *QosPolicyFixed) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matri for _, k := range metrics { err := matrix.CreateMetric(k, data) if err != nil { - q.SLogger.Error("error while creating metric", slog.Any("err", err), slog.String("key", k)) + q.SLogger.Error("error while creating metric", slogx.Err(err), slog.String("key", k)) return nil, nil, err } } @@ -55,12 +56,12 @@ func (q *QosPolicyFixed) setFixed(data *matrix.Matrix, instance *matrix.Instance } minV, err := collectors.ZapiXputToRest(before) if err != nil { - q.SLogger.Error("Failed to parse fixed xput label", slog.Any("err", err), slog.String("label", before)) + q.SLogger.Error("Failed to parse fixed xput label", slogx.Err(err), slog.String("label", before)) return } maxV, err := collectors.ZapiXputToRest(after) if err != nil { - q.SLogger.Error("Failed to parse fixed xput label", slog.Any("err", err), slog.String("label", after)) + q.SLogger.Error("Failed to parse fixed xput label", slogx.Err(err), slog.String("label", after)) return } collectors.QosSetLabel("min_throughput_iops", data, instance, minV.IOPS, q.SLogger) diff --git a/cmd/collectors/rest/plugins/quota/quota.go b/cmd/collectors/rest/plugins/quota/quota.go index ad048dd0d..66583ec75 100644 --- a/cmd/collectors/rest/plugins/quota/quota.go +++ b/cmd/collectors/rest/plugins/quota/quota.go @@ -3,6 +3,7 @@ package quota import ( "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" ) @@ -34,7 +35,7 @@ func (q *Quota) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util. if data.GetMetric("threshold") == nil { _, err := data.NewMetricFloat64("threshold", "threshold") if err != nil { - q.SLogger.Error("add metric", slog.Any("err", err)) + q.SLogger.Error("add metric", slogx.Err(err)) } } @@ -47,7 +48,7 @@ func (q *Quota) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util. for metricName, m := range metricsMap { _, err := data.NewMetricFloat64(metricName, m.GetName()) if err != nil { - q.SLogger.Error("add metric", slog.Any("err", err)) + q.SLogger.Error("add metric", slogx.Err(err)) } } @@ -98,7 +99,7 @@ func (q *Quota) handlingQuotaMetrics(instanceMap map[string]*matrix.Instance, me quotaInstanceKey := index + volumeUUID + metricName quotaInstance, err := data.NewInstance(quotaInstanceKey) if err != nil { - q.SLogger.Debug("add instance", slog.String("metricName", metricName), slog.Any("err", err)) + q.SLogger.Debug("add instance", slog.String("metricName", metricName), slogx.Err(err)) return err } // set labels @@ -116,7 +117,7 @@ func (q *Quota) handlingQuotaMetrics(instanceMap map[string]*matrix.Instance, me if err := t.SetValueFloat64(quotaInstance, value); err != nil { q.SLogger.Error( "Failed to parse value", - slog.Any("err", err), + slogx.Err(err), slog.String("metricName", metricName), slog.Float64("value", value), ) @@ -132,7 +133,7 @@ func (q *Quota) handlingQuotaMetrics(instanceMap map[string]*matrix.Instance, me if err = t.SetValueFloat64(quotaInstance, value); err != nil { q.SLogger.Error( "Failed to parse value", - slog.Any("err", err), + slogx.Err(err), slog.String("metricName", metricName), slog.Float64("value", value), ) diff --git a/cmd/collectors/rest/plugins/snapmirror/snapmirror.go b/cmd/collectors/rest/plugins/snapmirror/snapmirror.go index 73e529983..6ef8117d9 100644 --- a/cmd/collectors/rest/plugins/snapmirror/snapmirror.go +++ b/cmd/collectors/rest/plugins/snapmirror/snapmirror.go @@ -10,6 +10,7 @@ import ( "github.com/netapp/harvest/v2/cmd/tools/rest" "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "log/slog" @@ -48,7 +49,7 @@ func (m *SnapMirror) Init() error { timeout, _ := time.ParseDuration(rest.DefaultTimeout) if m.client, err = rest.New(conf.ZapiPoller(m.ParentParams), timeout, m.Auth); err != nil { - m.SLogger.Error("connecting", slog.Any("err", err)) + m.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -130,7 +131,7 @@ func (m *SnapMirror) getSVMPeerData(cluster string) error { result, err := rest.FetchAll(m.client, href) if err != nil { - m.SLogger.Error("Failed to fetch data", slog.Any("err", err), slog.String("href", href)) + m.SLogger.Error("Failed to fetch data", slogx.Err(err), slog.String("href", href)) return err } @@ -161,7 +162,7 @@ func (m *SnapMirror) getClusterPeerData() error { result, err := rest.FetchAll(m.client, href) if err != nil { - m.SLogger.Error("Failed to fetch data", slog.Any("err", err), slog.String("href", href)) + m.SLogger.Error("Failed to fetch data", slogx.Err(err), slog.String("href", href)) return err } @@ -256,7 +257,7 @@ func (m *SnapMirror) handleCGRelationships(data *matrix.Matrix, keys []string) { cgVolumeInstanceKey := key + sourceVol + destinationVol if cgVolumeInstance, err = m.data.NewInstance(cgVolumeInstanceKey); err != nil { - m.SLogger.Error("", slog.Any("err", err), slog.String("key", cgVolumeInstanceKey)) + m.SLogger.Error("", slogx.Err(err), slog.String("key", cgVolumeInstanceKey)) continue } diff --git a/cmd/collectors/rest/plugins/svm/svm.go b/cmd/collectors/rest/plugins/svm/svm.go index 34c5b62b7..ec79a02d6 100644 --- a/cmd/collectors/rest/plugins/svm/svm.go +++ b/cmd/collectors/rest/plugins/svm/svm.go @@ -11,9 +11,9 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" - "log/slog" "regexp" "sort" "strconv" @@ -58,7 +58,7 @@ func (s *SVM) Init() error { timeout, _ := time.ParseDuration(rest.DefaultTimeout) if s.client, err = rest.New(conf.ZapiPoller(s.ParentParams), timeout, s.Auth); err != nil { - s.SLogger.Error("connecting", slog.Any("err", err)) + s.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -85,45 +85,45 @@ func (s *SVM) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Me // update nsswitch info if s.nsswitchInfo, err = s.GetNSSwitchInfo(data); err != nil { if errs.IsRestErr(err, errs.APINotFound) { - s.SLogger.Debug("Failed to collect nsswitch info", slog.Any("err", err)) + s.SLogger.Debug("Failed to collect nsswitch info", slogx.Err(err)) } else { - s.SLogger.Warn("Failed to collect nsswitch info", slog.Any("err", err)) + s.SLogger.Warn("Failed to collect nsswitch info", slogx.Err(err)) } } // invoke api/protocols/nfs/kerberos/interfaces rest and get nfs_kerberos_protocol_enabled if s.kerberosInfo, err = s.GetKerberosConfig(); err != nil { if errs.IsRestErr(err, errs.APINotFound) { - s.SLogger.Debug("Failed to collect kerberos config", slog.Any("err", err)) + s.SLogger.Debug("Failed to collect kerberos config", slogx.Err(err)) } else { - s.SLogger.Error("Failed to collect kerberos config", slog.Any("err", err)) + s.SLogger.Error("Failed to collect kerberos config", slogx.Err(err)) } } // invoke api/protocols/fpolicy rest and get fpolicy_enabled, fpolicy_name if s.fpolicyInfo, err = s.GetFpolicy(); err != nil { if errs.IsRestErr(err, errs.APINotFound) { - s.SLogger.Debug("Failed to collect fpolicy info", slog.Any("err", err)) + s.SLogger.Debug("Failed to collect fpolicy info", slogx.Err(err)) } else { - s.SLogger.Error("Failed to collect fpolicy info", slog.Any("err", err)) + s.SLogger.Error("Failed to collect fpolicy info", slogx.Err(err)) } } // invoke api/protocols/san/iscsi/services rest and get iscsi_service_enabled if s.iscsiServiceInfo, err = s.GetIscsiServices(); err != nil { if errs.IsRestErr(err, errs.APINotFound) { - s.SLogger.Debug("Failed to collect iscsi service info", slog.Any("err", err)) + s.SLogger.Debug("Failed to collect iscsi service info", slogx.Err(err)) } else { - s.SLogger.Error("Failed to collect iscsi service info", slog.Any("err", err)) + s.SLogger.Error("Failed to collect iscsi service info", slogx.Err(err)) } } // invoke api/protocols/san/iscsi/credentials rest and get iscsi_authentication_type if s.iscsiCredentialInfo, err = s.GetIscsiCredentials(); err != nil { if errs.IsRestErr(err, errs.APINotFound) { - s.SLogger.Debug("Failed to collect iscsi credential info", slog.Any("err", err)) + s.SLogger.Debug("Failed to collect iscsi credential info", slogx.Err(err)) } else { - s.SLogger.Error("Failed to collect iscsi credential info", slog.Any("err", err)) + s.SLogger.Error("Failed to collect iscsi credential info", slogx.Err(err)) } } diff --git a/cmd/collectors/rest/plugins/volume/volume.go b/cmd/collectors/rest/plugins/volume/volume.go index 290001719..e13792870 100644 --- a/cmd/collectors/rest/plugins/volume/volume.go +++ b/cmd/collectors/rest/plugins/volume/volume.go @@ -12,6 +12,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" @@ -64,7 +65,7 @@ func (v *Volume) Init() error { timeout, _ := time.ParseDuration(rest.DefaultTimeout) if v.client, err = rest.New(conf.ZapiPoller(v.ParentParams), timeout, v.Auth); err != nil { - v.SLogger.Error("connecting", slog.Any("err", err)) + v.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -79,7 +80,7 @@ func (v *Volume) Init() error { v.arw.SetExportOptions(exportOptions) _, err = v.arw.NewMetricFloat64("status", "status") if err != nil { - v.SLogger.Error("add metric", slog.Any("err", err)) + v.SLogger.Error("add metric", slogx.Err(err)) return err } @@ -103,9 +104,9 @@ func (v *Volume) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util // invoke disk rest and populate info in aggrsMap if disks, err := v.getEncryptedDisks(); err != nil { if errs.IsRestErr(err, errs.APINotFound) { - v.SLogger.Debug("Failed to collect disk data", slog.Any("err", err)) + v.SLogger.Debug("Failed to collect disk data", slogx.Err(err)) } else { - v.SLogger.Error("Failed to collect disk data", slog.Any("err", err)) + v.SLogger.Error("Failed to collect disk data", slogx.Err(err)) } } else { // update aggrsMap based on disk data @@ -115,7 +116,7 @@ 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", slog.Any("err", err)) + v.SLogger.Error("Failed to collect volume info data", slogx.Err(err)) } // update volume instance labels @@ -133,7 +134,7 @@ func (v *Volume) updateVolumeLabels(data *matrix.Matrix, volumeMap map[string]vo cloneSplitEstimateMetric := data.GetMetric("clone_split_estimate") if cloneSplitEstimateMetric == nil { if cloneSplitEstimateMetric, err = data.NewMetricFloat64("clone_split_estimate"); err != nil { - v.SLogger.Error("error while creating clone split estimate metric", slog.Any("err", err)) + v.SLogger.Error("error while creating clone split estimate metric", slogx.Err(err)) return } } @@ -160,7 +161,7 @@ func (v *Volume) updateVolumeLabels(data *matrix.Matrix, volumeMap map[string]vo if err = cloneSplitEstimateMetric.SetValueFloat64(volume, vInfo.cloneSplitEstimateMetric); err != nil { v.SLogger.Error( "error while setting value on metric", - slog.Any("err", err), + slogx.Err(err), slog.String("metric", "clone_split_estimate"), ) } @@ -215,7 +216,7 @@ func (v *Volume) handleARWProtection(data *matrix.Matrix) { if arwStartTimeValue, err = time.Parse(time.RFC3339, arwStartTime); err != nil { v.SLogger.Error( "Failed to parse arw start time", - slog.Any("err", err), + slogx.Err(err), slog.String("arwStartTime", arwStartTime), ) arwStartTimeValue = time.Now() @@ -232,7 +233,7 @@ func (v *Volume) handleARWProtection(data *matrix.Matrix) { if arwInstance, err = v.arw.NewInstance(arwInstanceKey); err != nil { v.SLogger.Error( "Failed to create arw instance", - slog.Any("err", err), + slogx.Err(err), slog.String("arwInstanceKey", arwInstanceKey), ) return @@ -243,7 +244,7 @@ func (v *Volume) handleARWProtection(data *matrix.Matrix) { // populate numeric data value := 1.0 if err = m.SetValueFloat64(arwInstance, value); err != nil { - v.SLogger.Error("Failed to parse value", slog.Any("err", err), slog.Float64("value", value)) + v.SLogger.Error("Failed to parse value", slogx.Err(err), slog.Float64("value", value)) } else { v.SLogger.Debug("added value", slog.Float64("value", value)) } diff --git a/cmd/collectors/rest/plugins/volumeanalytics/volumeanalytics.go b/cmd/collectors/rest/plugins/volumeanalytics/volumeanalytics.go index 6d0182f7e..835b95631 100644 --- a/cmd/collectors/rest/plugins/volumeanalytics/volumeanalytics.go +++ b/cmd/collectors/rest/plugins/volumeanalytics/volumeanalytics.go @@ -6,6 +6,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" goversion "github.com/netapp/harvest/v2/third_party/go-version" "github.com/tidwall/gjson" @@ -62,7 +63,7 @@ func (v *VolumeAnalytics) Init() error { timeout, _ := time.ParseDuration(rest.DefaultTimeout) if v.client, err = rest.New(conf.ZapiPoller(v.ParentParams), timeout, v.Auth); err != nil { - v.SLogger.Error("connecting", slog.Any("err", err)) + v.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -102,7 +103,7 @@ func (v *VolumeAnalytics) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matr ontapVersion, err := goversion.NewVersion(clusterVersion) if err != nil { v.SLogger.Error("Failed to parse version", - slog.Any("err", err), + slogx.Err(err), slog.String("version", clusterVersion), ) return nil, nil, nil @@ -111,7 +112,7 @@ func (v *VolumeAnalytics) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matr version98After, err := goversion.NewVersion(version98) if err != nil { v.SLogger.Error("Failed to parse version", - slog.Any("err", err), + slogx.Err(err), slog.String("version", version98), ) return nil, nil, nil @@ -125,7 +126,7 @@ func (v *VolumeAnalytics) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matr // remove all metrics as analytics label may change over time err = v.initMatrix() if err != nil { - v.SLogger.Warn("error while init matrix", slog.Any("err", err)) + v.SLogger.Warn("error while init matrix", slogx.Err(err)) return nil, nil, err } for k := range v.data { @@ -136,9 +137,9 @@ func (v *VolumeAnalytics) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matr for instanceID, dataInstance := range data.GetInstances() { if records, analytics, err := v.getAnalyticsData(instanceID); err != nil { if errs.IsRestErr(err, errs.APINotFound) { - v.SLogger.Debug("API not found", slog.Any("err", err)) + v.SLogger.Debug("API not found", slogx.Err(err)) } else { - v.SLogger.Error("Failed to collect analytic data", slog.Any("err", err)) + v.SLogger.Error("Failed to collect analytic data", slogx.Err(err)) } } else { explorerMatrix := v.data[explorer] @@ -168,22 +169,22 @@ func (v *VolumeAnalytics) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matr } if bytesUsed != "" { if err = explorerMatrix.GetMetric("dir_bytes_used").SetValueString(instance, bytesUsed); err != nil { - v.SLogger.Error("set metric", slog.Any("err", err), slog.String("value", bytesUsed)) + v.SLogger.Error("set metric", slogx.Err(err), slog.String("value", bytesUsed)) } } if fileCount != "" { if err = explorerMatrix.GetMetric("dir_file_count").SetValueString(instance, fileCount); err != nil { - v.SLogger.Error("set metric", slog.Any("err", err), slog.String("value", fileCount)) + v.SLogger.Error("set metric", slogx.Err(err), slog.String("value", fileCount)) } } if subDirCount != "" { if name == "." { if err = explorerMatrix.GetMetric("dir_subdir_count").SetValueString(instance, util.AddIntString(subDirCount, 1)); err != nil { - v.SLogger.Error("set metric", slog.Any("err", err), slog.String("value", subDirCount)) + v.SLogger.Error("set metric", slogx.Err(err), slog.String("value", subDirCount)) } } else { if err = explorerMatrix.GetMetric("dir_subdir_count").SetValueString(instance, subDirCount); err != nil { - v.SLogger.Error("set metric", slog.Any("err", err), slog.String("value", subDirCount)) + v.SLogger.Error("set metric", slogx.Err(err), slog.String("value", subDirCount)) } } } @@ -204,7 +205,7 @@ func (v *VolumeAnalytics) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matr m.SetLabel("order", strconv.Itoa(i)) m.SetLabel("activity", v.getLabelBucket(atBytesUsedLabels[i])) if err = m.SetValueString(instance, mv); err != nil { - v.SLogger.Error("set metric", slog.Any("err", err), slog.String("value", mv)) + v.SLogger.Error("set metric", slogx.Err(err), slog.String("value", mv)) } } @@ -223,7 +224,7 @@ func (v *VolumeAnalytics) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matr m.SetLabel("order", strconv.Itoa(i)) m.SetLabel("activity", v.getLabelBucket(atBytesUsedLabels[i])) if err = m.SetValueString(instance, mp); err != nil { - v.SLogger.Error("set metric", slog.Any("err", err), slog.String("value", mp)) + v.SLogger.Error("set metric", slogx.Err(err), slog.String("value", mp)) } } @@ -246,7 +247,7 @@ func (v *VolumeAnalytics) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matr m.SetLabel("order", strconv.Itoa(i)) m.SetLabel("activity", v.getLabelBucket(atBytesUsedLabels[i])) if err = m.SetValueString(instance, av); err != nil { - v.SLogger.Error("set metric", slog.Any("err", err), slog.String("value", av)) + v.SLogger.Error("set metric", slogx.Err(err), slog.String("value", av)) } } @@ -265,7 +266,7 @@ func (v *VolumeAnalytics) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matr m.SetLabel("order", strconv.Itoa(i)) m.SetLabel("activity", v.getLabelBucket(atBytesUsedLabels[i])) if err = m.SetValueString(instance, ap); err != nil { - v.SLogger.Error("set metric", slog.Any("err", err), slog.String("value", ap)) + v.SLogger.Error("set metric", slogx.Err(err), slog.String("value", ap)) } } diff --git a/cmd/collectors/rest/plugins/workload/workload.go b/cmd/collectors/rest/plugins/workload/workload.go index 4149d294d..67c70365e 100644 --- a/cmd/collectors/rest/plugins/workload/workload.go +++ b/cmd/collectors/rest/plugins/workload/workload.go @@ -4,6 +4,7 @@ import ( "github.com/netapp/harvest/v2/cmd/collectors" "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" ) @@ -32,7 +33,7 @@ func (w *Workload) createMetrics(data *matrix.Matrix) error { for _, k := range metrics { err := matrix.CreateMetric(k, data) if err != nil { - w.SLogger.Warn("error while creating metric", slog.Any("err", err), slog.String("key", k)) + w.SLogger.Warn("error while creating metric", slogx.Err(err), slog.String("key", k)) return err } } diff --git a/cmd/collectors/rest/rest.go b/cmd/collectors/rest/rest.go index ab5564d7c..239d10f62 100644 --- a/cmd/collectors/rest/rest.go +++ b/cmd/collectors/rest/rest.go @@ -30,6 +30,7 @@ import ( "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" "github.com/netapp/harvest/v2/pkg/set" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" @@ -228,7 +229,7 @@ func (r *Rest) getClient(a *collector.AbstractCollector, c *auth.Credentials) (* opt := a.GetOptions() if poller, err = conf.PollerNamed(opt.Poller); err != nil { - r.Logger.Error("", slog.Any("err", err), slog.String("poller", opt.Poller)) + r.Logger.Error("", slogx.Err(err), slog.String("poller", opt.Poller)) return nil, err } if poller.Addr == "" { @@ -240,7 +241,7 @@ func (r *Rest) getClient(a *collector.AbstractCollector, c *auth.Credentials) (* return &rest.Client{Metadata: &util.Metadata{}}, nil } if client, err = rest.New(poller, timeout, c); err != nil { - r.Logger.Error("error creating new client", slog.Any("err", err), slog.String("poller", opt.Poller)) + r.Logger.Error("error creating new client", slogx.Err(err), slog.String("poller", opt.Poller)) os.Exit(1) } @@ -463,7 +464,7 @@ func (r *Rest) ProcessEndPoints(mat *matrix.Matrix, endpointFunc func(e *EndPoin totalAPID += apiD if err != nil { - r.Logger.Error("", slog.Any("err", err), slog.String("api", endpoint.prop.Query)) + r.Logger.Error("", slogx.Err(err), slog.String("api", endpoint.prop.Query)) continue } @@ -575,7 +576,7 @@ func (r *Rest) HandleResults(mat *matrix.Matrix, result []gjson.Result, prop *pr if instance == nil { if instance, err = mat.NewInstance(instanceKey); err != nil { - r.Logger.Error("Failed to create new instance", slog.Any("err", err), slog.String("instKey", instanceKey)) + r.Logger.Error("Failed to create new instance", slogx.Err(err), slog.String("instKey", instanceKey)) continue } } @@ -626,7 +627,7 @@ func (r *Rest) HandleResults(mat *matrix.Matrix, result []gjson.Result, prop *pr if metr, err = mat.NewMetricFloat64(metric.Name, metric.Label); err != nil { r.Logger.Error( "NewMetricFloat64", - slog.Any("err", err), + slogx.Err(err), slog.String("name", metric.Name), ) } @@ -648,7 +649,7 @@ func (r *Rest) HandleResults(mat *matrix.Matrix, result []gjson.Result, prop *pr if err = metr.SetValueFloat64(instance, floatValue); err != nil { r.Logger.Error( "Unable to set float key on metric", - slog.Any("err", err), + slogx.Err(err), slog.String("key", metric.Name), slog.String("metric", metric.Label), ) @@ -759,7 +760,7 @@ func (r *Rest) CollectAutoSupport(p *collector.Payload) { nodeIDs, err = r.getNodeUuids() if err != nil { // log but don't return so the other info below is collected - r.Logger.Error("Unable to get nodes", slog.Any("err", err)) + r.Logger.Error("Unable to get nodes", slogx.Err(err)) } info.Ids = nodeIDs p.Nodes = &info diff --git a/cmd/collectors/restperf/plugins/disk/disk.go b/cmd/collectors/restperf/plugins/disk/disk.go index 429ffa2d9..c0d291407 100644 --- a/cmd/collectors/restperf/plugins/disk/disk.go +++ b/cmd/collectors/restperf/plugins/disk/disk.go @@ -8,6 +8,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" @@ -116,7 +117,7 @@ func (d *Disk) Init() error { timeout, _ := time.ParseDuration(rest.DefaultTimeout) if d.client, err = rest.New(conf.ZapiPoller(d.ParentParams), timeout, d.Auth); err != nil { - d.SLogger.Error("connecting", slog.Any("err", err)) + d.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -175,7 +176,7 @@ func (d *Disk) Init() error { case "float": _, err := d.shelfData[attribute].NewMetricFloat64(metricName, display) if err != nil { - d.SLogger.Error("add metric", slog.Any("err", err)) + d.SLogger.Error("add metric", slogx.Err(err)) return err } } @@ -214,7 +215,7 @@ func (d *Disk) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.M records, err := rest.FetchAll(d.client, href) if err != nil { - d.SLogger.Error("Failed to fetch shelfData", slog.Any("err", err), slog.String("href", href)) + d.SLogger.Error("Failed to fetch shelfData", slogx.Err(err), slog.String("href", href)) return nil, nil, err } @@ -321,7 +322,7 @@ func (d *Disk) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.M if err = m.SetValueString(shelfChildInstance, value.String()); err != nil { // float d.SLogger.Error( "Unable to set float key on metric", - slog.Any("err", err), + slogx.Err(err), slog.String("key", metricKey), slog.String("metric", m.GetName()), slog.String("value", value.String()), @@ -466,7 +467,7 @@ func (d *Disk) calculateAggrPower(data *matrix.Matrix, output []*matrix.Matrix) for instanceKey, v := range d.aggrMap { instance, err := aggrData.NewInstance(instanceKey) if err != nil { - d.SLogger.Error("Failed to add instance", slog.Any("err", err), slog.String("key", instanceKey)) + d.SLogger.Error("Failed to add instance", slogx.Err(err), slog.String("key", instanceKey)) continue } instance.SetLabel("aggr", instanceKey) @@ -476,7 +477,7 @@ func (d *Disk) calculateAggrPower(data *matrix.Matrix, output []*matrix.Matrix) m := aggrData.GetMetric("power") err = m.SetValueFloat64(instance, v.power) if err != nil { - d.SLogger.Error("Failed to set value", slog.Any("err", err), slog.String("key", instanceKey)) + d.SLogger.Error("Failed to set value", slogx.Err(err), slog.String("key", instanceKey)) continue } } @@ -539,7 +540,7 @@ func (d *Disk) getDisks() error { records, err := rest.FetchAll(d.client, href) if err != nil { - d.SLogger.Error("Failed to fetch data", slog.Any("err", err), slog.String("href", href)) + d.SLogger.Error("Failed to fetch data", slogx.Err(err), slog.String("href", href)) return err } @@ -598,7 +599,7 @@ func (d *Disk) getAggregates() error { records, err := rest.FetchAll(d.client, href) if err != nil { - d.SLogger.Error("Failed to fetch data", slog.Any("err", err), slog.String("href", href)) + d.SLogger.Error("Failed to fetch data", slogx.Err(err), slog.String("href", href)) return err } @@ -680,7 +681,7 @@ func (d *Disk) handleShelfPower(shelves []gjson.Result, output []*matrix.Matrix) instanceKey := shelfSerialNumber instance, err := data.NewInstance(instanceKey) if err != nil { - d.SLogger.Error("Failed to add instance", slog.Any("err", err), slog.String("key", instanceKey)) + d.SLogger.Error("Failed to add instance", slogx.Err(err), slog.String("key", instanceKey)) return output, err } instance.SetLabel("shelf", shelfName) @@ -700,7 +701,7 @@ func (d *Disk) initShelfPowerMatrix() { for _, k := range shelfMetrics { err := matrix.CreateMetric(k, d.powerData["shelf"]) if err != nil { - d.SLogger.Warn("error while creating metric", slog.Any("err", err), slog.String("key", k)) + d.SLogger.Warn("error while creating metric", slogx.Err(err), slog.String("key", k)) } } } @@ -711,7 +712,7 @@ func (d *Disk) initAggrPowerMatrix() { for _, k := range aggrMetrics { err := matrix.CreateMetric(k, d.powerData["aggr"]) if err != nil { - d.SLogger.Warn("error while creating metric", slog.Any("err", err), slog.String("key", k)) + d.SLogger.Warn("error while creating metric", slogx.Err(err), slog.String("key", k)) } } } @@ -788,7 +789,7 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) { for _, k := range shelfMetrics { err := matrix.CreateMetric(k, data) if err != nil { - d.SLogger.Warn("error while creating metric", slog.Any("err", err), slog.String("key", k)) + d.SLogger.Warn("error while creating metric", slogx.Err(err), slog.String("key", k)) } } for key, v := range shelfEnvironmentMetricMap { @@ -813,7 +814,7 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) { err = m.SetValueFloat64(instance, sumPower) if err != nil { - d.SLogger.Error("Unable to set power", slog.Any("err", err), slog.Float64("power", sumPower)) + d.SLogger.Error("Unable to set power", slogx.Err(err), slog.Float64("power", sumPower)) } else { d.ShelfMap[instance.GetLabel("shelfUID")] = &shelf{power: sumPower} } @@ -825,7 +826,7 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) { if err != nil { d.SLogger.Error( "Unable to set average_ambient_temperature", - slog.Any("err", err), + slogx.Err(err), slog.Float64("average_ambient_temperature", aaT), ) } @@ -836,7 +837,7 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) { if err != nil { d.SLogger.Error( "Unable to set min_ambient_temperature", - slog.Any("err", err), + slogx.Err(err), slog.Float64("min_ambient_temperature", maT), ) } @@ -846,7 +847,7 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) { if err != nil { d.SLogger.Error( "Unable to set max_temperature", - slog.Any("err", err), + slogx.Err(err), slog.Float64("max_temperature", mT), ) } @@ -857,7 +858,7 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) { if err != nil { d.SLogger.Error( "Unable to set average_temperature", - slog.Any("err", err), + slogx.Err(err), slog.Float64("average_temperature", nat), ) } @@ -868,7 +869,7 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) { if err != nil { d.SLogger.Error( "Unable to set min_temperature", - slog.Any("err", err), + slogx.Err(err), slog.Float64("min_temperature", mT), ) } @@ -879,7 +880,7 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) { if err != nil { d.SLogger.Error( "Unable to set average_fan_speed", - slog.Any("err", err), + slogx.Err(err), slog.Float64("average_fan_speed", afs), ) } @@ -890,7 +891,7 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) { if err != nil { d.SLogger.Error( "Unable to set max_fan_speed", - slog.Any("err", err), + slogx.Err(err), slog.Float64("max_fan_speed", mfs), ) } @@ -900,7 +901,7 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) { if err != nil { d.SLogger.Error( "Unable to set min_fan_speed", - slog.Any("err", err), + slogx.Err(err), slog.Float64("min_fan_speed", mfs), ) } diff --git a/cmd/collectors/restperf/plugins/fcp/fcp.go b/cmd/collectors/restperf/plugins/fcp/fcp.go index 26a765a42..5eb8bed6a 100644 --- a/cmd/collectors/restperf/plugins/fcp/fcp.go +++ b/cmd/collectors/restperf/plugins/fcp/fcp.go @@ -4,6 +4,7 @@ import ( "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" "math" @@ -78,7 +79,7 @@ func (f *Fcp) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Me rxPercent = rxBytes / float64(speed) err := rx.SetValueFloat64(instance, rxPercent) if err != nil { - f.SLogger.Error("error", slog.Any("err", err)) + f.SLogger.Error("error", slogx.Err(err)) } } @@ -86,14 +87,14 @@ func (f *Fcp) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Me txPercent = txBytes / float64(speed) err := tx.SetValueFloat64(instance, txPercent) if err != nil { - f.SLogger.Error("error", slog.Any("err", err)) + f.SLogger.Error("error", slogx.Err(err)) } } if rxOk || txOk { err := utilPercent.SetValueFloat64(instance, math.Max(rxPercent, txPercent)) if err != nil { - f.SLogger.Error("error", slog.Any("err", err)) + f.SLogger.Error("error", slogx.Err(err)) } } } diff --git a/cmd/collectors/restperf/plugins/fcvi/fcvi.go b/cmd/collectors/restperf/plugins/fcvi/fcvi.go index 8f75b6e73..8ab00f90e 100644 --- a/cmd/collectors/restperf/plugins/fcvi/fcvi.go +++ b/cmd/collectors/restperf/plugins/fcvi/fcvi.go @@ -6,6 +6,7 @@ import ( "github.com/netapp/harvest/v2/cmd/tools/rest" "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" "time" @@ -28,7 +29,7 @@ func (f *FCVI) Init() error { timeout, _ := time.ParseDuration(rest.DefaultTimeout) if f.client, err = rest.New(conf.ZapiPoller(f.ParentParams), timeout, f.Auth); err != nil { - f.SLogger.Error("connecting", slog.Any("err", err)) + f.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -48,7 +49,7 @@ func (f *FCVI) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.M Build() records, err := rest.FetchAll(f.client, href) if err != nil { - f.SLogger.Error("Failed to fetch data", slog.Any("err", err), slog.String("href", href)) + f.SLogger.Error("Failed to fetch data", slogx.Err(err), slog.String("href", href)) return nil, nil, err } diff --git a/cmd/collectors/restperf/plugins/nic/nic.go b/cmd/collectors/restperf/plugins/nic/nic.go index fbaca404c..107268c63 100644 --- a/cmd/collectors/restperf/plugins/nic/nic.go +++ b/cmd/collectors/restperf/plugins/nic/nic.go @@ -19,6 +19,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" @@ -64,7 +65,7 @@ func (n *Nic) Init() error { metricName, display, _, _ := util.ParseMetric(obj) _, err := n.data.NewMetricFloat64(metricName, display) if err != nil { - n.SLogger.Error("add metric", slog.Any("err", err)) + n.SLogger.Error("add metric", slogx.Err(err)) return err } } @@ -75,7 +76,7 @@ func (n *Nic) Init() error { timeout, _ := time.ParseDuration(rest.DefaultTimeout) if n.client, err = rest.New(conf.ZapiPoller(n.ParentParams), timeout, n.Auth); err != nil { - n.SLogger.Error("connecting", slog.Any("err", err)) + n.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -174,7 +175,7 @@ func (n *Nic) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Me rxPercent = rxBytes / float64(speed) err := rx.SetValueFloat64(instance, rxPercent) if err != nil { - n.SLogger.Error("error", slog.Any("err", err)) + n.SLogger.Error("error", slogx.Err(err)) } } @@ -182,7 +183,7 @@ func (n *Nic) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Me txPercent = txBytes / float64(speed) err := tx.SetValueFloat64(instance, txPercent) if err != nil { - n.SLogger.Error("error", slog.Any("err", err)) + n.SLogger.Error("error", slogx.Err(err)) } } @@ -191,7 +192,7 @@ func (n *Nic) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Me if rxOk || txOk { err := utilPercent.SetValueFloat64(instance, math.Max(rxPercent, txPercent)) if err != nil { - n.SLogger.Error("error", slog.Any("err", err)) + n.SLogger.Error("error", slogx.Err(err)) } } } diff --git a/cmd/collectors/restperf/plugins/volumetag/volumetag.go b/cmd/collectors/restperf/plugins/volumetag/volumetag.go index beb9875d8..501136514 100644 --- a/cmd/collectors/restperf/plugins/volumetag/volumetag.go +++ b/cmd/collectors/restperf/plugins/volumetag/volumetag.go @@ -6,6 +6,7 @@ import ( "github.com/netapp/harvest/v2/cmd/tools/rest" "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" "time" @@ -28,7 +29,7 @@ func (v *VolumeTag) Init() error { timeout, _ := time.ParseDuration(rest.DefaultTimeout) if v.client, err = rest.New(conf.ZapiPoller(v.ParentParams), timeout, v.Auth); err != nil { - v.SLogger.Error("connecting", slog.Any("err", err)) + v.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -54,7 +55,7 @@ func (v *VolumeTag) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *u records, err := rest.FetchAll(v.client, href) if err != nil { - v.SLogger.Error("Failed to fetch data", slog.Any("err", err), slog.String("href", href)) + v.SLogger.Error("Failed to fetch data", slogx.Err(err), slog.String("href", href)) return nil, nil, err } diff --git a/cmd/collectors/restperf/plugins/volumetopclients/volumetopclients.go b/cmd/collectors/restperf/plugins/volumetopclients/volumetopclients.go index 6bafaddc1..1e9f176d3 100644 --- a/cmd/collectors/restperf/plugins/volumetopclients/volumetopclients.go +++ b/cmd/collectors/restperf/plugins/volumetopclients/volumetopclients.go @@ -8,6 +8,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/matrix" "github.com/netapp/harvest/v2/pkg/set" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" "log/slog" @@ -90,7 +91,7 @@ func (t *TopClients) initMatrix(name string, object string, inputMat map[string] } err := matrix.CreateMetric(metric, inputMat[name]) if err != nil { - t.SLogger.Warn("error while creating metric", slog.Any("err", err), slog.String("key", metric)) + t.SLogger.Warn("error while creating metric", slogx.Err(err), slog.String("key", metric)) return err } return nil @@ -324,7 +325,7 @@ func (t *TopClients) processTopClientsByMetric(volumes, svms *set.Set, matrixNam instanceKey := clientIP + keyToken + vol + keyToken + svm instance, err := mat.NewInstance(instanceKey) if err != nil { - t.SLogger.Warn("error while creating instance", slog.Any("err", err), slog.String("volume", vol)) + t.SLogger.Warn("error while creating instance", slogx.Err(err), slog.String("volume", vol)) continue } instance.SetLabel("volume", vol) @@ -340,12 +341,12 @@ func (t *TopClients) setMetric(mat *matrix.Matrix, instance *matrix.Instance, va m := mat.GetMetric(metricType) if m == nil { if m, err = mat.NewMetricFloat64(metricType); err != nil { - t.SLogger.Warn("error while creating metric", slog.Any("err", err), slog.String("key", metricType)) + t.SLogger.Warn("error while creating metric", slogx.Err(err), slog.String("key", metricType)) return } } if err = m.SetValueFloat64(instance, value); err != nil { - t.SLogger.Error("error while setting value", slog.Any("err", err), slog.String("metric", metricType)) + t.SLogger.Error("error while setting value", slogx.Err(err), slog.String("metric", metricType)) } } diff --git a/cmd/collectors/restperf/plugins/vscan/vscan.go b/cmd/collectors/restperf/plugins/vscan/vscan.go index 9172433cf..b0dc9b1c8 100644 --- a/cmd/collectors/restperf/plugins/vscan/vscan.go +++ b/cmd/collectors/restperf/plugins/vscan/vscan.go @@ -4,6 +4,7 @@ import ( "github.com/netapp/harvest/v2/cmd/collectors" "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" "strconv" @@ -26,7 +27,7 @@ func (v *Vscan) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util. if parseBool, err := strconv.ParseBool(s); err == nil { isPerScanner = parseBool } else { - v.SLogger.Error("Failed to parse metricsPerScanner", slog.Any("err", err)) + v.SLogger.Error("Failed to parse metricsPerScanner", slogx.Err(err)) } } v.SLogger.Debug("Vscan options", slog.Bool("isPerScanner", isPerScanner)) diff --git a/cmd/collectors/restperf/restperf.go b/cmd/collectors/restperf/restperf.go index 8586405fc..99b280f45 100644 --- a/cmd/collectors/restperf/restperf.go +++ b/cmd/collectors/restperf/restperf.go @@ -20,6 +20,7 @@ import ( "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" "github.com/netapp/harvest/v2/pkg/set" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" @@ -391,7 +392,7 @@ func (r *RestPerf) pollCounter(records []gjson.Result, apiD time.Duration) (map[ if mat.GetMetric(timestampMetricName) == nil { m, err := mat.NewMetricFloat64(timestampMetricName) if err != nil { - r.Logger.Error("add timestamp metric", slog.Any("err", err)) + r.Logger.Error("add timestamp metric", slogx.Err(err)) } m.SetProperty("raw") m.SetExportable(false) @@ -613,7 +614,7 @@ func (r *RestPerf) processWorkLoadCounter() (map[string]*matrix.Matrix, error) { metr, ok := mat.GetMetrics()[name] if !ok { if metr, err = mat.NewMetricFloat64(name, metric.Label); err != nil { - r.Logger.Error("NewMetricFloat64", slog.Any("err", err), slog.String("name", name)) + r.Logger.Error("NewMetricFloat64", slogx.Err(err), slog.String("name", name)) } } metr.SetExportable(metric.Exportable) @@ -927,7 +928,7 @@ func (r *RestPerf) pollData(startTime time.Time, perfRecords []rest.PerfRecord) if err := wMetric.AddValueString(instance, f.value); err != nil { r.Logger.Error( "Add resource_latency failed", - slog.Any("err", err), + slogx.Err(err), slog.String("name", name), slog.String("value", f.value), ) @@ -939,7 +940,7 @@ func (r *RestPerf) pollData(startTime time.Time, perfRecords []rest.PerfRecord) if err = wMetric.SetValueString(instance, f.value); err != nil { r.Logger.Error( "Add service_time_latency failed", - slog.Any("err", err), + slogx.Err(err), slog.String("name", name), slog.String("value", f.value), ) @@ -950,7 +951,7 @@ func (r *RestPerf) pollData(startTime time.Time, perfRecords []rest.PerfRecord) if err = wMetric.SetValueString(instance, f.value); err != nil { r.Logger.Error( "Add wait_time_latency failed", - slog.Any("err", err), + slogx.Err(err), slog.String("name", name), slog.String("value", f.value), ) @@ -985,7 +986,7 @@ func (r *RestPerf) pollData(startTime time.Time, perfRecords []rest.PerfRecord) if err != nil { r.Logger.Error( "unable to create histogram metric", - slog.Any("err", err), + slogx.Err(err), slog.String("key", key), ) continue @@ -1003,7 +1004,7 @@ func (r *RestPerf) pollData(startTime time.Time, perfRecords []rest.PerfRecord) if metr, err = r.getMetric(curMat, prevMat, k, metric.Label); err != nil { r.Logger.Error( "NewMetricFloat64", - slog.Any("err", err), + slogx.Err(err), slog.String("name", k), ) continue @@ -1028,7 +1029,7 @@ func (r *RestPerf) pollData(startTime time.Time, perfRecords []rest.PerfRecord) if err = metr.SetValueString(instance, values[i]); err != nil { r.Logger.Error( "Set value failed", - slog.Any("err", err), + slogx.Err(err), slog.String("name", name), slog.String("label", label), slog.String("value", values[i]), @@ -1044,7 +1045,7 @@ func (r *RestPerf) pollData(startTime time.Time, perfRecords []rest.PerfRecord) if metr, err = r.getMetric(curMat, prevMat, name, metric.Label); err != nil { r.Logger.Error( "NewMetricFloat64", - slog.Any("err", err), + slogx.Err(err), slog.String("name", name), slog.Int("instIndex", instIndex), ) @@ -1055,7 +1056,7 @@ func (r *RestPerf) pollData(startTime time.Time, perfRecords []rest.PerfRecord) if err = metr.SetValueFloat64(instance, c); err != nil { r.Logger.Error( "Unable to set float key on metric", - slog.Any("err", err), + slogx.Err(err), slog.String("key", metric.Name), slog.String("metric", metric.Label), slog.Int("instIndex", instIndex), @@ -1064,7 +1065,7 @@ func (r *RestPerf) pollData(startTime time.Time, perfRecords []rest.PerfRecord) } else { r.Logger.Error( "Unable to parse float value", - slog.Any("err", err), + slogx.Err(err), slog.String("key", metric.Name), slog.String("metric", metric.Label), slog.Int("instIndex", instIndex), @@ -1077,7 +1078,7 @@ func (r *RestPerf) pollData(startTime time.Time, perfRecords []rest.PerfRecord) } } if err = curMat.GetMetric(timestampMetricName).SetValueFloat64(instance, ts); err != nil { - r.Logger.Error("Failed to set timestamp", slog.Any("err", err)) + r.Logger.Error("Failed to set timestamp", slogx.Err(err)) } return true @@ -1149,7 +1150,7 @@ func (r *RestPerf) pollData(startTime time.Time, perfRecords []rest.PerfRecord) // Calculate timestamp delta first since many counters require it for postprocessing. // Timestamp has "raw" property, so it isn't post-processed automatically if _, err = curMat.Delta("timestamp", prevMat, r.Logger); err != nil { - r.Logger.Error("(timestamp) calculate delta:", slog.Any("err", err)) + r.Logger.Error("(timestamp) calculate delta:", slogx.Err(err)) } var base *matrix.Metric @@ -1161,7 +1162,7 @@ func (r *RestPerf) pollData(startTime time.Time, perfRecords []rest.PerfRecord) if counter == nil { r.Logger.Error( "Missing counter:", - slog.Any("err", err), + slogx.Err(err), slog.String("counter", metric.GetName()), ) continue @@ -1179,7 +1180,7 @@ func (r *RestPerf) pollData(startTime time.Time, perfRecords []rest.PerfRecord) // all other properties - first calculate delta if skips, err = curMat.Delta(key, prevMat, r.Logger); err != nil { - r.Logger.Error("Calculate delta:", slog.Any("err", err), slog.String("key", key)) + r.Logger.Error("Calculate delta:", slogx.Err(err), slog.String("key", key)) continue } totalSkips += skips @@ -1233,7 +1234,7 @@ func (r *RestPerf) pollData(startTime time.Time, perfRecords []rest.PerfRecord) } if err != nil { - r.Logger.Error("Division by base", slog.Any("err", err), slog.String("key", key)) + r.Logger.Error("Division by base", slogx.Err(err), slog.String("key", key)) continue } totalSkips += skips @@ -1245,7 +1246,7 @@ func (r *RestPerf) pollData(startTime time.Time, perfRecords []rest.PerfRecord) if property == "percent" { if skips, err = curMat.MultiplyByScalar(key, 100); err != nil { - r.Logger.Error("Multiply by scalar", slog.Any("err", err), slog.String("key", key)) + r.Logger.Error("Multiply by scalar", slogx.Err(err), slog.String("key", key)) } else { totalSkips += skips } @@ -1270,7 +1271,7 @@ func (r *RestPerf) pollData(startTime time.Time, perfRecords []rest.PerfRecord) if skips, err = curMat.Divide(orderedKeys[i], timestampMetricName); err != nil { r.Logger.Error( "Calculate rate", - slog.Any("err", err), + slogx.Err(err), slog.Int("i", i), slog.String("metric", metric.GetName()), slog.String("key", key), @@ -1342,7 +1343,7 @@ func (r *RestPerf) getParentOpsCounters(data *matrix.Matrix) error { records, err = rest.FetchAll(r.Client, href) if err != nil { - r.Logger.Error("Failed to fetch data", slog.Any("err", err), slog.String("href", href)) + r.Logger.Error("Failed to fetch data", slogx.Err(err), slog.String("href", href)) return err } @@ -1379,7 +1380,7 @@ func (r *RestPerf) getParentOpsCounters(data *matrix.Matrix) error { if err = ops.SetValueString(instance, f.value); err != nil { r.Logger.Error( "set metric", - slog.Any("err", err), + slogx.Err(err), slog.String("metric", counterName), slog.String("value", value.String()), ) @@ -1544,7 +1545,7 @@ func (r *RestPerf) pollInstance(records []gjson.Result, apiD time.Duration) (map instance := mat.GetInstance(instanceKey) r.updateQosLabels(instanceData, instance, instanceKey) } else if instance, err := mat.NewInstance(instanceKey); err != nil { - r.Logger.Error("add instance", slog.Any("err", err), slog.String("instanceKey", instanceKey)) + r.Logger.Error("add instance", slogx.Err(err), slog.String("instanceKey", instanceKey)) } else { r.updateQosLabels(instanceData, instance, instanceKey) } diff --git a/cmd/collectors/simple/simple.go b/cmd/collectors/simple/simple.go index 2cb570ca6..abbcfa35a 100644 --- a/cmd/collectors/simple/simple.go +++ b/cmd/collectors/simple/simple.go @@ -8,6 +8,7 @@ import ( "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "log/slog" "os" @@ -43,7 +44,7 @@ func (n *NodeMon) Init(a *collector.AbstractCollector) error { // load list of counters from template if counters := n.Params.GetChildS("counters"); counters != nil { if err = n.loadMetrics(counters); err != nil { - n.Logger.Error("load metrics", slog.Any("err", err)) + n.Logger.Error("load metrics", slogx.Err(err)) return err } } else { @@ -119,7 +120,7 @@ func (n *NodeMon) PollData() (map[string]*matrix.Matrix, error) { if err != nil { n.Logger.Error( "initializing metric cache", - slog.Any("err", err), + slogx.Err(err), slog.String("key", key), ) } diff --git a/cmd/collectors/storagegrid/plugins/bucket/bucket.go b/cmd/collectors/storagegrid/plugins/bucket/bucket.go index 9f7f3a26a..b4d34980e 100644 --- a/cmd/collectors/storagegrid/plugins/bucket/bucket.go +++ b/cmd/collectors/storagegrid/plugins/bucket/bucket.go @@ -4,6 +4,7 @@ import ( "github.com/netapp/harvest/v2/cmd/collectors/storagegrid/rest" "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" "log/slog" @@ -29,7 +30,7 @@ func (b *Bucket) Init() error { clientTimeout := b.ParentParams.GetChildContentS("client_timeout") if b.client, err = rest.NewClient(b.Options.Poller, clientTimeout, b.Auth); err != nil { - b.SLogger.Error("connecting", slog.Any("err", err)) + b.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -70,7 +71,7 @@ func (b *Bucket) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util tenantName := inst.GetLabel("tenant") if err != nil { b.SLogger.Error("Unable to fetch bucket details", - slog.Any("err", err), + slogx.Err(err), slog.String("id", instKey), slog.String("tenantName", tenantName), ) @@ -107,7 +108,7 @@ func (b *Bucket) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util if err = m.SetValueString(bucketInstance, value.String()); err != nil { b.SLogger.Error( "Unable to set float key on metric", - slog.Any("err", err), + slogx.Err(err), slog.String("key", metricKey), slog.String("metric", m.GetName()), slog.String("value", value.String()), diff --git a/cmd/collectors/storagegrid/plugins/joinrest/joinrest.go b/cmd/collectors/storagegrid/plugins/joinrest/joinrest.go index fdbabef2b..81f5ebb14 100644 --- a/cmd/collectors/storagegrid/plugins/joinrest/joinrest.go +++ b/cmd/collectors/storagegrid/plugins/joinrest/joinrest.go @@ -4,6 +4,7 @@ import ( "github.com/netapp/harvest/v2/cmd/collectors/storagegrid/rest" "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" "gopkg.in/yaml.v3" @@ -57,7 +58,7 @@ func (t *JoinRest) Init() error { var tm translatePlugin err = decoder.Decode(&tm) if err != nil { - t.SLogger.Error("Failed to decode joinTemplate", slog.Any("err", err)) + t.SLogger.Error("Failed to decode joinTemplate", slogx.Err(err)) return err } for _, p := range tm.Plugins { @@ -89,7 +90,7 @@ func (t *JoinRest) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *ut if err != nil { t.SLogger.Error( "Failed to collect records from REST", - slog.Any("err", err), + slogx.Err(err), slog.String("rest", model.Rest), ) continue diff --git a/cmd/collectors/storagegrid/storagegrid.go b/cmd/collectors/storagegrid/storagegrid.go index 634856d91..cdff8d2cb 100644 --- a/cmd/collectors/storagegrid/storagegrid.go +++ b/cmd/collectors/storagegrid/storagegrid.go @@ -10,6 +10,7 @@ import ( "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" @@ -158,7 +159,7 @@ func (s *StorageGrid) pollPrometheusMetrics() (map[string]*matrix.Matrix, error) for _, metric := range s.Props.Metrics { mat, err := s.GetMetric(metric.Name, metric.Label, nil) if err != nil { - s.Logger.Error("failed to get metric", slog.Any("err", err), slog.String("metric", metric.Name)) + s.Logger.Error("failed to get metric", slogx.Err(err), slog.String("metric", metric.Name)) continue } metrics[metric.Name] = mat @@ -217,7 +218,7 @@ func (s *StorageGrid) makePromMetrics(metricName string, result *[]gjson.Result, if instance, err = mat.NewInstance(metricName + "-" + strconv.Itoa(i)); err != nil { s.Logger.Error( "", - slog.Any("err", err), + slogx.Err(err), slog.String("metricName", metricName), slog.Int("i", i), ) @@ -250,7 +251,7 @@ func (s *StorageGrid) makePromMetrics(metricName string, result *[]gjson.Result, if err != nil { s.Logger.Error( "Unable to set float key on metric", - slog.Any("err", err), + slogx.Err(err), slog.String("metric", metricName), ) continue @@ -355,7 +356,7 @@ func (s *StorageGrid) handleResults(result []gjson.Result) uint64 { if instance == nil { if instance, err = mat.NewInstance(instanceKey); err != nil { - s.Logger.Error("", slog.Any("err", err), slog.String("instanceKey", instanceKey)) + s.Logger.Error("", slogx.Err(err), slog.String("instanceKey", instanceKey)) continue } } @@ -385,7 +386,7 @@ func (s *StorageGrid) handleResults(result []gjson.Result) uint64 { if metr, err = mat.NewMetricFloat64(metric.Name, metric.Label); err != nil { s.Logger.Error( "NewMetricFloat64", - slog.Any("err", err), + slogx.Err(err), slog.String("name", metric.Name), ) } @@ -407,7 +408,7 @@ func (s *StorageGrid) handleResults(result []gjson.Result) uint64 { if err = metr.SetValueFloat64(instance, floatValue); err != nil { s.Logger.Error( "Unable to set float key on metric", - slog.Any("err", err), + slogx.Err(err), slog.String("key", metric.Name), slog.String("metric", metric.Label), ) @@ -584,7 +585,7 @@ func (s *StorageGrid) CollectAutoSupport(p *collector.Payload) { nodeIDs, err := s.getNodeUuids() if err != nil { // log the error, but don't exit method so later info is collected - s.Logger.Error("Unable to get nodes", slog.Any("err", err)) + s.Logger.Error("Unable to get nodes", slogx.Err(err)) nodeIDs = make([]collector.ID, 0) } p.Nodes = &collector.InstanceInfo{ diff --git a/cmd/collectors/storagegrid/tenant.go b/cmd/collectors/storagegrid/tenant.go index 193977741..ca10c1674 100644 --- a/cmd/collectors/storagegrid/tenant.go +++ b/cmd/collectors/storagegrid/tenant.go @@ -4,6 +4,7 @@ import ( "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" ) @@ -64,7 +65,7 @@ func (t *Tenant) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util } err := usedPercent.SetValueFloat64(instance, percentage) if err != nil { - t.SLogger.Error("failed to set percentage", slog.Any("err", err), slog.Float64("percentage", percentage)) + t.SLogger.Error("failed to set percentage", slogx.Err(err), slog.Float64("percentage", percentage)) } } @@ -88,7 +89,7 @@ func (t *Tenant) collectPromMetrics(tenantNamesByID map[string]string) []*matrix for _, metric := range promMetrics { mat, err := t.sg.GetMetric(metric, metric[lenOfPrefix:], tenantNamesByID) if err != nil { - t.SLogger.Error("Unable to get metric", slog.Any("err", err), slog.String("metric", metric)) + t.SLogger.Error("Unable to get metric", slogx.Err(err), slog.String("metric", metric)) continue } mat.Object = "storagegrid" diff --git a/cmd/collectors/unix/main.go b/cmd/collectors/unix/main.go index bc1f3316a..15f204df8 100644 --- a/cmd/collectors/unix/main.go +++ b/cmd/collectors/unix/main.go @@ -12,6 +12,7 @@ import ( "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" "github.com/netapp/harvest/v2/pkg/set" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "log/slog" @@ -161,7 +162,7 @@ func (u *Unix) Init(a *collector.AbstractCollector) error { // load list of counters from template if counters := u.Params.GetChildS("counters"); counters != nil { if err = u.loadMetrics(counters); err != nil { - u.Logger.Error("load metrics", slog.Any("err", err)) + u.Logger.Error("load metrics", slogx.Err(err)) return err } } else { @@ -170,7 +171,7 @@ func (u *Unix) Init(a *collector.AbstractCollector) error { getClockTicks() if u.system, err = NewSystem(); err != nil { - u.Logger.Error("load system", slog.Any("err", err)) + u.Logger.Error("load system", slogx.Err(err)) return err } @@ -414,21 +415,21 @@ func (u *Unix) PollData() (map[string]*matrix.Matrix, error) { func setStartTime(m *matrix.Metric, i *matrix.Instance, p *Process, s *System) { err := m.SetValueFloat64(i, p.startTime+s.bootTime) if err != nil { - slog.Default().Error("error", slog.Any("err", err)) + slog.Default().Error("error", slogx.Err(err)) } } func setNumThreads(m *matrix.Metric, i *matrix.Instance, p *Process, _ *System) { err := m.SetValueUint64(i, p.numThreads) if err != nil { - slog.Default().Error("error", slog.Any("err", err)) + slog.Default().Error("error", slogx.Err(err)) } } func setNumFds(m *matrix.Metric, i *matrix.Instance, p *Process, _ *System) { err := m.SetValueUint64(i, p.numFds) if err != nil { - slog.Default().Error("error", slog.Any("err", err)) + slog.Default().Error("error", slogx.Err(err)) } } @@ -436,12 +437,12 @@ func setCPUPercent(m *matrix.Metric, i *matrix.Instance, p *Process, _ *System) if p.elapsedTime != 0 { err := m.SetValueFloat64(i, p.cpuTotal/p.elapsedTime*100) if err != nil { - slog.Default().Error("error", slog.Any("err", err)) + slog.Default().Error("error", slogx.Err(err)) } } else { err := m.SetValueFloat64(i, p.cpuTotal/(float64(time.Now().Unix())-p.startTime)*100) if err != nil { - slog.Default().Error("error", slog.Any("err", err)) + slog.Default().Error("error", slogx.Err(err)) } } } @@ -450,7 +451,7 @@ func setCPU(m *matrix.Metric, l string, i *matrix.Instance, p *Process) { if value, ok := p.cpu[l]; ok { err := m.SetValueFloat64(i, value) if err != nil { - slog.Default().Error("error", slog.Any("err", err)) + slog.Default().Error("error", slogx.Err(err)) } } } @@ -459,7 +460,7 @@ func setMemory(m *matrix.Metric, l string, i *matrix.Instance, p *Process) { if value, ok := p.mem[l]; ok { err := m.SetValueUint64(i, value) if err != nil { - slog.Default().Error("error", slog.Any("err", err)) + slog.Default().Error("error", slogx.Err(err)) } } } @@ -468,7 +469,7 @@ func setIo(m *matrix.Metric, l string, i *matrix.Instance, p *Process) { if value, ok := p.io[l]; ok { err := m.SetValueUint64(i, value) if err != nil { - slog.Default().Error("error", slog.Any("err", err)) + slog.Default().Error("error", slogx.Err(err)) } } } @@ -477,7 +478,7 @@ func setNet(m *matrix.Metric, l string, i *matrix.Instance, p *Process) { if value, ok := p.net[l]; ok { err := m.SetValueUint64(i, value) if err != nil { - slog.Default().Error("error", slog.Any("err", err)) + slog.Default().Error("error", slogx.Err(err)) } } } @@ -486,7 +487,7 @@ func setCtx(m *matrix.Metric, l string, i *matrix.Instance, p *Process) { if value, ok := p.ctx[l]; ok { err := m.SetValueUint64(i, value) if err != nil { - slog.Default().Error("error", slog.Any("err", err)) + slog.Default().Error("error", slogx.Err(err)) } } } diff --git a/cmd/collectors/volume.go b/cmd/collectors/volume.go index 3831ab37a..3e894d268 100644 --- a/cmd/collectors/volume.go +++ b/cmd/collectors/volume.go @@ -3,6 +3,7 @@ package collectors import ( "github.com/netapp/harvest/v2/pkg/matrix" "github.com/netapp/harvest/v2/pkg/set" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" "maps" @@ -25,7 +26,7 @@ func ProcessFlexGroupData(logger *slog.Logger, data *matrix.Matrix, style string metric, err := volumeAggrmetric.NewMetricFloat64(metricName) if err != nil { - logger.Error("add metric", slog.Any("err", err), slog.String("key", metricName)) + logger.Error("add metric", slogx.Err(err), slog.String("key", metricName)) return nil, nil, err } @@ -54,7 +55,7 @@ func ProcessFlexGroupData(logger *slog.Logger, data *matrix.Matrix, style string flexgroupInstance.SetLabel(style, "flexgroup") flexgroupAggrsMap[key] = set.New() if err := metric.SetValueFloat64(flexgroupInstance, 1); err != nil { - logger.Error("set value", slog.Any("err", err), slog.String("metric", metricName)) + logger.Error("set value", slogx.Err(err), slog.String("metric", metricName)) } } fgAggrMap[key].Add(i.GetLabel("aggr")) @@ -66,13 +67,13 @@ func ProcessFlexGroupData(logger *slog.Logger, data *matrix.Matrix, style string key := i.GetLabel("svm") + "." + i.GetLabel("volume") flexvolInstance, err := volumeAggrmetric.NewInstance(key) if err != nil { - logger.Error("Failed to create new instance", slog.Any("err", err), slog.String("key", key)) + logger.Error("Failed to create new instance", slogx.Err(err), slog.String("key", key)) continue } flexvolInstance.SetLabels(maps.Clone(i.GetLabels())) flexvolInstance.SetLabel(style, "flexvol") if err := metric.SetValueFloat64(flexvolInstance, 1); err != nil { - logger.Error("Unable to set value on metric", slog.Any("err", err), slog.String("metric", metricName)) + logger.Error("Unable to set value on metric", slogx.Err(err), slog.String("metric", metricName)) } } } @@ -121,7 +122,7 @@ func ProcessFlexGroupData(logger *slog.Logger, data *matrix.Matrix, style string if !strings.HasSuffix(m.GetName(), "_latency") { err := fgm.SetValueFloat64(fg, fgv+value) if err != nil { - logger.Error("error setting value", slog.Any("err", err)) + logger.Error("error setting value", slogx.Err(err)) } continue } @@ -150,12 +151,12 @@ func ProcessFlexGroupData(logger *slog.Logger, data *matrix.Matrix, style string if value != 0 { err = tempOps.SetValueFloat64(fg, tempOpsV+opsValue) if err != nil { - logger.Error("error setting value", slog.Any("err", err)) + logger.Error("error setting value", slogx.Err(err)) } } err = fgm.SetValueFloat64(fg, fgv+prod) if err != nil { - logger.Error("error setting value", slog.Any("err", err)) + logger.Error("error setting value", slogx.Err(err)) } } else { s, ok := recordFGFalse[key] @@ -199,7 +200,7 @@ func ProcessFlexGroupData(logger *slog.Logger, data *matrix.Matrix, style string if opsValue, ok := ops.GetValueFloat64(i); ok && opsValue != 0 { err := m.SetValueFloat64(i, value/opsValue) if err != nil { - logger.Error("error setting value", slog.Any("err", err)) + logger.Error("error setting value", slogx.Err(err)) } } else { m.SetValueNAN(i) diff --git a/cmd/collectors/zapi/collector/parsers.go b/cmd/collectors/zapi/collector/parsers.go index af566ff49..9e76995d6 100644 --- a/cmd/collectors/zapi/collector/parsers.go +++ b/cmd/collectors/zapi/collector/parsers.go @@ -6,6 +6,7 @@ package zapi import ( "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "log/slog" @@ -116,7 +117,7 @@ func (z *Zapi) HandleCounter(path []string, content string) string { if err != nil { z.Logger.Error( "Failed to add metric", - slog.Any("err", err), + slogx.Err(err), slog.String("key", key), slog.String("display", display), ) diff --git a/cmd/collectors/zapi/collector/zapi.go b/cmd/collectors/zapi/collector/zapi.go index 004f5852a..7556f2b27 100644 --- a/cmd/collectors/zapi/collector/zapi.go +++ b/cmd/collectors/zapi/collector/zapi.go @@ -22,6 +22,7 @@ import ( "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/set" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" "sort" @@ -298,7 +299,7 @@ func (z *Zapi) PollData() (map[string]*matrix.Matrix, error) { if err := metric.SetValueString(instance, value); err != nil { z.Logger.Error( "failed to set value", - slog.Any("err", err), + slogx.Err(err), slog.String("key", key), slog.String("value", value), ) @@ -387,7 +388,7 @@ func (z *Zapi) PollData() (map[string]*matrix.Matrix, error) { if instance, err = mat.NewInstance(key); err != nil { z.Logger.Error( "Failed to create new missing instance", - slog.Any("err", err), + slogx.Err(err), slog.String("instKey", key), ) continue @@ -495,7 +496,7 @@ func (z *Zapi) CollectAutoSupport(p *collector.Payload) { nodeIDs, err = z.getNodeUuids() if err != nil { // log but don't return so the other info below is collected - z.Logger.Error("Unable to get nodes", slog.Any("err", err)) + z.Logger.Error("Unable to get nodes", slogx.Err(err)) } info.Ids = nodeIDs p.Nodes = &info diff --git a/cmd/collectors/zapi/plugins/aggregate/aggregate.go b/cmd/collectors/zapi/plugins/aggregate/aggregate.go index 09bfb3a3b..ead36c95b 100644 --- a/cmd/collectors/zapi/plugins/aggregate/aggregate.go +++ b/cmd/collectors/zapi/plugins/aggregate/aggregate.go @@ -8,6 +8,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" goversion "github.com/netapp/harvest/v2/third_party/go-version" @@ -35,7 +36,7 @@ func (a *Aggregate) Init() error { } if a.client, err = zapi.New(conf.ZapiPoller(a.ParentParams), a.Auth); err != nil { - a.SLogger.Error("connecting", slog.Any("err", err)) + a.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -54,13 +55,13 @@ func (a *Aggregate) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *u // invoke aggr-object-store-get-iter zapi and populate cloud stores info if err := a.getCloudStores(); err != nil { if !errors.Is(err, errs.ErrNoInstance) { - a.SLogger.Error("Failed to update get cloud stores", slog.Any("err", err)) + a.SLogger.Error("Failed to update get cloud stores", slogx.Err(err)) } } aggrFootprintMap, err := a.getAggrFootprint() if err != nil { - a.SLogger.Error("Failed to update footprint data", slog.Any("err", err)) + a.SLogger.Error("Failed to update footprint data", slogx.Err(err)) // clean the map in case of the error clear(aggrFootprintMap) } @@ -79,7 +80,7 @@ func (a *Aggregate) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *u vfMetric := data.GetMetric(afKey) if vfMetric == nil { if vfMetric, err = data.NewMetricFloat64(afKey); err != nil { - a.SLogger.Error("add metric", slog.Any("err", err), slog.String("metric", afKey)) + a.SLogger.Error("add metric", slogx.Err(err), slog.String("metric", afKey)) continue } } @@ -87,11 +88,11 @@ func (a *Aggregate) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *u if afVal != "" { vfMetricVal, err := strconv.ParseFloat(afVal, 64) if err != nil { - a.SLogger.Error("parse", slog.Any("err", err), slog.String(afKey, afVal)) + a.SLogger.Error("parse", slogx.Err(err), slog.String(afKey, afVal)) continue } if err = vfMetric.SetValueFloat64(aggr, vfMetricVal); err != nil { - a.SLogger.Error("set", slog.Any("err", err), slog.String(afKey, afVal)) + a.SLogger.Error("set", slogx.Err(err), slog.String(afKey, afVal)) continue } } @@ -114,7 +115,7 @@ func (a *Aggregate) getCloudStores() error { if err != nil { a.SLogger.Error( "Failed to parse version", - slog.Any("err", err), + slogx.Err(err), slog.String("version", clusterVersion), ) return err diff --git a/cmd/collectors/zapi/plugins/certificate/certificate.go b/cmd/collectors/zapi/plugins/certificate/certificate.go index f286341e7..d1210cf7d 100644 --- a/cmd/collectors/zapi/plugins/certificate/certificate.go +++ b/cmd/collectors/zapi/plugins/certificate/certificate.go @@ -13,6 +13,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "log/slog" @@ -42,7 +43,7 @@ func (c *Certificate) Init() error { } if c.client, err = zapi.New(conf.ZapiPoller(c.ParentParams), c.Auth); err != nil { - c.SLogger.Error("connecting", slog.Any("err", err)) + c.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -82,9 +83,9 @@ func (c *Certificate) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, // invoke vserver-get-iter zapi and get admin vserver name if adminVserver, err = c.GetAdminVserver(); err != nil { if errors.Is(err, errs.ErrNoInstance) { - c.SLogger.Debug("Failed to collect admin SVM", slog.Any("err", err)) + c.SLogger.Debug("Failed to collect admin SVM", slogx.Err(err)) } else { - c.SLogger.Error("Failed to collect admin SVM", slog.Any("err", err)) + c.SLogger.Error("Failed to collect admin SVM", slogx.Err(err)) } return nil, nil, nil } @@ -92,9 +93,9 @@ func (c *Certificate) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, // invoke security-ssl-get-iter zapi and get admin vserver's serial number if adminVserverSerial, err = c.GetSecuritySsl(adminVserver); err != nil { if errors.Is(err, errs.ErrNoInstance) { - c.SLogger.Debug("Failed to collect admin SVM's serial number", slog.Any("err", err)) + c.SLogger.Debug("Failed to collect admin SVM's serial number", slogx.Err(err)) } else { - c.SLogger.Error("Failed to collect admin SVM's serial number", slog.Any("err", err)) + c.SLogger.Error("Failed to collect admin SVM's serial number", slogx.Err(err)) } return nil, nil, nil } @@ -155,7 +156,7 @@ func (c *Certificate) setCertificateIssuerType(instance *matrix.Instance, certif } if cert, err = x509.ParseCertificate(certDecoded.Bytes); err != nil { - c.SLogger.Warn("PEM formatted object is not an X.509 certificate. Only PEM formatted X.509 certificate input is allowed", slog.Any("err", err)) + c.SLogger.Warn("PEM formatted object is not an X.509 certificate. Only PEM formatted X.509 certificate input is allowed", slogx.Err(err)) instance.SetLabel("certificateIssuerType", "unknown") return } diff --git a/cmd/collectors/zapi/plugins/qospolicyadaptive/qospolicyadaptive.go b/cmd/collectors/zapi/plugins/qospolicyadaptive/qospolicyadaptive.go index 24ca1544e..a5cb5f216 100644 --- a/cmd/collectors/zapi/plugins/qospolicyadaptive/qospolicyadaptive.go +++ b/cmd/collectors/zapi/plugins/qospolicyadaptive/qospolicyadaptive.go @@ -4,6 +4,7 @@ import ( "github.com/netapp/harvest/v2/cmd/collectors" "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" ) @@ -60,7 +61,7 @@ func (p *QosPolicyAdaptive) setIOPs(data *matrix.Matrix, instance *matrix.Instan if err != nil { p.SLogger.Error( "Unable to set metric", - slog.Any("err", err), + slogx.Err(err), slog.String(labelName, xput.IOPS), ) } diff --git a/cmd/collectors/zapi/plugins/qospolicyfixed/qospolicyfixed.go b/cmd/collectors/zapi/plugins/qospolicyfixed/qospolicyfixed.go index efc99c807..f7e5172d3 100644 --- a/cmd/collectors/zapi/plugins/qospolicyfixed/qospolicyfixed.go +++ b/cmd/collectors/zapi/plugins/qospolicyfixed/qospolicyfixed.go @@ -4,6 +4,7 @@ import ( "github.com/netapp/harvest/v2/cmd/collectors" "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" ) @@ -32,7 +33,7 @@ func (q *QosPolicyFixed) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matri for _, k := range metrics { err := matrix.CreateMetric(k, data) if err != nil { - q.SLogger.Error("error while creating metric", slog.Any("err", err), slog.String("key", k)) + q.SLogger.Error("error while creating metric", slogx.Err(err), slog.String("key", k)) return nil, nil, err } } diff --git a/cmd/collectors/zapi/plugins/qtree/qtree.go b/cmd/collectors/zapi/plugins/qtree/qtree.go index 9bcdb3b92..23ba04552 100644 --- a/cmd/collectors/zapi/plugins/qtree/qtree.go +++ b/cmd/collectors/zapi/plugins/qtree/qtree.go @@ -8,6 +8,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "log/slog" @@ -50,7 +51,7 @@ func (q *Qtree) Init() error { } if q.client, err = zapi.New(conf.ZapiPoller(q.ParentParams), q.Auth); err != nil { - q.SLogger.Error("connecting", slog.Any("err", err)) + q.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -122,7 +123,7 @@ func (q *Qtree) Init() error { _, err := q.data.NewMetricFloat64(metricName, display) if err != nil { - q.SLogger.Error("add metric", slog.Any("err", err)) + q.SLogger.Error("add metric", slogx.Err(err)) return err } } @@ -313,7 +314,7 @@ func (q *Qtree) handlingQuotaMetrics(quotas []*node.Node, data *matrix.Matrix, q } quotaInstance, err := q.data.NewInstance(quotaInstanceKey) if err != nil { - q.SLogger.Debug("add instance", slog.Any("err", err), slog.String("attribute", attribute)) + q.SLogger.Debug("add instance", slogx.Err(err), slog.String("attribute", attribute)) return err } @@ -368,7 +369,7 @@ func (q *Qtree) handlingQuotaMetrics(quotas []*node.Node, data *matrix.Matrix, q if err := m.SetValueString(quotaInstance, value); err != nil { q.SLogger.Debug( "failed to parse value", - slog.Any("err", err), + slogx.Err(err), slog.String("attribute", attribute), slog.String("value", value), ) diff --git a/cmd/collectors/zapi/plugins/security/security.go b/cmd/collectors/zapi/plugins/security/security.go index 476edfef3..4d0353004 100644 --- a/cmd/collectors/zapi/plugins/security/security.go +++ b/cmd/collectors/zapi/plugins/security/security.go @@ -10,9 +10,9 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" - "log/slog" ) type Security struct { @@ -37,7 +37,7 @@ func (s *Security) Init() error { } if s.client, err = zapi.New(conf.ZapiPoller(s.ParentParams), s.Auth); err != nil { - s.SLogger.Error("connecting", slog.Any("err", err)) + s.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -65,12 +65,12 @@ func (s *Security) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *ut // invoke security-config-get zapi with 'ssl' interface and get fips status if s.fipsEnabled, err = s.getSecurityConfig(); err != nil { - s.SLogger.Warn("Failed to collect fips enable status", slog.Any("err", err)) + s.SLogger.Warn("Failed to collect fips enable status", slogx.Err(err)) } // invoke security-protocol-get zapi with 'telnet' and 'rsh' and get if s.telnetEnabled, s.rshEnabled, err = s.getSecurityProtocols(); err != nil { - s.SLogger.Warn("Failed to collect telnet and rsh enable status", slog.Any("err", err)) + s.SLogger.Warn("Failed to collect telnet and rsh enable status", slogx.Err(err)) } // update instance based on the above zapi response diff --git a/cmd/collectors/zapi/plugins/shelf/shelf.go b/cmd/collectors/zapi/plugins/shelf/shelf.go index 82276ffa9..41ba48bea 100644 --- a/cmd/collectors/zapi/plugins/shelf/shelf.go +++ b/cmd/collectors/zapi/plugins/shelf/shelf.go @@ -8,6 +8,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "log/slog" @@ -48,7 +49,7 @@ func (s *Shelf) Init() error { } if s.client, err = zapi.New(conf.ZapiPoller(s.ParentParams), s.Auth); err != nil { - s.SLogger.Error("connecting", slog.Any("err", err)) + s.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -129,7 +130,7 @@ func (s *Shelf) Init() error { case "float": _, err := s.data[attribute].NewMetricFloat64(metricName, display) if err != nil { - s.SLogger.Error("add metric", slog.Any("err", err)) + s.SLogger.Error("add metric", slogx.Err(err)) return err } s.SLogger.Debug( @@ -255,7 +256,7 @@ func (s *Shelf) handle7Mode(data *matrix.Matrix, result []*node.Node) ([]*matrix for metricName, m := range s.shelfMetrics.GetMetrics() { _, err := data.NewMetricFloat64(metricName, m.GetName()) if err != nil { - s.SLogger.Error("add metric", slog.Any("err", err)) + s.SLogger.Error("add metric", slogx.Err(err)) } s.SLogger.Debug("added", slog.String("metric", m.GetName())) } @@ -278,7 +279,7 @@ func (s *Shelf) handle7Mode(data *matrix.Matrix, result []*node.Node) ([]*matrix // generating new instances from plugin and adding into data newShelfInstance, err := data.NewInstance(shelfInstanceKey) if err != nil { - s.SLogger.Error("add shelf instance", slog.Any("err", err)) + s.SLogger.Error("add shelf instance", slogx.Err(err)) return nil, err } @@ -301,7 +302,7 @@ func (s *Shelf) handle7Mode(data *matrix.Matrix, result []*node.Node) ([]*matrix for metricKey, m := range data.GetMetrics() { if value := strings.Split(shelf.GetChildContentS(metricKey), " ")[0]; value != "" { if err := m.SetValueString(newShelfInstance, value); err != nil { - s.SLogger.Debug("failed to parse", slog.String("metricKey", metricKey), slog.String("value", value), slog.Any("err", err)) + s.SLogger.Debug("failed to parse", slog.String("metricKey", metricKey), slog.String("value", value), slogx.Err(err)) } else { s.SLogger.Debug("added", slog.String("metricKey", metricKey), slog.String("value", value)) } @@ -338,7 +339,7 @@ func (s *Shelf) handle7Mode(data *matrix.Matrix, result []*node.Node) ([]*matrix instance, err := data1.NewInstance(instanceKey) if err != nil { - s.SLogger.Error("add instance", slog.String("attribute", attribute), slog.Any("err", err)) + s.SLogger.Error("add instance", slog.String("attribute", attribute), slogx.Err(err)) return nil, err } s.SLogger.Debug( @@ -374,7 +375,7 @@ func (s *Shelf) handle7Mode(data *matrix.Matrix, result []*node.Node) ([]*matrix "failed to parse", slog.String("metricKey", metricKey), slog.String("value", value), - slog.Any("err", err), + slogx.Err(err), ) } else { s.SLogger.Debug("added", slog.String("metricKey", metricKey), slog.String("value", value)) @@ -434,7 +435,7 @@ func (s *Shelf) parse7ModeTemplate(shelfInfo *node.Node, shelfInstanceKeys, shel case "float": _, err := s.shelfMetrics.NewMetricFloat64(metricName, display) if err != nil { - s.SLogger.Error("add metric", slog.Any("err", err)) + s.SLogger.Error("add metric", slogx.Err(err)) } s.SLogger.Debug("added", slog.String("metric", display)) } diff --git a/cmd/collectors/zapi/plugins/snapmirror/snapmirror.go b/cmd/collectors/zapi/plugins/snapmirror/snapmirror.go index 85bf70993..68d902cb2 100644 --- a/cmd/collectors/zapi/plugins/snapmirror/snapmirror.go +++ b/cmd/collectors/zapi/plugins/snapmirror/snapmirror.go @@ -11,6 +11,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "log/slog" @@ -41,7 +42,7 @@ func (m *SnapMirror) Init() error { return err } if m.client, err = zapi.New(conf.ZapiPoller(m.ParentParams), m.Auth); err != nil { - m.SLogger.Error("connecting", slog.Any("err", err)) + m.SLogger.Error("connecting", slogx.Err(err)) return err } if err := m.client.Init(5); err != nil { diff --git a/cmd/collectors/zapi/plugins/svm/svm.go b/cmd/collectors/zapi/plugins/svm/svm.go index 85da1e353..e8eacd387 100644 --- a/cmd/collectors/zapi/plugins/svm/svm.go +++ b/cmd/collectors/zapi/plugins/svm/svm.go @@ -12,6 +12,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "log/slog" @@ -78,7 +79,7 @@ func (s *SVM) Init() error { } if s.client, err = zapi.New(conf.ZapiPoller(s.ParentParams), s.Auth); err != nil { - s.SLogger.Error("connecting", slog.Any("err", err)) + s.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -127,84 +128,84 @@ func (s *SVM) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Me // invoke fileservice-audit-config-get-iter zapi and get audit protocols if s.auditProtocols, err = s.GetAuditProtocols(); err != nil { if !errors.Is(err, errs.ErrNoInstance) { - s.SLogger.Error("Failed to collect audit protocols", slog.Any("err", err)) + s.SLogger.Error("Failed to collect audit protocols", slogx.Err(err)) } } // invoke cifs-security-get-iter zapi and get cifs protocols if s.cifsProtocols, err = s.GetCifsProtocols(); err != nil { if !errors.Is(err, errs.ErrNoInstance) { - s.SLogger.Error("Failed to collect cifs protocols", slog.Any("err", err)) + s.SLogger.Error("Failed to collect cifs protocols", slogx.Err(err)) } } // invoke nameservice-nsswitch-get-iter zapi and get nsswitch info if s.nsswitchInfo, err = s.GetNSSwitchInfo(); err != nil { if !errors.Is(err, errs.ErrNoInstance) { - s.SLogger.Error("Failed to collect nsswitch info", slog.Any("err", err)) + s.SLogger.Error("Failed to collect nsswitch info", slogx.Err(err)) } } // invoke nis-get-iter zapi and get nisdomain info if s.nisInfo, err = s.GetNisInfo(); err != nil { if !errors.Is(err, errs.ErrNoInstance) { - s.SLogger.Error("Failed to collect nisdomain info", slog.Any("err", err)) + s.SLogger.Error("Failed to collect nisdomain info", slogx.Err(err)) } } // invoke cifs-server-get-iter zapi and get cifsenabled info if s.cifsEnabled, err = s.GetCifsEnabled(); err != nil { if !errors.Is(err, errs.ErrNoInstance) { - s.SLogger.Error("Failed to collect cifsenabled info", slog.Any("err", err)) + s.SLogger.Error("Failed to collect cifsenabled info", slogx.Err(err)) } } // invoke nfs-service-get-iter zapi and get cifsenabled info if s.nfsEnabled, err = s.GetNfsEnabled(); err != nil { if !errors.Is(err, errs.ErrNoInstance) { - s.SLogger.Error("Failed to collect nfsenabled info", slog.Any("err", err)) + s.SLogger.Error("Failed to collect nfsenabled info", slogx.Err(err)) } } // invoke security-ssh-get-iter zapi and get ssh data if s.sshData, err = s.GetSSHData(); err != nil { if !errors.Is(err, errs.ErrNoInstance) { - s.SLogger.Error("Failed to collect ssh data", slog.Any("err", err)) + s.SLogger.Error("Failed to collect ssh data", slogx.Err(err)) } } // invoke iscsi-initiator-auth-get-iter zapi and get iscsi_authentication_type if s.iscsiAuth, err = s.GetIscsiInitiatorAuth(); err != nil { if !errors.Is(err, errs.ErrNoInstance) { - s.SLogger.Error("Failed to collect iscsi authentication type", slog.Any("err", err)) + s.SLogger.Error("Failed to collect iscsi authentication type", slogx.Err(err)) } } // invoke iscsi-service-get-iter zapi and get iscsi_service_enabled if s.iscsiService, err = s.GetIscsiService(); err != nil { if !errors.Is(err, errs.ErrNoInstance) { - s.SLogger.Error("Failed to collect iscsi service", slog.Any("err", err)) + s.SLogger.Error("Failed to collect iscsi service", slogx.Err(err)) } } // invoke fpolicy-policy-status-get-iter zapi and get fpolicy_enabled, fpolicy_name if s.fpolicyData, err = s.GetFpolicy(); err != nil { if !errors.Is(err, errs.ErrNoInstance) { - s.SLogger.Error("Failed to collect fpolicy detail", slog.Any("err", err)) + s.SLogger.Error("Failed to collect fpolicy detail", slogx.Err(err)) } } // invoke ldap-client-get-iter zapi and get ldap_session_security if s.ldapData, err = s.GetLdapData(); err != nil { if !errors.Is(err, errs.ErrNoInstance) { - s.SLogger.Error("Failed to collect ldap session", slog.Any("err", err)) + s.SLogger.Error("Failed to collect ldap session", slogx.Err(err)) } } // invoke kerberos-config-get-iter zapi and get nfs_kerberos_protocol_enabled if s.kerberosConfig, err = s.GetKerberosConfig(); err != nil { if !errors.Is(err, errs.ErrNoInstance) { - s.SLogger.Error("Failed to collect kerberos config", slog.Any("err", err)) + s.SLogger.Error("Failed to collect kerberos config", slogx.Err(err)) } } } diff --git a/cmd/collectors/zapi/plugins/systemnode/systemnode.go b/cmd/collectors/zapi/plugins/systemnode/systemnode.go index a70ae50c8..8a5375bc4 100644 --- a/cmd/collectors/zapi/plugins/systemnode/systemnode.go +++ b/cmd/collectors/zapi/plugins/systemnode/systemnode.go @@ -6,9 +6,9 @@ import ( "github.com/netapp/harvest/v2/pkg/api/ontapi/zapi" "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" - "log/slog" ) type SystemNode struct { @@ -29,7 +29,7 @@ func (s *SystemNode) Init() error { } if s.client, err = zapi.New(conf.ZapiPoller(s.ParentParams), s.Auth); err != nil { - s.SLogger.Error("connecting", slog.Any("err", err)) + s.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -48,13 +48,13 @@ func (s *SystemNode) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, * // invoke service-processor-get-iter zapi and populate the BMC firmware version serviceProcessorMap, err := s.getServiceProcessor() if err != nil { - s.SLogger.Error("Failed to collect service processor info", slog.Any("err", err)) + s.SLogger.Error("Failed to collect service processor info", slogx.Err(err)) } // invoke system-get-node-info-iter zapi and populate node info partnerNameMap, err := s.getPartnerNodeInfo() if err != nil { - s.SLogger.Error("Failed to collect partner node info", slog.Any("err", err)) + s.SLogger.Error("Failed to collect partner node info", slogx.Err(err)) } for _, aNode := range data.GetInstanceKeys() { diff --git a/cmd/collectors/zapi/plugins/volume/volume.go b/cmd/collectors/zapi/plugins/volume/volume.go index 18be48429..27a5b740a 100644 --- a/cmd/collectors/zapi/plugins/volume/volume.go +++ b/cmd/collectors/zapi/plugins/volume/volume.go @@ -8,6 +8,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "log/slog" @@ -44,7 +45,7 @@ func (v *Volume) Init() error { } if v.client, err = zapi.New(conf.ZapiPoller(v.ParentParams), v.Auth); err != nil { - v.SLogger.Error("connecting", slog.Any("err", err)) + v.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -96,12 +97,12 @@ func (v *Volume) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util volumeCloneMap, err := v.getVolumeCloneInfo() if err != nil { - v.SLogger.Error("Failed to update clone data", slog.Any("err", err)) + v.SLogger.Error("Failed to update clone data", slogx.Err(err)) } volumeFootprintMap, err := v.getVolumeFootprint() if err != nil { - v.SLogger.Error("Failed to update footprint data", slog.Any("err", err)) + v.SLogger.Error("Failed to update footprint data", slogx.Err(err)) // clean the map in case of the error clear(volumeFootprintMap) } @@ -145,7 +146,7 @@ func (v *Volume) updateVolumeLabels(data *matrix.Matrix, volumeCloneMap map[stri if splitEstimate, err = data.NewMetricFloat64("clone_split_estimate"); err != nil { v.SLogger.Error( "Failed to add metric", - slog.Any("err", err), + slogx.Err(err), slog.String("metric", "clone_split_estimate"), ) continue @@ -160,7 +161,7 @@ func (v *Volume) updateVolumeLabels(data *matrix.Matrix, volumeCloneMap map[stri if splitEstimateBytes, err = strconv.ParseFloat(vc.splitEstimate, 64); err != nil { v.SLogger.Error( "Failed to parse clone_split_estimate", - slog.Any("err", err), + slogx.Err(err), slog.String("clone_split_estimate", vc.splitEstimate), ) continue @@ -169,7 +170,7 @@ func (v *Volume) updateVolumeLabels(data *matrix.Matrix, volumeCloneMap map[stri if err = splitEstimate.SetValueFloat64(volume, splitEstimateBytes); err != nil { v.SLogger.Error( "Failed to set clone_split_estimate", - slog.Any("err", err), + slogx.Err(err), slog.String("clone_split_estimate", vc.splitEstimate), ) continue @@ -182,7 +183,7 @@ func (v *Volume) updateVolumeLabels(data *matrix.Matrix, volumeCloneMap map[stri vfMetric := data.GetMetric(vfKey) if vfMetric == nil { if vfMetric, err = data.NewMetricFloat64(vfKey); err != nil { - v.SLogger.Error("add metric", slog.Any("err", err), slog.String("metric", vfKey)) + v.SLogger.Error("add metric", slogx.Err(err), slog.String("metric", vfKey)) continue } } @@ -190,11 +191,11 @@ func (v *Volume) updateVolumeLabels(data *matrix.Matrix, volumeCloneMap map[stri if vfVal != "" { vfMetricVal, err := strconv.ParseFloat(vfVal, 64) if err != nil { - v.SLogger.Error("parse", slog.Any("err", err), slog.String(vfKey, vfVal)) + v.SLogger.Error("parse", slogx.Err(err), slog.String(vfKey, vfVal)) continue } if err = vfMetric.SetValueFloat64(volume, vfMetricVal); err != nil { - v.SLogger.Error("set", slog.Any("err", err), slog.String(vfKey, vfVal)) + v.SLogger.Error("set", slogx.Err(err), slog.String(vfKey, vfVal)) continue } } diff --git a/cmd/collectors/zapi/plugins/workload/workload.go b/cmd/collectors/zapi/plugins/workload/workload.go index 4149d294d..67c70365e 100644 --- a/cmd/collectors/zapi/plugins/workload/workload.go +++ b/cmd/collectors/zapi/plugins/workload/workload.go @@ -4,6 +4,7 @@ import ( "github.com/netapp/harvest/v2/cmd/collectors" "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" ) @@ -32,7 +33,7 @@ func (w *Workload) createMetrics(data *matrix.Matrix) error { for _, k := range metrics { err := matrix.CreateMetric(k, data) if err != nil { - w.SLogger.Warn("error while creating metric", slog.Any("err", err), slog.String("key", k)) + w.SLogger.Warn("error while creating metric", slogx.Err(err), slog.String("key", k)) return err } } diff --git a/cmd/collectors/zapiperf/plugins/disk/disk.go b/cmd/collectors/zapiperf/plugins/disk/disk.go index 4b27d66bf..fe2d73059 100644 --- a/cmd/collectors/zapiperf/plugins/disk/disk.go +++ b/cmd/collectors/zapiperf/plugins/disk/disk.go @@ -8,6 +8,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "log/slog" @@ -117,7 +118,7 @@ func (d *Disk) Init() error { } if d.client, err = zapi.New(conf.ZapiPoller(d.ParentParams), d.Auth); err != nil { - d.SLogger.Error("connecting", slog.Any("err", err)) + d.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -180,7 +181,7 @@ func (d *Disk) Init() error { case "float": _, err := d.shelfData[attribute].NewMetricFloat64(metricName, display) if err != nil { - d.SLogger.Error("add metric", slog.Any("err", err)) + d.SLogger.Error("add metric", slogx.Err(err)) return err } } @@ -214,7 +215,7 @@ func (d *Disk) initShelfPowerMatrix() { for _, k := range shelfMetrics { err := matrix.CreateMetric(k, d.powerData["shelf"]) if err != nil { - d.SLogger.Warn("create metric", slog.Any("err", err), slog.String("key", k)) + d.SLogger.Warn("create metric", slogx.Err(err), slog.String("key", k)) } } } @@ -225,7 +226,7 @@ func (d *Disk) initAggrPowerMatrix() { for _, k := range aggrMetrics { err := matrix.CreateMetric(k, d.powerData["aggr"]) if err != nil { - d.SLogger.Warn("create metric", slog.Any("err", err), slog.String("key", k)) + d.SLogger.Warn("create metric", slogx.Err(err), slog.String("key", k)) } } } @@ -381,7 +382,7 @@ func (d *Disk) calculateAggrPower(data *matrix.Matrix, output []*matrix.Matrix) for instanceKey, v := range d.aggrMap { instance, err := aggrData.NewInstance(instanceKey) if err != nil { - d.SLogger.Error("Failed to add instance", slog.Any("err", err), slog.String("key", instanceKey)) + d.SLogger.Error("Failed to add instance", slogx.Err(err), slog.String("key", instanceKey)) continue } instance.SetLabel("aggr", instanceKey) @@ -391,7 +392,7 @@ func (d *Disk) calculateAggrPower(data *matrix.Matrix, output []*matrix.Matrix) m := aggrData.GetMetric("power") err = m.SetValueFloat64(instance, v.power) if err != nil { - d.SLogger.Error("Failed to set value", slog.Any("err", err), slog.String("key", instanceKey)) + d.SLogger.Error("Failed to set value", slogx.Err(err), slog.String("key", instanceKey)) continue } } @@ -641,7 +642,7 @@ func (d *Disk) handleShelfPower(shelves []*node.Node, output []*matrix.Matrix) ( instanceKey := shelfUID instance, err := data.NewInstance(instanceKey) if err != nil { - d.SLogger.Error("add instance", slog.Any("err", err), slog.String("key", instanceKey)) + d.SLogger.Error("add instance", slogx.Err(err), slog.String("key", instanceKey)) return output, err } instance.SetLabel("shelf", shelfName) @@ -734,7 +735,7 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) { err = m.SetValueFloat64(instance, sumPower) if err != nil { - d.SLogger.Error("set power", slog.Any("err", err), slog.Float64("power", sumPower)) + d.SLogger.Error("set power", slogx.Err(err), slog.Float64("power", sumPower)) } else { d.ShelfMap[instance.GetLabel("shelfID")] = &shelf{power: sumPower} } @@ -746,7 +747,7 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) { if err != nil { d.SLogger.Error( "set average_ambient_temperature", - slog.Any("err", err), + slogx.Err(err), slog.Float64("average_ambient_temperature", aaT), ) } @@ -757,7 +758,7 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) { if err != nil { d.SLogger.Error( "set min_ambient_temperature", - slog.Any("err", err), + slogx.Err(err), slog.Float64("min_ambient_temperature", maT), ) } @@ -767,7 +768,7 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) { if err != nil { d.SLogger.Error( "set max_temperature", - slog.Any("err", err), + slogx.Err(err), slog.Float64("max_temperature", mT), ) } @@ -778,7 +779,7 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) { if err != nil { d.SLogger.Error( "set average_temperature", - slog.Any("err", err), + slogx.Err(err), slog.Float64("average_temperature", nat), ) } @@ -789,7 +790,7 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) { if err != nil { d.SLogger.Error( "set min_temperature", - slog.Any("err", err), + slogx.Err(err), slog.Float64("min_temperature", mT), ) } @@ -800,7 +801,7 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) { if err != nil { d.SLogger.Error( "set average_fan_speed", - slog.Any("err", err), + slogx.Err(err), slog.Float64("average_fan_speed", afs), ) } @@ -811,7 +812,7 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) { if err != nil { d.SLogger.Error( "set max_fan_speed", - slog.Any("err", err), + slogx.Err(err), slog.Float64("max_fan_speed", mfs), ) } @@ -821,7 +822,7 @@ func (d *Disk) calculateEnvironmentMetrics(data *matrix.Matrix) { if err != nil { d.SLogger.Error( "set min_fan_speed", - slog.Any("err", err), + slogx.Err(err), slog.Float64("min_fan_speed", mfs), ) } @@ -875,7 +876,7 @@ func (d *Disk) handleCMode(shelves []*node.Node) ([]*matrix.Matrix, error) { instance, err := data1.NewInstance(instanceKey) if err != nil { - d.SLogger.Error("add instance", slog.Any("err", err), slog.String("attribute", attribute)) + d.SLogger.Error("add instance", slogx.Err(err), slog.String("attribute", attribute)) return nil, err } @@ -905,7 +906,7 @@ func (d *Disk) handleCMode(shelves []*node.Node) ([]*matrix.Matrix, error) { "failed to parse value", slog.String("metricKey", metricKey), slog.String("value", value), - slog.Any("err", err), + slogx.Err(err), ) } } diff --git a/cmd/collectors/zapiperf/plugins/fcp/fcp.go b/cmd/collectors/zapiperf/plugins/fcp/fcp.go index 20680c474..0215e8a34 100644 --- a/cmd/collectors/zapiperf/plugins/fcp/fcp.go +++ b/cmd/collectors/zapiperf/plugins/fcp/fcp.go @@ -8,6 +8,7 @@ import ( "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" "math" @@ -91,7 +92,7 @@ func (f *Fcp) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Me rxPercent = rxBytes / float64(speed) err := rx.SetValueFloat64(instance, rxPercent) if err != nil { - f.SLogger.Error("error", slog.Any("err", err)) + f.SLogger.Error("error", slogx.Err(err)) } } @@ -99,14 +100,14 @@ func (f *Fcp) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Me txPercent = txBytes / float64(speed) err := tx.SetValueFloat64(instance, txPercent) if err != nil { - f.SLogger.Error("error", slog.Any("err", err)) + f.SLogger.Error("error", slogx.Err(err)) } } if rxOk || txOk { err := utilPercent.SetValueFloat64(instance, math.Max(rxPercent, txPercent)) if err != nil { - f.SLogger.Error("error", slog.Any("err", err)) + f.SLogger.Error("error", slogx.Err(err)) } } } diff --git a/cmd/collectors/zapiperf/plugins/fcvi/fcvi.go b/cmd/collectors/zapiperf/plugins/fcvi/fcvi.go index d702f34a1..4f7abf5c7 100644 --- a/cmd/collectors/zapiperf/plugins/fcvi/fcvi.go +++ b/cmd/collectors/zapiperf/plugins/fcvi/fcvi.go @@ -6,6 +6,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "log/slog" @@ -29,7 +30,7 @@ func (f *FCVI) Init() error { } if f.client, err = zapi.New(conf.ZapiPoller(f.ParentParams), f.Auth); err != nil { - f.SLogger.Error("connecting", slog.Any("err", err)) + f.SLogger.Error("connecting", slogx.Err(err)) return err } return f.client.Init(5) diff --git a/cmd/collectors/zapiperf/plugins/flexcache/flexcache.go b/cmd/collectors/zapiperf/plugins/flexcache/flexcache.go index 52ddd9b44..4c14781bd 100644 --- a/cmd/collectors/zapiperf/plugins/flexcache/flexcache.go +++ b/cmd/collectors/zapiperf/plugins/flexcache/flexcache.go @@ -6,9 +6,9 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/matrix" "github.com/netapp/harvest/v2/pkg/set" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" - "log/slog" ) const ( @@ -34,7 +34,7 @@ func (f *FlexCache) Init() error { } if f.client, err = zapi.New(conf.ZapiPoller(f.ParentParams), f.Auth); err != nil { - f.SLogger.Error("connecting", slog.Any("err", err)) + f.SLogger.Error("connecting", slogx.Err(err)) return err } diff --git a/cmd/collectors/zapiperf/plugins/nic/nic.go b/cmd/collectors/zapiperf/plugins/nic/nic.go index 3d5ea5179..7467b3990 100644 --- a/cmd/collectors/zapiperf/plugins/nic/nic.go +++ b/cmd/collectors/zapiperf/plugins/nic/nic.go @@ -21,6 +21,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" "log/slog" @@ -53,7 +54,7 @@ func (n *Nic) Init() error { } if n.client, err = zapi.New(conf.ZapiPoller(n.ParentParams), n.Auth); err != nil { - n.SLogger.Error("connecting", slog.Any("err", err)) + n.SLogger.Error("connecting", slogx.Err(err)) return err } @@ -74,7 +75,7 @@ func (n *Nic) Init() error { metricName, display, _, _ := util.ParseMetric(obj) _, err := n.data.NewMetricFloat64(metricName, display) if err != nil { - n.SLogger.Error("add metric", slog.Any("err", err)) + n.SLogger.Error("add metric", slogx.Err(err)) return err } } @@ -167,7 +168,7 @@ func (n *Nic) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Me rxPercent = rxBytes / float64(speed) err := rx.SetValueFloat64(instance, rxPercent) if err != nil { - n.SLogger.Error("error", slog.Any("err", err)) + n.SLogger.Error("error", slogx.Err(err)) } } @@ -175,7 +176,7 @@ func (n *Nic) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Me txPercent = txBytes / float64(speed) err := tx.SetValueFloat64(instance, txPercent) if err != nil { - n.SLogger.Error("error", slog.Any("err", err)) + n.SLogger.Error("error", slogx.Err(err)) } } @@ -184,7 +185,7 @@ func (n *Nic) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Me if rxOk || txOk { err := utilPercent.SetValueFloat64(instance, math.Max(rxPercent, txPercent)) if err != nil { - n.SLogger.Error("error", slog.Any("err", err)) + n.SLogger.Error("error", slogx.Err(err)) } } } @@ -243,7 +244,7 @@ func (n *Nic) getIfgroupInfo() map[string]string { for { responseData, err := n.client.InvokeBatchRequest(request, tag, "") if err != nil { - n.SLogger.Error("Failed to invoke batch zapi call", slog.Any("err", err)) + n.SLogger.Error("Failed to invoke batch zapi call", slogx.Err(err)) return portIfgroupMap } result = responseData.Result diff --git a/cmd/collectors/zapiperf/plugins/volumetag/volumetag.go b/cmd/collectors/zapiperf/plugins/volumetag/volumetag.go index 9db85da5e..16f32113f 100644 --- a/cmd/collectors/zapiperf/plugins/volumetag/volumetag.go +++ b/cmd/collectors/zapiperf/plugins/volumetag/volumetag.go @@ -5,9 +5,9 @@ import ( "github.com/netapp/harvest/v2/pkg/api/ontapi/zapi" "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" - "log/slog" ) const batchSize = "500" @@ -28,7 +28,7 @@ func (v *VolumeTag) Init() error { } if v.client, err = zapi.New(conf.ZapiPoller(v.ParentParams), v.Auth); err != nil { - v.SLogger.Error("connecting", slog.Any("err", err)) + v.SLogger.Error("connecting", slogx.Err(err)) return err } return v.client.Init(5) diff --git a/cmd/collectors/zapiperf/plugins/vscan/vscan.go b/cmd/collectors/zapiperf/plugins/vscan/vscan.go index 29a400791..9555cb1dc 100644 --- a/cmd/collectors/zapiperf/plugins/vscan/vscan.go +++ b/cmd/collectors/zapiperf/plugins/vscan/vscan.go @@ -4,6 +4,7 @@ import ( "github.com/netapp/harvest/v2/cmd/collectors" "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" "strconv" @@ -26,7 +27,7 @@ func (v *Vscan) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util. if parseBool, err := strconv.ParseBool(s); err == nil { isPerScanner = parseBool } else { - v.SLogger.Error("Failed to parse metricsPerScanner", slog.Any("err", err)) + v.SLogger.Error("Failed to parse metricsPerScanner", slogx.Err(err)) } } v.SLogger.Debug("Vscan options", slog.Bool("isPerScanner", isPerScanner)) diff --git a/cmd/collectors/zapiperf/zapiperf.go b/cmd/collectors/zapiperf/zapiperf.go index fb99939aa..91db51133 100644 --- a/cmd/collectors/zapiperf/zapiperf.go +++ b/cmd/collectors/zapiperf/zapiperf.go @@ -43,6 +43,7 @@ import ( "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" "github.com/netapp/harvest/v2/pkg/set" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "log/slog" "strconv" @@ -467,7 +468,7 @@ func (z *ZapiPerf) PollData() (map[string]*matrix.Matrix, error) { startIndex = endIndex if err = z.Client.BuildRequest(request); err != nil { - z.Logger.Error("Build request", slog.Any("err", err), slog.String("objectname", z.Query)) + z.Logger.Error("Build request", slogx.Err(err), slog.String("objectname", z.Query)) return nil, err } @@ -478,7 +479,7 @@ func (z *ZapiPerf) PollData() (map[string]*matrix.Matrix, error) { if strings.Contains(errMsg, "resource limit exceeded") && z.batchSize > 100 { z.Logger.Error( "Changed batch_size", - slog.Any("err", err), + slogx.Err(err), slog.Int("oldBatchSize", z.batchSize), slog.Int("newBatchSize", z.batchSize-100), ) @@ -487,7 +488,7 @@ func (z *ZapiPerf) PollData() (map[string]*matrix.Matrix, error) { } else if strings.Contains(errMsg, "timeout: operation") && z.batchSize > 100 { z.Logger.Error( "ONTAP timeout, reducing batch size", - slog.Any("err", err), + slogx.Err(err), slog.Int("oldBatchSize", z.batchSize), slog.Int("newBatchSize", z.batchSize-100), ) @@ -571,7 +572,7 @@ func (z *ZapiPerf) PollData() (map[string]*matrix.Matrix, error) { // add batch timestamp as custom counter if err := timestamp.SetValueFloat64(instance, ts); err != nil { - z.Logger.Error("set timestamp value", slog.Any("err", err)) + z.Logger.Error("set timestamp value", slogx.Err(err)) } for _, cnt := range counters.GetChildren() { @@ -615,7 +616,7 @@ func (z *ZapiPerf) PollData() (map[string]*matrix.Matrix, error) { if err = metric.SetValueString(instance, values[i]); err != nil { z.Logger.Error( "Set histogram value failed", - slog.Any("err", err), + slogx.Err(err), slog.String("name", name), slog.String("label", label), slog.String("value", values[i]), @@ -647,7 +648,7 @@ func (z *ZapiPerf) PollData() (map[string]*matrix.Matrix, error) { if err := wMetric.AddValueString(instance, value); err != nil { z.Logger.Error( "Add resource_latency failed", - slog.Any("err", err), + slogx.Err(err), slog.String("name", name), slog.String("value", value), slog.Int("instIndex", instIndex), @@ -660,7 +661,7 @@ func (z *ZapiPerf) PollData() (map[string]*matrix.Matrix, error) { if err = wMetric.SetValueString(instance, value); err != nil { z.Logger.Error( "Add service_time_latency failed", - slog.Any("err", err), + slogx.Err(err), slog.String("name", name), slog.String("value", value), slog.Int("instIndex", instIndex), @@ -672,7 +673,7 @@ func (z *ZapiPerf) PollData() (map[string]*matrix.Matrix, error) { if err = wMetric.SetValueString(instance, value); err != nil { z.Logger.Error( "Add wait_time_latency failed", - slog.Any("err", err), + slogx.Err(err), slog.String("name", name), slog.String("value", value), slog.Int("instIndex", instIndex), @@ -690,7 +691,7 @@ func (z *ZapiPerf) PollData() (map[string]*matrix.Matrix, error) { if err = metric.SetValueString(instance, value); err != nil { z.Logger.Error( "Set metric failed", - slog.Any("err", err), + slogx.Err(err), slog.String("name", name), slog.String("value", value), slog.Int("instIndex", instIndex), @@ -765,7 +766,7 @@ func (z *ZapiPerf) PollData() (map[string]*matrix.Matrix, error) { // calculate timestamp delta first since many counters require it for postprocessing. // Timestamp has "raw" property, so it isn't post-processed automatically if _, err = curMat.Delta(timestampMetricName, prevMat, z.Logger); err != nil { - z.Logger.Error("(timestamp) calculate delta:", slog.Any("err", err)) + z.Logger.Error("(timestamp) calculate delta:", slogx.Err(err)) // @TODO terminate since other counters will be incorrect } @@ -784,7 +785,7 @@ func (z *ZapiPerf) PollData() (map[string]*matrix.Matrix, error) { // all other properties - first calculate delta if skips, err = curMat.Delta(key, prevMat, z.Logger); err != nil { - z.Logger.Error("Calculate delta", slog.Any("err", err), slog.String("key", key)) + z.Logger.Error("Calculate delta", slogx.Err(err), slog.String("key", key)) continue } totalSkips += skips @@ -838,7 +839,7 @@ func (z *ZapiPerf) PollData() (map[string]*matrix.Matrix, error) { } if err != nil { - z.Logger.Error("Division by base", slog.Any("err", err), slog.String("key", key)) + z.Logger.Error("Division by base", slogx.Err(err), slog.String("key", key)) } totalSkips += skips @@ -849,7 +850,7 @@ func (z *ZapiPerf) PollData() (map[string]*matrix.Matrix, error) { if property == "percent" { if skips, err = curMat.MultiplyByScalar(key, 100); err != nil { - z.Logger.Error("Multiply by scalar", slog.Any("err", err), slog.String("key", key)) + z.Logger.Error("Multiply by scalar", slogx.Err(err), slog.String("key", key)) } else { totalSkips += skips } @@ -857,7 +858,7 @@ func (z *ZapiPerf) PollData() (map[string]*matrix.Matrix, error) { } z.Logger.Error( "Unknown property", - slog.Any("err", err), + slogx.Err(err), slog.String("key", key), slog.String("property", property), ) @@ -869,7 +870,7 @@ func (z *ZapiPerf) PollData() (map[string]*matrix.Matrix, error) { if skips, err = curMat.Divide(orderedKeys[i], timestampMetricName); err != nil { z.Logger.Error( "Calculate rate", - slog.Any("err", err), + slogx.Err(err), slog.Int("i", i), slog.String("key", orderedKeys[i]), ) @@ -1017,7 +1018,7 @@ func (z *ZapiPerf) getParentOpsCounters(data *matrix.Matrix, keyAttr string) (ti if err = ops.SetValueString(instance, value); err != nil { z.Logger.Error( "set metric value", - slog.Any("err", err), + slogx.Err(err), slog.String("name", name), slog.String("value", value), ) @@ -1212,7 +1213,7 @@ func (z *ZapiPerf) PollCounter() (map[string]*matrix.Matrix, error) { if !oldMetrics.Has(timestampMetricName) { m, err := mat.NewMetricFloat64(timestampMetricName) if err != nil { - z.Logger.Error("add timestamp metric", slog.Any("err", err)) + z.Logger.Error("add timestamp metric", slogx.Err(err)) } m.SetProperty("raw") m.SetExportable(false) @@ -1422,7 +1423,7 @@ func (z *ZapiPerf) addCounter(counter *node.Node, name, display string, enabled if err != nil { z.Logger.Error( "unable to create histogram metric", - slog.Any("err", err), + slogx.Err(err), slog.String("key", key), ) return "" @@ -1454,7 +1455,7 @@ func (z *ZapiPerf) addCounter(counter *node.Node, name, display string, enabled if err != nil { z.Logger.Error( "unable to create array metric", - slog.Any("err", err), + slogx.Err(err), slog.String("key", key), ) return "" @@ -1490,7 +1491,7 @@ func (z *ZapiPerf) addCounter(counter *node.Node, name, display string, enabled if err != nil { z.Logger.Error( "unable to create scalar metric", - slog.Any("err", err), + slogx.Err(err), slog.String("name", name), ) return "" @@ -1619,7 +1620,7 @@ func (z *ZapiPerf) PollInstance() (map[string]*matrix.Matrix, error) { } else { z.Logger.Error( "InvokeBatchRequest failed", - slog.Any("err", err), + slogx.Err(err), slog.String("request", request.GetNameS()), slog.String("batchTag", batchTag), ) @@ -1665,7 +1666,7 @@ func (z *ZapiPerf) PollInstance() (map[string]*matrix.Matrix, error) { z.updateQosLabels(i, instance, key) continue } else if instance, err := mat.NewInstance(key); err != nil { - z.Logger.Error("add instance", slog.Any("err", err)) + z.Logger.Error("add instance", slogx.Err(err)) } else { z.updateQosLabels(i, instance, key) } diff --git a/cmd/collectors/zapiperf/zapiperf_test.go b/cmd/collectors/zapiperf/zapiperf_test.go index 455dad050..51b735ba6 100644 --- a/cmd/collectors/zapiperf/zapiperf_test.go +++ b/cmd/collectors/zapiperf/zapiperf_test.go @@ -6,6 +6,7 @@ import ( "github.com/netapp/harvest/v2/cmd/poller/options" "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree" "github.com/netapp/harvest/v2/pkg/tree/node" "log/slog" @@ -191,7 +192,7 @@ func NewZapiPerf(object, path string) *ZapiPerf { ac := collector.New("Zapiperf", object, opts, params(object, path), nil) z := &ZapiPerf{} if err := z.Init(ac); err != nil { - slog.Error("", slog.Any("err", err)) + slog.Error("", slogx.Err(err)) os.Exit(1) } diff --git a/cmd/exporters/influxdb/influxdb.go b/cmd/exporters/influxdb/influxdb.go index 7b4531fda..f0ebb4d03 100644 --- a/cmd/exporters/influxdb/influxdb.go +++ b/cmd/exporters/influxdb/influxdb.go @@ -11,6 +11,7 @@ import ( "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" "github.com/netapp/harvest/v2/pkg/requests" + "github.com/netapp/harvest/v2/pkg/slogx" "io" "log/slog" "net/http" @@ -167,7 +168,7 @@ func (e *InfluxDB) Export(data *matrix.Matrix) (exporter.Stats, error) { if metrics, stats, err = e.Render(data); err == nil && len(metrics) != 0 { // fix render time if err = e.Metadata.LazyAddValueInt64("time", "render", time.Since(s).Microseconds()); err != nil { - e.Logger.Error("metadata render time", slog.Any("err", err)) + e.Logger.Error("metadata render time", slogx.Err(err)) } // in test mode, don't emit metrics if e.Options.IsTest { @@ -187,13 +188,13 @@ func (e *InfluxDB) Export(data *matrix.Matrix) (exporter.Stats, error) { // update metadata if err = e.Metadata.LazySetValueInt64("time", "export", time.Since(s).Microseconds()); err != nil { - e.Logger.Error("metadata export time", slog.Any("err", err)) + e.Logger.Error("metadata export time", slogx.Err(err)) } if metrics, stats, err = e.Render(e.Metadata); err != nil { - e.Logger.Error("render metadata", slog.Any("err", err)) + e.Logger.Error("render metadata", slogx.Err(err)) } else if err = e.Emit(metrics); err != nil { - e.Logger.Error("emit metadata", slog.Any("err", err)) + e.Logger.Error("emit metadata", slogx.Err(err)) } return stats, nil @@ -357,7 +358,7 @@ func (e *InfluxDB) Render(data *matrix.Matrix) ([][]byte, exporter.Stats, error) // update metadata e.AddExportCount(count) if err := e.Metadata.LazySetValueUint64("count", "export", count); err != nil { - e.Logger.Error("metadata export count", slog.Any("err", err)) + e.Logger.Error("metadata export count", slogx.Err(err)) } return rendered, exporter.Stats{InstancesExported: instancesExported, MetricsExported: count}, nil } diff --git a/cmd/exporters/prometheus/httpd.go b/cmd/exporters/prometheus/httpd.go index c0fc61e44..d6233b6e3 100644 --- a/cmd/exporters/prometheus/httpd.go +++ b/cmd/exporters/prometheus/httpd.go @@ -11,6 +11,7 @@ import ( "errors" "fmt" "github.com/netapp/harvest/v2/pkg/set" + "github.com/netapp/harvest/v2/pkg/slogx" "log/slog" "net" "net/http" @@ -51,7 +52,7 @@ func (p *Prometheus) startHTTPD(addr string, port int) { if err := server.ListenAndServeTLS(p.Params.TLS.CertFile, p.Params.TLS.KeyFile); err != nil && !errors.Is(err, http.ErrServerClosed) { p.Logger.Error( "Failed to start server", - slog.Any("err", err), + slogx.Err(err), slog.String("url", url), slog.String("cert_file", p.Params.TLS.CertFile), slog.String("key_file", p.Params.TLS.KeyFile), @@ -60,7 +61,7 @@ func (p *Prometheus) startHTTPD(addr string, port int) { } } else { if err := server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { - p.Logger.Error("Failed to start server", slog.Any("err", err), slog.String("url", url)) + p.Logger.Error("Failed to start server", slogx.Err(err), slog.String("url", url)) os.Exit(1) } } @@ -110,7 +111,7 @@ func (p *Prometheus) denyAccess(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") _, err := w.Write([]byte("403 Forbidden")) if err != nil { - p.Logger.Error("error", slog.Any("err", err)) + p.Logger.Error("error", slogx.Err(err)) } } @@ -153,7 +154,7 @@ func (p *Prometheus) ServeMetrics(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") _, err := w.Write(bytes.Join(data, []byte("\n"))) if err != nil { - p.Logger.Error("write metrics", slog.Any("err", err)) + p.Logger.Error("write metrics", slogx.Err(err)) } else { // make sure stream ends with newline if _, err2 := w.Write([]byte("\n")); err2 != nil { @@ -165,11 +166,11 @@ func (p *Prometheus) ServeMetrics(w http.ResponseWriter, r *http.Request) { p.Metadata.Reset() err = p.Metadata.LazySetValueInt64("time", "http", time.Since(start).Microseconds()) if err != nil { - p.Logger.Error("metadata time", slog.Any("err", err)) + p.Logger.Error("metadata time", slogx.Err(err)) } err = p.Metadata.LazySetValueInt64("count", "http", int64(count)) if err != nil { - p.Logger.Error("metadata count", slog.Any("err", err)) + p.Logger.Error("metadata count", slogx.Err(err)) } } @@ -292,11 +293,11 @@ func (p *Prometheus) ServeInfo(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") _, err := w.Write([]byte(bodyFlat)) if err != nil { - p.Logger.Error("write info", slog.Any("err", err)) + p.Logger.Error("write info", slogx.Err(err)) } err = p.Metadata.LazyAddValueInt64("time", "info", time.Since(start).Microseconds()) if err != nil { - p.Logger.Error("metadata time", slog.Any("err", err)) + p.Logger.Error("metadata time", slogx.Err(err)) } } diff --git a/cmd/exporters/prometheus/prometheus.go b/cmd/exporters/prometheus/prometheus.go index 01b4e79fb..2e95f7498 100644 --- a/cmd/exporters/prometheus/prometheus.go +++ b/cmd/exporters/prometheus/prometheus.go @@ -27,6 +27,7 @@ import ( "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" "github.com/netapp/harvest/v2/pkg/set" + "github.com/netapp/harvest/v2/pkg/slogx" "log/slog" "regexp" "sort" @@ -102,7 +103,7 @@ func (p *Prometheus) Init() error { p.Logger.Debug("using custom cache_max_keep", slog.String("cacheMaxKeep", *x)) p.cache = newCache(d) } else { - p.Logger.Error("cache_max_keep", slog.Any("err", err), slog.String("x", *x)) + p.Logger.Error("cache_max_keep", slogx.Err(err), slog.String("x", *x)) } } @@ -134,7 +135,7 @@ func (p *Prometheus) Init() error { if reg, err := regexp.Compile(r); err == nil { p.allowAddrsRegex = append(p.allowAddrsRegex, reg) } else { - p.Logger.Error("parse regex", slog.Any("err", err)) + p.Logger.Error("parse regex", slogx.Err(err)) return errs.New(errs.ErrInvalidParam, "allow_addrs_regex") } } @@ -232,11 +233,11 @@ func (p *Prometheus) Export(data *matrix.Matrix) (exporter.Stats, error) { p.AddExportCount(uint64(len(metrics))) err = p.Metadata.LazyAddValueInt64("time", "render", d.Microseconds()) if err != nil { - p.Logger.Error("error", slog.Any("err", err)) + p.Logger.Error("error", slogx.Err(err)) } err = p.Metadata.LazyAddValueInt64("time", "export", time.Since(start).Microseconds()) if err != nil { - p.Logger.Error("error", slog.Any("err", err)) + p.Logger.Error("error", slogx.Err(err)) } return stats, nil @@ -295,13 +296,13 @@ func (p *Prometheus) render(data *matrix.Matrix) ([][]byte, exporter.Stats) { if x := options.GetChildContentS("include_all_labels"); x != "" { if includeAllLabels, err = strconv.ParseBool(x); err != nil { - p.Logger.Error("parameter: include_all_labels", slog.Any("err", err)) + p.Logger.Error("parameter: include_all_labels", slogx.Err(err)) } } if x := options.GetChildContentS("require_instance_keys"); x != "" { if requireInstanceKeys, err = strconv.ParseBool(x); err != nil { - p.Logger.Error("parameter: require_instance_keys", slog.Any("err", err)) + p.Logger.Error("parameter: require_instance_keys", slogx.Err(err)) } } diff --git a/cmd/poller/collector/asup.go b/cmd/poller/collector/asup.go index 16f8950ac..0cfd3c5bd 100644 --- a/cmd/poller/collector/asup.go +++ b/cmd/poller/collector/asup.go @@ -12,6 +12,7 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/logging" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "github.com/shirou/gopsutil/v4/cpu" "github.com/shirou/gopsutil/v4/host" @@ -243,15 +244,15 @@ func BuildAndWriteAutoSupport(collectors []Collector, status *matrix.Matrix, pol pid := os.Getpid() pid32, err := util.SafeConvertToInt32(pid) if err != nil { - logging.Get().Error("", slog.Any("err", err), slog.Int("pid", pid)) + logging.Get().Error("", slogx.Err(err), slog.Int("pid", pid)) } else { newProcess, err := process.NewProcess(pid32) if err != nil { - slog.Default().Error("failed to get process info", slog.Any("err", err)) + slog.Default().Error("failed to get process info", slogx.Err(err)) } else { memInfo, err := newProcess.MemoryInfo() if err != nil { - slog.Default().Error("failed to get memory info", slog.Any("err", err), slog.Int("pid", pid)) + slog.Default().Error("failed to get memory info", slogx.Err(err), slog.Int("pid", pid)) } else { rssBytes = memInfo.RSS } @@ -439,11 +440,11 @@ func getPayloadPath(asupDir string, pollerName string) (string, error) { var perm os.FileMode = 0750 err := checkAndDeleteIfPermissionsMismatch(workingDir, perm) if err != nil { - logging.Get().Warn("", slog.Any("err", err)) + logging.Get().Warn("", slogx.Err(err)) } err = checkAndDeleteIfPermissionsMismatch(payloadDir, perm) if err != nil { - logging.Get().Warn("", slog.Any("err", err)) + logging.Get().Warn("", slogx.Err(err)) } // Create the asup payload directory if needed if _, err := os.Stat(payloadDir); os.IsNotExist(err) { diff --git a/cmd/poller/collector/collector.go b/cmd/poller/collector/collector.go index 2ff2f0070..548215715 100644 --- a/cmd/poller/collector/collector.go +++ b/cmd/poller/collector/collector.go @@ -21,6 +21,7 @@ import ( "fmt" "github.com/netapp/harvest/v2/pkg/auth" "github.com/netapp/harvest/v2/pkg/conf" + "github.com/netapp/harvest/v2/pkg/slogx" "golang.org/x/text/cases" "golang.org/x/text/language" "log/slog" @@ -365,7 +366,7 @@ func (c *AbstractCollector) Start(wg *sync.WaitGroup) { if !c.Schedule.IsStandBy() { c.Logger.Debug( "handling error during poll", - slog.Any("err", err), + slogx.Err(err), slog.String("task", task.Name), ) } @@ -384,7 +385,7 @@ func (c *AbstractCollector) Start(wg *sync.WaitGroup) { } c.Logger.Debug( "target unreachable, entering standby mode and retry", - slog.Any("err", err), + slogx.Err(err), slog.String("task", task.Name), slog.Int("retryDelaySecs", retryDelay), ) @@ -425,7 +426,7 @@ func (c *AbstractCollector) Start(wg *sync.WaitGroup) { c.Schedule.SetStandByModeMax(task, 1*time.Hour) c.Logger.Error( "Entering standby mode", - slog.Any("err", err), + slogx.Err(err), slog.String("task", task.Name), ) case errors.Is(err, errs.ErrAPIRequestRejected): @@ -434,12 +435,12 @@ func (c *AbstractCollector) Start(wg *sync.WaitGroup) { // Log as info since these are not errors. c.Logger.Info( "Entering standby mode", - slog.Any("err", err), + slogx.Err(err), slog.String("task", task.Name), ) } default: - c.Logger.Error("", slog.Any("err", err), slog.String("task", task.Name)) + c.Logger.Error("", slogx.Err(err), slog.String("task", task.Name)) } var herr errs.HarvestError @@ -477,7 +478,7 @@ func (c *AbstractCollector) Start(wg *sync.WaitGroup) { for _, plg := range v { pluginData, pluginMetadata, err := plg.Run(data) if err != nil { - c.Logger.Error("", slog.Any("err", err), slog.String("plugin", plg.GetName())) + c.Logger.Error("", slogx.Err(err), slog.String("plugin", plg.GetName())) continue } if pluginData != nil { @@ -528,7 +529,7 @@ func (c *AbstractCollector) Start(wg *sync.WaitGroup) { if _, err := e.Export(c.Metadata); err != nil { c.Logger.Warn( "Unable to export metadata", - slog.Any("err", err), + slogx.Err(err), slog.String("exporter", e.GetName()), ) } @@ -540,7 +541,7 @@ func (c *AbstractCollector) Start(wg *sync.WaitGroup) { if err != nil { c.Logger.Error( "export data", - slog.Any("err", err), + slogx.Err(err), slog.String("exporter", e.GetName()), ) break @@ -766,7 +767,7 @@ func (c *AbstractCollector) LoadPlugins(params *node.Node, collector Collector, } if err := p.Init(); err != nil { - slog.Error("init plugin", slog.Any("err", err), slog.String("name", name)) + slog.Error("init plugin", slogx.Err(err), slog.String("name", name)) return err } plugins = append(plugins, p) diff --git a/cmd/poller/collector/helpers.go b/cmd/poller/collector/helpers.go index 1b94c2982..669866ef9 100644 --- a/cmd/poller/collector/helpers.go +++ b/cmd/poller/collector/helpers.go @@ -18,6 +18,7 @@ import ( "github.com/netapp/harvest/v2/cmd/poller/plugin/metricagent" "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/third_party/go-version" @@ -110,7 +111,7 @@ nextFile: customTemplate, customTemplateErr = tree.ImportYaml(templatePath) if customTemplateErr != nil { c.Logger.Warn("Unable to import template file. File is invalid or empty", - slog.Any("err", err), + slogx.Err(err), slog.String("path", templatePath), ) continue diff --git a/cmd/poller/plugin/aggregator/aggregator.go b/cmd/poller/plugin/aggregator/aggregator.go index b85154154..6f5044757 100644 --- a/cmd/poller/plugin/aggregator/aggregator.go +++ b/cmd/poller/plugin/aggregator/aggregator.go @@ -9,6 +9,7 @@ import ( "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" "maps" @@ -80,7 +81,7 @@ func (a *Aggregator) parseRules() error { if strings.HasPrefix(value, "`") { value = strings.TrimPrefix(strings.TrimSuffix(value, "`"), "`") if r.checkRegex, err = regexp.Compile(value); err != nil { - a.SLogger.Error("ignore rule", slog.Any("err", err)) + a.SLogger.Error("ignore rule", slogx.Err(err)) return err } } else if value != "" { @@ -222,7 +223,7 @@ func (a *Aggregator) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, * if err = objMetric.AddValueFloat64(objInstance, opsValue*value); err != nil { a.SLogger.Error( "add value", - slog.Any("err", err), + slogx.Err(err), slog.String("key", key), slog.String("objName", objName), ) @@ -234,7 +235,7 @@ func (a *Aggregator) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, * if err = objMetric.AddValueFloat64(objInstance, value); err != nil { a.SLogger.Error( "add value", - slog.Any("err", err), + slogx.Err(err), slog.String("key", key), slog.String("objName", objName), ) @@ -291,7 +292,7 @@ func (a *Aggregator) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, * if err != nil { a.SLogger.Error( "set value", - slog.Any("err", err), + slogx.Err(err), slog.String("mn", mn), slog.String("key", key), ) diff --git a/cmd/poller/plugin/changelog/changelog_helper.go b/cmd/poller/plugin/changelog/changelog_helper.go index 05475675e..38118c0af 100644 --- a/cmd/poller/plugin/changelog/changelog_helper.go +++ b/cmd/poller/plugin/changelog/changelog_helper.go @@ -1,6 +1,7 @@ package changelog import ( + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "gopkg.in/yaml.v3" "log/slog" @@ -63,7 +64,7 @@ func getChangeLogConfig(parentParams *node.Node, overwriteConfig []byte, logger if err != nil { logger.Warn( "failed to parse changelog dsl. Trying default", - slog.Any("err", err), + slogx.Err(err), slog.String("template", string(overwriteConfig)), ) } else { @@ -92,7 +93,7 @@ func getChangeLogConfig(parentParams *node.Node, overwriteConfig []byte, logger entry.PublishLabels = append(entry.PublishLabels, exportedKeys.GetAllChildContentS()...) } else if x := exportOption.GetChildContentS("include_all_labels"); x != "" { if includeAllLabels, err := strconv.ParseBool(x); err != nil { - logger.Error("parameter: include_all_labels", slog.Any("err", err)) + logger.Error("parameter: include_all_labels", slogx.Err(err)) } else if includeAllLabels { entry.includeAll = true } diff --git a/cmd/poller/plugin/labelagent/label_agent.go b/cmd/poller/plugin/labelagent/label_agent.go index 0401f4e53..da57ad061 100644 --- a/cmd/poller/plugin/labelagent/label_agent.go +++ b/cmd/poller/plugin/labelagent/label_agent.go @@ -9,6 +9,7 @@ import ( "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" "strings" @@ -278,7 +279,7 @@ func (a *LabelAgent) mapValueToNum(m *matrix.Matrix) error { if metric = m.GetMetric(r.metric); metric == nil { if metric, err = m.NewMetricUint8(r.metric); err != nil { - a.SLogger.Error("valueToNumMapping", slog.Any("err", err), slog.String("metric", r.metric)) + a.SLogger.Error("valueToNumMapping", slogx.Err(err), slog.String("metric", r.metric)) return err } metric.SetProperty("value_to_num mapping") @@ -306,7 +307,7 @@ func (a *LabelAgent) mapValueToNumRegex(m *matrix.Matrix) error { for _, r := range a.valueToNumRegexRules { if metric = m.GetMetric(r.metric); metric == nil { if metric, err = m.NewMetricUint8(r.metric); err != nil { - a.SLogger.Error("valueToNumRegexMapping", slog.Any("err", err), slog.String("metric", r.metric)) + a.SLogger.Error("valueToNumRegexMapping", slogx.Err(err), slog.String("metric", r.metric)) return err } metric.SetProperty("value_to_num_regex mapping") diff --git a/cmd/poller/plugin/labelagent/parse_rules.go b/cmd/poller/plugin/labelagent/parse_rules.go index dd7dfe67c..28d221d9c 100644 --- a/cmd/poller/plugin/labelagent/parse_rules.go +++ b/cmd/poller/plugin/labelagent/parse_rules.go @@ -6,6 +6,7 @@ package labelagent import ( "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "log/slog" "regexp" "strconv" @@ -241,7 +242,7 @@ func (a *LabelAgent) parseSplitRegexRule(rule string) { if fields = strings.SplitN(fields[1], "` ", 2); len(fields) == 2 { var err error if r.reg, err = regexp.Compile(fields[0]); err != nil { - a.SLogger.Error("(split_regex) invalid regex", slog.Any("err", err)) + a.SLogger.Error("(split_regex) invalid regex", slogx.Err(err)) return } if r.targets = strings.Split(fields[1], ","); len(r.targets) != 0 { @@ -334,7 +335,7 @@ func (a *LabelAgent) parseReplaceRegexRule(rule string) { a.newLabelNames = append(a.newLabelNames, r.target) var err error if r.reg, err = regexp.Compile(strings.TrimSuffix(fields[1], "`")); err != nil { - a.SLogger.Error("(replace_regex) invalid regex", slog.Any("err", err)) + a.SLogger.Error("(replace_regex) invalid regex", slogx.Err(err)) return } @@ -441,7 +442,7 @@ func (a *LabelAgent) parseExcludeRegexRule(rule string) { a.excludeRegexRules = append(a.excludeRegexRules, r) a.SLogger.Debug("parsed exclude_regex", slog.String("pattern", pattern), slog.String("rule", r.label)) } else { - a.SLogger.Error("ignore exclude_regex", slog.Any("err", err)) + a.SLogger.Error("ignore exclude_regex", slogx.Err(err)) } } else { a.SLogger.Error("exclude_regex rule definition should have two fields", slog.String("rule", rule)) @@ -501,7 +502,7 @@ func (a *LabelAgent) parseIncludeRegexRule(rule string) { slog.String("label", r.label), ) } else { - a.SLogger.Error("(include_regex) compile regex", slog.Any("err", err)) + a.SLogger.Error("(include_regex) compile regex", slogx.Err(err)) } } else { a.SLogger.Error("(include_regex) rule definition should have two fields", slog.String("rule", rule)) @@ -542,7 +543,7 @@ func (a *LabelAgent) parseValueToNumRule(rule string) { v, err := strconv.ParseUint(fields[4], 10, 8) if err != nil { - a.SLogger.Error("(value_to_num) parse", slog.Any("err", err), slog.String("default", fields[4])) + a.SLogger.Error("(value_to_num) parse", slogx.Err(err), slog.String("default", fields[4])) return } r.hasDefault = true @@ -579,7 +580,7 @@ func (a *LabelAgent) parseValueToNumRegexRule(rule string) { if r.reg[0], err = regexp.Compile(fields[2]); err != nil { a.SLogger.Error( "(value_to_num_regex) compile regex", - slog.Any("err", err), + slogx.Err(err), slog.String("regex", r.reg[0].String()), slog.String("value", fields[2]), ) @@ -588,7 +589,7 @@ func (a *LabelAgent) parseValueToNumRegexRule(rule string) { if r.reg[1], err = regexp.Compile(fields[3]); err != nil { a.SLogger.Error( "(value_to_num_regex) compile regex", - slog.Any("err", err), + slogx.Err(err), slog.String("regex", r.reg[1].String()), slog.String("value", fields[3]), ) @@ -598,7 +599,7 @@ func (a *LabelAgent) parseValueToNumRegexRule(rule string) { fields[4] = strings.TrimPrefix(strings.TrimSuffix(fields[4], "`"), "`") v, err := strconv.ParseUint(fields[4], 10, 8) if err != nil { - a.SLogger.Error("(value_to_num_regex) parse default value", slog.Any("err", err), slog.String("regex", fields[4])) + a.SLogger.Error("(value_to_num_regex) parse default value", slogx.Err(err), slog.String("regex", fields[4])) return } r.hasDefault = true diff --git a/cmd/poller/plugin/max/max.go b/cmd/poller/plugin/max/max.go index 5230bcfd7..d3a46948c 100644 --- a/cmd/poller/plugin/max/max.go +++ b/cmd/poller/plugin/max/max.go @@ -8,6 +8,7 @@ import ( "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" "regexp" @@ -84,7 +85,7 @@ func (m *Max) parseRules() error { if r.checkRegex, err = regexp.Compile(value); err != nil { m.SLogger.Error( "rule compile regex", - slog.Any("err", err), + slogx.Err(err), slog.String("line", line), ) return err @@ -204,7 +205,7 @@ func (m *Max) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Me if err = objMetric.SetValueFloat64(objInstance, value); err != nil { m.SLogger.Error( "add value", - slog.Any("err", err), + slogx.Err(err), slog.String("key", key), slog.String("objName", objName), ) diff --git a/cmd/poller/plugin/metricagent/metric_agent.go b/cmd/poller/plugin/metricagent/metric_agent.go index 6ac248f9c..30ce39b30 100644 --- a/cmd/poller/plugin/metricagent/metric_agent.go +++ b/cmd/poller/plugin/metricagent/metric_agent.go @@ -8,6 +8,7 @@ import ( "github.com/netapp/harvest/v2/cmd/poller/plugin" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/util" "log/slog" "strconv" @@ -69,7 +70,7 @@ func (a *MetricAgent) computeMetrics(m *matrix.Matrix) error { for _, r := range a.computeMetricRules { if metric = a.getMetric(m, r.metric); metric == nil { if metric, err = m.NewMetricFloat64(r.metric); err != nil { - a.SLogger.Error("Failed to create metric", slog.Any("err", err), slog.String("metric", r.metric)) + a.SLogger.Error("Failed to create metric", slogx.Err(err), slog.String("metric", r.metric)) return err } metric.SetProperty("compute_metric mapping") @@ -86,7 +87,7 @@ func (a *MetricAgent) computeMetrics(m *matrix.Matrix) error { continue } } else { - a.SLogger.Warn("computeMetrics: metric not found", slog.Any("err", err), slog.String("metricName", r.metricNames[0])) + a.SLogger.Warn("computeMetrics: metric not found", slogx.Err(err), slog.String("metricName", r.metricNames[0])) } // Parse other operands and process them diff --git a/cmd/poller/poller.go b/cmd/poller/poller.go index a03494411..05cd6151f 100644 --- a/cmd/poller/poller.go +++ b/cmd/poller/poller.go @@ -55,6 +55,7 @@ import ( "github.com/netapp/harvest/v2/pkg/logging" "github.com/netapp/harvest/v2/pkg/matrix" "github.com/netapp/harvest/v2/pkg/requests" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" goversion "github.com/netapp/harvest/v2/third_party/go-version" @@ -168,7 +169,7 @@ func (p *Poller) Init() error { // Using default instance of logger which logs below error to harvest.log slog.Default().With(slog.String("Poller", p.name)).Error( "Unable to read config", - slog.Any("err", err), + slogx.Err(err), slog.String("config", p.options.Config), slog.String("configPath", configPath), ) @@ -178,7 +179,7 @@ func (p *Poller) Init() error { if err != nil { slog.Default().With(slog.String("Poller", p.name)).Error( "Failed to find poller", - slog.Any("err", err), + slogx.Err(err), slog.String("config", p.options.Config), slog.String("configPath", configPath), ) @@ -227,7 +228,7 @@ func (p *Poller) Init() error { getwd, err := os.Getwd() if err != nil { - slog.Error("Unable to get current working directory", slog.Any("err", err)) + slog.Error("Unable to get current working directory", slogx.Err(err)) getwd = "" } slog.Info("Init", @@ -249,7 +250,7 @@ func (p *Poller) Init() error { if err != nil { slog.Error( "Unable to read cert file", - slog.Any("err", err), + slogx.Err(err), slog.String("certFile", conf.Config.Admin.Httpsd.TLS.CertFile), ) os.Exit(1) @@ -315,7 +316,7 @@ func (p *Poller) Init() error { if err != nil { slog.Error( "Failed to read objects", - slog.Any("err", err), + slogx.Err(err), slog.String("collector", c.Name), slog.String("templates", strings.Join(*c.Templates, ",")), slog.String("error", err.Error()), @@ -333,7 +334,7 @@ func (p *Poller) Init() error { // start the uniqueified collectors err = p.loadCollectorObject(uniqueOCs) if err != nil { - logger.Error("Failed to load collector", slog.Any("err", err)) + logger.Error("Failed to load collector", slogx.Err(err)) } // at least one collector should successfully initialize @@ -360,7 +361,7 @@ func (p *Poller) Init() error { } p.schedule = schedule.New() if err = p.schedule.NewTaskString("poller", pollerSchedule, 0, nil, true, "poller_"+p.name); err != nil { - logger.Error("set schedule:", slog.Any("err", err)) + logger.Error("set schedule:", slogx.Err(err)) return err } @@ -368,7 +369,7 @@ func (p *Poller) Init() error { pollerLogSchedule = p.params.PollerLogSchedule } if err = p.schedule.NewTaskString("log", pollerLogSchedule, 0, p.logPollerMetadata, true, "poller_log_"+p.name); err != nil { - logger.Error("set log schedule:", slog.Any("err", err)) + logger.Error("set log schedule:", slogx.Err(err)) return err } @@ -391,7 +392,7 @@ func (p *Poller) Init() error { if err != nil { logger.Error( "Failed to write first autosupport payload.", - slog.Any("err", err), + slogx.Err(err), slog.String("asupFirstWrite", asupFirstWrite), ) } else { @@ -478,7 +479,7 @@ func (p *Poller) firstAutoSupport() { if _, err := collector.BuildAndWriteAutoSupport(p.collectors, p.metadataTarget, p.name, p.maxRssBytes); err != nil { slog.Error( "First autosupport failed", - slog.Any("err", err), + slogx.Err(err), slog.String("poller", p.name), ) } @@ -489,7 +490,7 @@ func (p *Poller) startAsup() (map[string]*matrix.Matrix, error) { if err := collector.SendAutosupport(p.collectors, p.metadataTarget, p.name, p.maxRssBytes); err != nil { slog.Error( "Start autosupport failed.", - slog.Any("err", err), + slogx.Err(err), slog.String("poller", p.name), ) return nil, err @@ -618,13 +619,13 @@ func (p *Poller) Run() { // @TODO if there are no "master" exporters, don't collect metadata for _, ee := range p.exporters { if _, err := ee.Export(p.metadata); err != nil { - logger.Error("export component metadata", slog.Any("err", err)) + logger.Error("export component metadata", slogx.Err(err)) } if _, err := ee.Export(p.metadataTarget); err != nil { - logger.Error("export target metadata", slog.Any("err", err)) + logger.Error("export target metadata", slogx.Err(err)) } if _, err := ee.Export(p.status); err != nil { - logger.Error("export poller status", slog.Any("err", err)) + logger.Error("export poller status", slogx.Err(err)) } } @@ -736,7 +737,7 @@ func (p *Poller) readObjects(c conf.Collector) ([]objectCollector, error) { context.Background(), level, "Unable to load template", - slog.Any("err", err), + slogx.Err(err), slog.String("template", t), slog.String("collector", class), slog.Any("confPaths", p.options.ConfPaths), @@ -806,16 +807,16 @@ func (p *Poller) loadCollectorObject(ocs []objectCollector) error { case errors.Is(err, errs.ErrConnection): logger.Warn( "abort collector", - slog.Any("err", err), + slogx.Err(err), slog.String("collector", oc.class), slog.String("object", oc.object), ) case errors.Is(err, errs.ErrWrongTemplate): - logger.Debug("Zapi Status_7mode failed to load", slog.Any("err", err)) + logger.Debug("Zapi Status_7mode failed to load", slogx.Err(err)) default: logger.Warn( "init collector-object", - slog.Any("err", err), + slogx.Err(err), slog.String("collector", oc.class), slog.String("object", oc.object), ) @@ -1019,7 +1020,7 @@ func (p *Poller) loadExporter(name string) exporter.Exporter { return nil } if err = exp.Init(); err != nil { - logger.Error("Unable to init exporter", slog.Any("err", err), slog.String("name", name)) + logger.Error("Unable to init exporter", slogx.Err(err), slog.String("name", name)) return nil } @@ -1028,7 +1029,7 @@ func (p *Poller) loadExporter(name string) exporter.Exporter { // update metadata if instance, err := p.metadata.NewInstance(exp.GetClass() + "." + exp.GetName()); err != nil { - logger.Error("add metadata instance", slog.Any("err", err)) + logger.Error("add metadata instance", slogx.Err(err)) } else { instance.SetLabel("type", "exporter") instance.SetLabel("name", exp.GetClass()) @@ -1147,7 +1148,7 @@ type pollerDetails struct { func (p *Poller) publishDetails() { localIP, err := util.FindLocalIP() if err != nil { - logger.Error("Unable to find local IP", slog.Any("err", err)) + logger.Error("Unable to find local IP", slogx.Err(err)) return } if p.client == nil { @@ -1186,7 +1187,7 @@ func (p *Poller) publishDetails() { } payload, err := json.Marshal(details) if err != nil { - logger.Error("Unable to marshal poller details", slog.Any("err", err), slog.String("poller", p.name)) + logger.Error("Unable to marshal poller details", slogx.Err(err), slog.String("poller", p.name)) return } defaultURL := p.makePublishURL() @@ -1196,7 +1197,7 @@ func (p *Poller) publishDetails() { } req, err := requests.New("PUT", heartBeatURL, bytes.NewBuffer(payload)) if err != nil { - logger.Error("failed to connect to admin", slog.Any("err", err)) + logger.Error("failed to connect to admin", slogx.Err(err)) return } req.Header.Set("Content-Type", "application/json; charset=utf-8") @@ -1229,7 +1230,7 @@ func (p *Poller) publishDetails() { defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { - logger.Error("failed to read publishDetails response to admin", slog.Any("err", err)) + logger.Error("failed to read publishDetails response to admin", slogx.Err(err)) return } p.client.CloseIdleConnections() @@ -1263,7 +1264,7 @@ func (p *Poller) startHeartBeat() { if err != nil { logger.Warn( "Invalid heart_beat using 1m", - slog.Any("err", err), + slogx.Err(err), slog.String("heart_beat", conf.Config.Admin.Httpsd.HeartBeat), ) duration = 1 * time.Minute @@ -1344,7 +1345,7 @@ func (p *Poller) negotiateAPI(c conf.Collector, checkZAPIs func() error) conf.Co Templates: c.Templates, } } - logger.Error("Failed to negotiateAPI", slog.Any("err", err), slog.String("collector", c.Name)) + logger.Error("Failed to negotiateAPI", slogx.Err(err), slog.String("collector", c.Name)) } return c @@ -1392,12 +1393,12 @@ func (p *Poller) addMemoryMetadata() { proc, err := process.NewProcess(pid32) if err != nil { - slog.Error("Failed to lookup process for poller", slog.Any("err", err), slog.Int("pid", pid)) + slog.Error("Failed to lookup process for poller", slogx.Err(err), slog.Int("pid", pid)) return } memInfo, err := proc.MemoryInfo() if err != nil { - slog.Error("Failed to get memory info for poller", slog.Any("err", err), slog.Int("pid", pid)) + slog.Error("Failed to get memory info for poller", slogx.Err(err), slog.Int("pid", pid)) return } @@ -1409,7 +1410,7 @@ func (p *Poller) addMemoryMetadata() { // Calculate memory percentage memory, err := mem.VirtualMemory() if err != nil { - slog.Error("Failed to get memory for machine", slog.Any("err", err), slog.Int("pid", pid)) + slog.Error("Failed to get memory for machine", slogx.Err(err), slog.Int("pid", pid)) return } @@ -1423,7 +1424,7 @@ func (p *Poller) addMemoryMetadata() { func (p *Poller) logPollerMetadata() (map[string]*matrix.Matrix, error) { err := p.sendHarvestVersion() if err != nil { - slog.Error("Failed to send Harvest version", slog.Any("err", err)) + slog.Error("Failed to send Harvest version", slogx.Err(err)) } rss, _ := p.status.LazyGetValueFloat64("memory.rss", "host") diff --git a/integration/certer/main.go b/integration/certer/main.go index abd53ca76..c36a407e7 100644 --- a/integration/certer/main.go +++ b/integration/certer/main.go @@ -9,6 +9,7 @@ import ( "github.com/Netapp/harvest-automation/certer/models" "github.com/Netapp/harvest-automation/test/utils" "github.com/carlmjohnson/requests" + "github.com/netapp/harvest/v2/pkg/slogx" "log/slog" "net/http" "os" @@ -72,7 +73,7 @@ func begin() { // Query for existing CA certificates, err := fetchCA() if err != nil { - slog.Error("", slog.Any("err", err)) + slog.Error("", slogx.Err(err)) return } @@ -84,7 +85,7 @@ func begin() { // Create private key and certificate signing request (CSR) csr, err := ensureOpenSSLInstalled() if err != nil { - slog.Error("", slog.Any("err", err)) + slog.Error("", slogx.Err(err)) return } @@ -96,7 +97,7 @@ func begin() { err := deleteCertificates(certificates) if err != nil { - slog.Error("failed to delete certificates", slog.Any("err", err)) + slog.Error("failed to delete certificates", slogx.Err(err)) return } } @@ -104,21 +105,21 @@ func begin() { // Create a root CA certificate that will be used to sign certificate requests for the user account(s) err = createRootCA() if err != nil { - slog.Error("failed", slog.Any("err", err)) + slog.Error("failed", slogx.Err(err)) return } // Sign the locally created certificate with the root CA generated above err = signCSR(csr) if err != nil { - slog.Error("failed", slog.Any("err", err)) + slog.Error("failed", slogx.Err(err)) return } // Add certificate auth to this ONTAP user err = addCertificateAuthToHarvestUser() if err != nil { - slog.Error("", slog.Any("err", err)) + slog.Error("", slogx.Err(err)) } @@ -131,7 +132,7 @@ func begin() { func sleep(s string) { duration, err := time.ParseDuration(s) if err != nil { - slog.Error("failed to sleep", slog.Any("err", err)) + slog.Error("failed to sleep", slogx.Err(err)) } slog.Info("sleep", slog.String("sleep", s)) time.Sleep(duration) @@ -149,7 +150,7 @@ func curlServer() { fmt.Sprintf("https://%s/api/cluster?fields=version", ip)) output, err := command.CombinedOutput() if err != nil { - slog.Error("failed to exec curl", slog.Any("err", err), slog.String("output", string(output))) + slog.Error("failed to exec curl", slogx.Err(err), slog.String("output", string(output))) } else { fmt.Println(string(output)) return @@ -323,7 +324,7 @@ func fetchAdminSVM() { ToJSON(&svmResp). Fetch(context.Background()) if err != nil { - slog.Error("failed to fetch admin SVM", slog.Any("err", err)) + slog.Error("failed to fetch admin SVM", slogx.Err(err)) return } adminSVM = svmResp.Records[0].Vserver diff --git a/integration/go.mod b/integration/go.mod index 28ee86bdf..55d1b3c2c 100644 --- a/integration/go.mod +++ b/integration/go.mod @@ -10,7 +10,7 @@ require ( github.com/carlmjohnson/requests v0.24.2 github.com/netapp/harvest/v2 v2.0.0-20241001142758-f137ab714dd8 github.com/tidwall/gjson v1.18.0 - golang.org/x/text v0.18.0 + golang.org/x/text v0.19.0 ) require ( @@ -35,8 +35,8 @@ require ( github.com/tklauser/numcpus v0.8.0 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect golang.org/x/net v0.29.0 // indirect - golang.org/x/sys v0.25.0 // indirect - golang.org/x/term v0.24.0 // indirect + golang.org/x/sys v0.26.0 // indirect + golang.org/x/term v0.25.0 // indirect gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/integration/go.sum b/integration/go.sum index e44fa1391..4fd396742 100644 --- a/integration/go.sum +++ b/integration/go.sum @@ -65,12 +65,12 @@ golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= -golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM= -golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8= -golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= -golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24= +golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/integration/test/copy_logs_test.go b/integration/test/copy_logs_test.go index 5185163d2..ba96da752 100644 --- a/integration/test/copy_logs_test.go +++ b/integration/test/copy_logs_test.go @@ -6,6 +6,7 @@ import ( "github.com/Netapp/harvest-automation/test/docker" "github.com/Netapp/harvest-automation/test/installer" "github.com/Netapp/harvest-automation/test/utils" + "github.com/netapp/harvest/v2/pkg/slogx" "log/slog" "os/exec" "testing" @@ -28,7 +29,7 @@ func TestCopyLogs(t *testing.T) { if err != nil { slog.Error( "Unable to copy logs", - slog.Any("err", err), + slogx.Err(err), slog.String("id", containerShortID), slog.String("dest", dest), ) diff --git a/integration/test/counter_test.go b/integration/test/counter_test.go index 9a90a7360..a55a07536 100644 --- a/integration/test/counter_test.go +++ b/integration/test/counter_test.go @@ -8,6 +8,7 @@ import ( rest2 "github.com/netapp/harvest/v2/cmd/tools/rest" "github.com/netapp/harvest/v2/pkg/auth" "github.com/netapp/harvest/v2/pkg/conf" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/pkg/tree" "github.com/netapp/harvest/v2/pkg/tree/node" "github.com/netapp/harvest/v2/pkg/util" @@ -45,13 +46,13 @@ func TestCounters(t *testing.T) { utils.SkipIfMissing(t, utils.Regression) _, err := conf.LoadHarvestConfig(installer.HarvestConfigFile) if err != nil { - slog.Error("Unable to load harvest config", slog.Any("err", err)) + slog.Error("Unable to load harvest config", slogx.Err(err)) os.Exit(1) } pollerName := "dc1" if poller, err = conf.PollerNamed(pollerName); err != nil { - slog.Error("", slog.Any("err", err), slog.String("poller", pollerName)) + slog.Error("", slogx.Err(err), slog.String("poller", pollerName)) os.Exit(1) } if poller.Addr == "" { @@ -63,20 +64,20 @@ func TestCounters(t *testing.T) { if client, err = rest2.New(poller, timeout, auth.NewCredentials(poller, slog.Default())); err != nil { slog.Error( "error creating new client", - slog.Any("err", err), + slogx.Err(err), slog.String("poller", pollerName), ) os.Exit(1) } if err = client.Init(5); err != nil { - slog.Error("client init failed", slog.Any("err", err)) + slog.Error("client init failed", slogx.Err(err)) os.Exit(1) } restCounters := processRestCounters(client) if err = invokeRestCall(client, restCounters); err != nil { - slog.Error("rest call failed", slog.Any("err", err)) + slog.Error("rest call failed", slogx.Err(err)) os.Exit(1) } @@ -118,7 +119,7 @@ func visitRestTemplates(dir string, client *rest2.Client, eachTemp func(path str result := make(map[string][]counterData) err := filepath.Walk(dir, func(path string, _ os.FileInfo, err error) error { if err != nil { - slog.Error("failed to read directory:", slog.Any("err", err)) + slog.Error("failed to read directory:", slogx.Err(err)) os.Exit(1) } ext := filepath.Ext(path) @@ -141,7 +142,7 @@ func visitRestTemplates(dir string, client *rest2.Client, eachTemp func(path str }) if err != nil { - slog.Error("failed to walk directory", slog.Any("err", err), slog.String("dir", dir)) + slog.Error("failed to walk directory", slogx.Err(err), slog.String("dir", dir)) os.Exit(1) } diff --git a/integration/test/grafana/grafana_mgr.go b/integration/test/grafana/grafana_mgr.go index 47267d02b..6a894446c 100644 --- a/integration/test/grafana/grafana_mgr.go +++ b/integration/test/grafana/grafana_mgr.go @@ -5,6 +5,7 @@ import ( "github.com/Netapp/harvest-automation/test/docker" "github.com/Netapp/harvest-automation/test/installer" "github.com/Netapp/harvest-automation/test/utils" + "github.com/netapp/harvest/v2/pkg/slogx" "log/slog" "regexp" ) @@ -45,7 +46,7 @@ func (g *Mgr) Import() (bool, string) { importOutput, err = utils.Exec(installer.HarvestHome, "bin/harvest", nil, importCmds...) } if err != nil { - slog.Error("error", slog.Any("err", err)) + slog.Error("error", slogx.Err(err)) panic(err) } if re.MatchString(importOutput) { diff --git a/integration/test/installer/harvest.go b/integration/test/installer/harvest.go index af467313b..dd8836656 100644 --- a/integration/test/installer/harvest.go +++ b/integration/test/installer/harvest.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/Netapp/harvest-automation/test/core" "github.com/Netapp/harvest-automation/test/utils" + "github.com/netapp/harvest/v2/pkg/slogx" "log/slog" "strings" "time" @@ -18,7 +19,7 @@ type Harvest struct { func (h *Harvest) Start() { status, err := utils.Exec(HarvestHome, HarvestBin, nil, "start") if err != nil { - slog.Error("", slog.Any("err", err)) + slog.Error("", slogx.Err(err)) panic(err) } fmt.Println(status) @@ -29,7 +30,7 @@ func (h *Harvest) Start() { func (h *Harvest) Stop() { status, err := utils.Exec(HarvestHome, HarvestBin, nil, "stop") if err != nil { - slog.Error("", slog.Any("err", err)) + slog.Error("", slogx.Err(err)) panic(err) } fmt.Println(status) @@ -49,7 +50,7 @@ func (h *Harvest) GetPollerInfo() []core.Poller { slog.Info("Getting all pollers details") harvestStatus, err := utils.Exec(HarvestHome, HarvestBin, nil, "status") if err != nil { - slog.Error("", slog.Any("err", err)) + slog.Error("", slogx.Err(err)) panic(err) } fmt.Println(harvestStatus) diff --git a/integration/test/installer/installer.go b/integration/test/installer/installer.go index e9a96f286..2ebaab01e 100644 --- a/integration/test/installer/installer.go +++ b/integration/test/installer/installer.go @@ -3,6 +3,7 @@ package installer import ( "bufio" "github.com/Netapp/harvest-automation/test/utils" + "github.com/netapp/harvest/v2/pkg/slogx" "log/slog" "os" "strings" @@ -27,7 +28,7 @@ func GetPerfFileWithQosCounters(source string, target string) string { writeBuffer := bufio.NewWriter(writeFile) file, err := os.Open(utils.GetHarvestRootDir() + "/" + source) if err != nil { - slog.Error("", slog.Any("err", err)) + slog.Error("", slogx.Err(err)) } defer func(file *os.File) { _ = file.Close() }(file) @@ -41,7 +42,7 @@ func GetPerfFileWithQosCounters(source string, target string) string { _, _ = writeBuffer.WriteString(lineString + "\n") } if err := scanner.Err(); err != nil { - slog.Error("", slog.Any("err", err)) + slog.Error("", slogx.Err(err)) } _ = writeBuffer.Flush() return modifiedFilePath diff --git a/integration/test/installer/native.go b/integration/test/installer/native.go index 09f3d4068..a652cb4c3 100644 --- a/integration/test/installer/native.go +++ b/integration/test/installer/native.go @@ -3,6 +3,7 @@ package installer import ( "errors" "github.com/Netapp/harvest-automation/test/utils" + "github.com/netapp/harvest/v2/pkg/slogx" "log/slog" ) @@ -28,7 +29,7 @@ func (n *Native) Install() bool { slog.Info("Installing " + tarFileName) unTarOutput, err := utils.Run("tar", "-xf", tarFileName, "--one-top-level=harvest", "--strip-components", "1", "-C", "/opt") if err != nil { - slog.Error("", slog.Any("err", err)) + slog.Error("", slogx.Err(err)) panic(err) } slog.Info("Untar output: " + unTarOutput) diff --git a/integration/test/installer/rpm.go b/integration/test/installer/rpm.go index 7feec789f..018f79f07 100644 --- a/integration/test/installer/rpm.go +++ b/integration/test/installer/rpm.go @@ -3,6 +3,7 @@ package installer import ( "errors" "github.com/Netapp/harvest-automation/test/utils" + "github.com/netapp/harvest/v2/pkg/slogx" "log/slog" "strings" ) @@ -29,7 +30,7 @@ func (r *RPM) Install() bool { slog.Info("Installing " + rpmFileName) installOutput, err := utils.Run("yum", "install", "-y", rpmFileName) if err != nil { - slog.Error("", slog.Any("err", err)) + slog.Error("", slogx.Err(err)) panic(err) } slog.Info(installOutput) @@ -56,7 +57,7 @@ func (r *RPM) Upgrade() bool { versionCmd := []string{"-qa", "harvest"} out, err := utils.Run("rpm", versionCmd...) if err != nil { - slog.Error("", slog.Any("err", err)) + slog.Error("", slogx.Err(err)) panic(err) } previousVersion := strings.TrimSpace(out) diff --git a/integration/test/metric_test.go b/integration/test/metric_test.go index 205945504..7b7a6fa7c 100644 --- a/integration/test/metric_test.go +++ b/integration/test/metric_test.go @@ -5,6 +5,7 @@ import ( "github.com/Netapp/harvest-automation/test/installer" "github.com/Netapp/harvest-automation/test/utils" "github.com/netapp/harvest/v2/pkg/conf" + "github.com/netapp/harvest/v2/pkg/slogx" "log/slog" "os" "sort" @@ -28,7 +29,7 @@ func TestPollerMetrics(t *testing.T) { utils.SkipIfMissing(t, utils.Regression) _, err := conf.LoadHarvestConfig(installer.HarvestConfigFile) if err != nil { - slog.Error("Unable to load harvest config", slog.Any("err", err)) + slog.Error("Unable to load harvest config", slogx.Err(err)) os.Exit(1) } var duplicateMetrics []string diff --git a/integration/test/utils/http_utils.go b/integration/test/utils/http_utils.go index afd3bb0e0..82d5a1147 100644 --- a/integration/test/utils/http_utils.go +++ b/integration/test/utils/http_utils.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "github.com/netapp/harvest/v2/pkg/requests" + "github.com/netapp/harvest/v2/pkg/slogx" "io" "log/slog" "net/http" @@ -27,12 +28,12 @@ func GetResponse(url string) (string, error) { func GetResponseBody(url string) ([]byte, error) { resp, err := http.Get(url) //nolint:gosec if err != nil { - slog.Error("", slog.Any("err", err)) + slog.Error("", slogx.Err(err)) os.Exit(1) } body, err := io.ReadAll(resp.Body) if err != nil { - slog.Error("", slog.Any("err", err)) + slog.Error("", slogx.Err(err)) os.Exit(1) } resp.Body.Close() diff --git a/integration/test/utils/utils.go b/integration/test/utils/utils.go index eaaef5101..f2b2894b9 100644 --- a/integration/test/utils/utils.go +++ b/integration/test/utils/utils.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/netapp/harvest/v2/cmd/tools/grafana" "github.com/netapp/harvest/v2/pkg/conf" + "github.com/netapp/harvest/v2/pkg/slogx" "io" "log/slog" "net" @@ -14,7 +15,6 @@ import ( "os" "os/exec" "path/filepath" - "runtime" "strconv" "strings" "testing" @@ -268,7 +268,7 @@ func WriteToken(token string) { } f, err := os.OpenFile(filename, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0600) if err != nil { - slog.Error("Failed to open file", slog.Any("err", err)) + slog.Error("Failed to open file", slogx.Err(err)) os.Exit(1) } defer func(f *os.File) { _ = f.Close() }(f) @@ -333,25 +333,6 @@ func SetupLogging() { slog.SetDefault(logger) } -func MarshalStack(err error) interface{} { - if err == nil { - return nil - } - // We don't know how big the stack trace will be, so start with 10K and double a few times if needed - n := 10_000 - var trace []byte - for range 5 { - trace = make([]byte, n) - bytesWritten := runtime.Stack(trace, false) - if bytesWritten < len(trace) { - trace = trace[:bytesWritten] - break - } - n *= 2 - } - return string(trace) -} - func SkipIfMissing(t *testing.T, vars ...string) { t.Helper() anyMatches := false diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go index ab5128207..06b7c72f5 100644 --- a/pkg/auth/auth.go +++ b/pkg/auth/auth.go @@ -11,6 +11,7 @@ import ( "github.com/netapp/harvest/v2/cmd/poller/options" "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/errs" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/third_party/mergo" "gopkg.in/yaml.v3" "log/slog" @@ -132,7 +133,7 @@ func (c *Credentials) execScript(cmdPath string, kind string, timeout string, e response := ScriptResponse{} lookPath, err := exec.LookPath(cmdPath) if err != nil { - c.logger.Debug("Failed to find script", slog.Any("err", err), slog.String("script", cmdPath), slog.String("kind", kind)) + c.logger.Debug("Failed to find script", slogx.Err(err), slog.String("script", cmdPath), slog.String("kind", kind)) // Don't return the error, err, since it may contain credentials return response, fmt.Errorf("script lookup failed kind=%s", kind) } @@ -168,7 +169,7 @@ func (c *Credentials) execScript(cmdPath string, kind string, timeout string, e if err != nil { c.logger.Error( "Failed to start script", - slog.Any("err", err), + slogx.Err(err), slog.String("script", lookPath), slog.String("timeout", duration.String()), slog.String("kind", kind), @@ -179,7 +180,7 @@ func (c *Credentials) execScript(cmdPath string, kind string, timeout string, e if err != nil { c.logger.Error( "Failed to execute script", - slog.Any("err", err), + slogx.Err(err), slog.String("script", lookPath), slog.String("timeout", duration.String()), slog.String("kind", kind), @@ -192,7 +193,7 @@ func (c *Credentials) execScript(cmdPath string, kind string, timeout string, e // Log the error but do not return it, we will try to use the output as plain text next. c.logger.Debug( "Failed to parse YAML output. Treating as plain text.", - slog.Any("err", err), + slogx.Err(err), slog.String("script", lookPath), slog.String("timeout", duration.String()), slog.String("kind", kind), @@ -223,7 +224,7 @@ func (c *Credentials) setNextUpdate() { if err != nil { c.logger.Error( "Failed to parse schedule. Using default", - slog.Any("err", err), + slogx.Err(err), slog.String("schedule", schedule), slog.String("default", defaultSchedule), ) @@ -272,7 +273,7 @@ func (a PollerAuth) loadCertPool(logger *slog.Logger) *x509.CertPool { if err != nil { logger.Error( "Failed to read CA certificate. Use host's root CA set.", - slog.Any("err", err), + slogx.Err(err), slog.String("caCertPath", a.CaCertPath), ) return nil diff --git a/pkg/slogx/logs.go b/pkg/slogx/logs.go new file mode 100644 index 000000000..972bdf63a --- /dev/null +++ b/pkg/slogx/logs.go @@ -0,0 +1,7 @@ +package slogx + +import "log/slog" + +func Err(err error) slog.Attr { + return slog.Any("error", err) +} diff --git a/pkg/util/util.go b/pkg/util/util.go index f291658b8..7356ea96e 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -7,6 +7,7 @@ package util import ( "errors" "fmt" + "github.com/netapp/harvest/v2/pkg/slogx" "github.com/netapp/harvest/v2/third_party/go-version" "github.com/shirou/gopsutil/v4/process" "golang.org/x/sys/unix" @@ -154,7 +155,7 @@ func CheckCert(certPath string, name string, configPath string, logger *slog.Log absPath := certPath if _, err := os.Stat(absPath); err != nil { logger.Error("TLS is enabled but cert path is invalid", - slog.Any("err", err), + slogx.Err(err), slog.String("config", configPath), slog.String(name, certPath), )