diff --git a/cmd/collectors/commonutils.go b/cmd/collectors/commonutils.go index 672c1ee89..52b311cb5 100644 --- a/cmd/collectors/commonutils.go +++ b/cmd/collectors/commonutils.go @@ -1,6 +1,7 @@ package collectors import ( + "fmt" "github.com/netapp/harvest/v2/cmd/tools/rest" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" @@ -60,7 +61,7 @@ func IsEmbedShelf(model string, moduleType string) bool { return combinations[embedShelf{model, moduleType}] } -func InvokeRestCallWithTestFile(client *rest.Client, href string, logger *slog.Logger, testFilePath string) ([]gjson.Result, error) { +func InvokeRestCallWithTestFile(client *rest.Client, href string, testFilePath string) ([]gjson.Result, error) { if testFilePath != "" { b, err := os.ReadFile(testFilePath) if err != nil { @@ -69,19 +70,13 @@ func InvokeRestCallWithTestFile(client *rest.Client, href string, logger *slog.L testData := gjson.Result{Type: gjson.JSON, Raw: string(b)} return testData.Get("records").Array(), nil } - return InvokeRestCall(client, href, logger) + return InvokeRestCall(client, href) } -func InvokeRestCall(client *rest.Client, href string, logger *slog.Logger) ([]gjson.Result, error) { +func InvokeRestCall(client *rest.Client, href string) ([]gjson.Result, error) { result, err := rest.FetchAll(client, href) if err != nil { - logger.Error( - "Failed to fetch data", - slogx.Err(err), - slog.String("href", href), - slog.Int("hrefLength", len(href)), - ) - return []gjson.Result{}, err + return []gjson.Result{}, fmt.Errorf("failed to fetchAll href=%s, hrefLength=%d err=%w", TruncateURL(href), len(href), err) } if len(result) == 0 { @@ -91,6 +86,14 @@ func InvokeRestCall(client *rest.Client, href string, logger *slog.Logger) ([]gj return result, nil } +func TruncateURL(href string) string { + indexOfQuestionMark := strings.Index(href, "?") + if indexOfQuestionMark == -1 { + return href + } + return href[:indexOfQuestionMark] + "..." +} + func GetClusterTime(client *rest.Client, returnTimeOut *int, logger *slog.Logger) (time.Time, error) { var ( err error diff --git a/cmd/collectors/rest/plugins/aggregate/aggregate.go b/cmd/collectors/rest/plugins/aggregate/aggregate.go index 3912045b3..c747c2ac7 100644 --- a/cmd/collectors/rest/plugins/aggregate/aggregate.go +++ b/cmd/collectors/rest/plugins/aggregate/aggregate.go @@ -177,5 +177,5 @@ func (a *Aggregate) getObjectStoreData() ([]gjson.Result, error) { Filter([]string{`tier_name=!" "|""`}). Build() - return collectors.InvokeRestCall(a.client, href, a.SLogger) + return collectors.InvokeRestCall(a.client, href) } diff --git a/cmd/collectors/rest/plugins/certificate/certificate.go b/cmd/collectors/rest/plugins/certificate/certificate.go index 0681f08f1..d6bf7e001 100644 --- a/cmd/collectors/rest/plugins/certificate/certificate.go +++ b/cmd/collectors/rest/plugins/certificate/certificate.go @@ -200,7 +200,7 @@ func (c *Certificate) GetAdminVserver() (string, error) { Filter([]string{"type=admin"}). Build() - if result, err = collectors.InvokeRestCall(c.client, href, c.SLogger); err != nil { + if result, err = collectors.InvokeRestCall(c.client, href); err != nil { return "", err } @@ -227,7 +227,7 @@ func (c *Certificate) GetSecuritySsl(adminSvm string) (string, error) { Filter([]string{"vserver=" + adminSvm}). Build() - if result, err = collectors.InvokeRestCall(c.client, href, c.SLogger); err != nil { + if result, err = collectors.InvokeRestCall(c.client, href); err != nil { return "", err } diff --git a/cmd/collectors/rest/plugins/health/health.go b/cmd/collectors/rest/plugins/health/health.go index df057d065..3318c8d7d 100644 --- a/cmd/collectors/rest/plugins/health/health.go +++ b/cmd/collectors/rest/plugins/health/health.go @@ -720,7 +720,7 @@ func (h *Health) getDisks() ([]gjson.Result, error) { Filter([]string{"container_type=broken|unassigned"}). Build() - return collectors.InvokeRestCall(h.client, href, h.SLogger) + return collectors.InvokeRestCall(h.client, href) } func (h *Health) getShelves() ([]gjson.Result, error) { @@ -732,7 +732,7 @@ func (h *Health) getShelves() ([]gjson.Result, error) { MaxRecords(collectors.DefaultBatchSize). Build() - return collectors.InvokeRestCall(h.client, href, h.SLogger) + return collectors.InvokeRestCall(h.client, href) } func (h *Health) getNodes() ([]gjson.Result, error) { @@ -745,7 +745,7 @@ func (h *Health) getNodes() ([]gjson.Result, error) { Filter([]string{"health=false"}). Build() - return collectors.InvokeRestCall(h.client, href, h.SLogger) + return collectors.InvokeRestCall(h.client, href) } func (h *Health) getHADown() ([]gjson.Result, error) { @@ -758,7 +758,7 @@ func (h *Health) getHADown() ([]gjson.Result, error) { Filter([]string{"possible=!true"}). Build() - return collectors.InvokeRestCall(h.client, href, h.SLogger) + return collectors.InvokeRestCall(h.client, href) } func (h *Health) getRansomwareVolumes() ([]gjson.Result, error) { @@ -769,7 +769,7 @@ func (h *Health) getRansomwareVolumes() ([]gjson.Result, error) { Filter([]string{"anti_ransomware.state=enabled", "anti_ransomware.attack_probability=low|moderate|high"}). Build() - return collectors.InvokeRestCall(h.client, href, h.SLogger) + return collectors.InvokeRestCall(h.client, href) } func (h *Health) getNonCompliantLicense() ([]gjson.Result, error) { @@ -782,7 +782,7 @@ func (h *Health) getNonCompliantLicense() ([]gjson.Result, error) { Filter([]string{"state=noncompliant"}). Build() - return collectors.InvokeRestCall(h.client, href, h.SLogger) + return collectors.InvokeRestCall(h.client, href) } func (h *Health) getMoveFailedVolumes() ([]gjson.Result, error) { @@ -795,7 +795,7 @@ func (h *Health) getMoveFailedVolumes() ([]gjson.Result, error) { Filter([]string{"movement.state=cutover_wait|failed|cutover_pending"}). Build() - return collectors.InvokeRestCall(h.client, href, h.SLogger) + return collectors.InvokeRestCall(h.client, href) } func (h *Health) getNonHomeLIFs() ([]gjson.Result, error) { @@ -807,7 +807,7 @@ func (h *Health) getNonHomeLIFs() ([]gjson.Result, error) { Filter([]string{"location.is_home=false"}). Build() - return collectors.InvokeRestCall(h.client, href, h.SLogger) + return collectors.InvokeRestCall(h.client, href) } func (h *Health) getFCPorts() ([]gjson.Result, error) { @@ -820,7 +820,7 @@ func (h *Health) getFCPorts() ([]gjson.Result, error) { Filter([]string{"enabled=true", "state=offlined_by_system"}). Build() - return collectors.InvokeRestCall(h.client, href, h.SLogger) + return collectors.InvokeRestCall(h.client, href) } func (h *Health) getEthernetPorts() ([]gjson.Result, error) { @@ -833,7 +833,7 @@ func (h *Health) getEthernetPorts() ([]gjson.Result, error) { Filter([]string{"enabled=true", "state=down"}). Build() - return collectors.InvokeRestCall(h.client, href, h.SLogger) + return collectors.InvokeRestCall(h.client, href) } func (h *Health) getEmsAlerts() ([]gjson.Result, error) { @@ -853,7 +853,7 @@ func (h *Health) getEmsAlerts() ([]gjson.Result, error) { Filter([]string{timeFilter, severityFilter}). Build() - return collectors.InvokeRestCall(h.client, href, h.SLogger) + return collectors.InvokeRestCall(h.client, href) } func (h *Health) getSupportAlerts(filter []string) ([]gjson.Result, error) { @@ -864,7 +864,7 @@ func (h *Health) getSupportAlerts(filter []string) ([]gjson.Result, error) { Filter(filter). Build() - return collectors.InvokeRestCall(h.client, href, h.SLogger) + return collectors.InvokeRestCall(h.client, href) } // returns time filter (clustertime - polldata duration) diff --git a/cmd/collectors/rest/plugins/ontaps3service/ontaps3service.go b/cmd/collectors/rest/plugins/ontaps3service/ontaps3service.go index 18884de95..cc1555472 100644 --- a/cmd/collectors/rest/plugins/ontaps3service/ontaps3service.go +++ b/cmd/collectors/rest/plugins/ontaps3service/ontaps3service.go @@ -77,7 +77,7 @@ func (o *OntapS3Service) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matri MaxRecords(collectors.DefaultBatchSize). Build() - if result, err = collectors.InvokeRestCall(o.client, href, o.SLogger); err != nil { + if result, err = collectors.InvokeRestCall(o.client, href); err != nil { return nil, nil, err } diff --git a/cmd/collectors/rest/plugins/securityaccount/securityaccount.go b/cmd/collectors/rest/plugins/securityaccount/securityaccount.go index e8cd71767..b0dd58fc8 100644 --- a/cmd/collectors/rest/plugins/securityaccount/securityaccount.go +++ b/cmd/collectors/rest/plugins/securityaccount/securityaccount.go @@ -70,7 +70,7 @@ func (s *SecurityAccount) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matr Build() s.client.Metadata.Reset() - if result, err = collectors.InvokeRestCall(s.client, href, s.SLogger); err != nil { + if result, err = collectors.InvokeRestCall(s.client, href); err != nil { return nil, nil, err } diff --git a/cmd/collectors/rest/plugins/svm/svm.go b/cmd/collectors/rest/plugins/svm/svm.go index ec79a02d6..d05887b93 100644 --- a/cmd/collectors/rest/plugins/svm/svm.go +++ b/cmd/collectors/rest/plugins/svm/svm.go @@ -219,7 +219,7 @@ func (s *SVM) GetKerberosConfig() (map[string]string, error) { MaxRecords(collectors.DefaultBatchSize). Build() - if result, err = collectors.InvokeRestCall(s.client, href, s.SLogger); err != nil { + if result, err = collectors.InvokeRestCall(s.client, href); err != nil { return nil, err } @@ -253,7 +253,7 @@ func (s *SVM) GetFpolicy() (map[string]Fpolicy, error) { MaxRecords(collectors.DefaultBatchSize). Build() - if result, err = collectors.InvokeRestCall(s.client, href, s.SLogger); err != nil { + if result, err = collectors.InvokeRestCall(s.client, href); err != nil { return nil, err } @@ -288,7 +288,7 @@ func (s *SVM) GetIscsiServices() (map[string]string, error) { MaxRecords(collectors.DefaultBatchSize). Build() - if result, err = collectors.InvokeRestCall(s.client, href, s.SLogger); err != nil { + if result, err = collectors.InvokeRestCall(s.client, href); err != nil { return nil, err } @@ -322,7 +322,7 @@ func (s *SVM) GetIscsiCredentials() (map[string]string, error) { MaxRecords(collectors.DefaultBatchSize). Build() - if result, err = collectors.InvokeRestCall(s.client, href, s.SLogger); err != nil { + if result, err = collectors.InvokeRestCall(s.client, href); err != nil { return nil, err } diff --git a/cmd/collectors/rest/plugins/volume/volume.go b/cmd/collectors/rest/plugins/volume/volume.go index d5b42a9f1..60332ea94 100644 --- a/cmd/collectors/rest/plugins/volume/volume.go +++ b/cmd/collectors/rest/plugins/volume/volume.go @@ -282,7 +282,7 @@ func (v *Volume) getEncryptedDisks() ([]gjson.Result, error) { Filter([]string{"protection_mode=!data|full"}). Build() - if result, err = collectors.InvokeRestCall(v.client, href, v.SLogger); err != nil { + if result, err = collectors.InvokeRestCall(v.client, href); err != nil { return nil, err } return result, nil @@ -319,7 +319,7 @@ func (v *Volume) getVolume(field string, fields []string, volumeMap map[string]v Filter([]string{field}). Build() - if result, err = collectors.InvokeRestCall(v.client, href, v.SLogger); err != nil { + if result, err = collectors.InvokeRestCall(v.client, href); err != nil { return nil, err } diff --git a/cmd/collectors/rest/rest_test.go b/cmd/collectors/rest/rest_test.go index b4b4373dc..bb23d1db7 100644 --- a/cmd/collectors/rest/rest_test.go +++ b/cmd/collectors/rest/rest_test.go @@ -353,7 +353,7 @@ func TestFields(t *testing.T) { func TestQuotas(t *testing.T) { r := newRest("Quota", "quota.yaml", "../../../conf") var instanceKeys []string - result, err := collectors.InvokeRestCallWithTestFile(r.Client, "", r.Logger, "testdata/quota.json") + result, err := collectors.InvokeRestCallWithTestFile(r.Client, "", "testdata/quota.json") if err != nil { t.Errorf("Error while invoking quota rest api call") } diff --git a/cmd/collectors/restperf/plugins/nic/nic.go b/cmd/collectors/restperf/plugins/nic/nic.go index 107268c63..33d2a687c 100644 --- a/cmd/collectors/restperf/plugins/nic/nic.go +++ b/cmd/collectors/restperf/plugins/nic/nic.go @@ -241,7 +241,7 @@ func (n *Nic) getIfgroupInfo() map[string]string { MaxRecords(collectors.DefaultBatchSize). Build() - if ifgroupsData, err = collectors.InvokeRestCallWithTestFile(n.client, href, n.SLogger, n.testFilePath); err != nil { + if ifgroupsData, err = collectors.InvokeRestCallWithTestFile(n.client, href, n.testFilePath); err != nil { return portIfgroupMap } diff --git a/cmd/collectors/restperf/plugins/volumetopclients/volumetopclients.go b/cmd/collectors/restperf/plugins/volumetopclients/volumetopclients.go index 1e9f176d3..082de6e12 100644 --- a/cmd/collectors/restperf/plugins/volumetopclients/volumetopclients.go +++ b/cmd/collectors/restperf/plugins/volumetopclients/volumetopclients.go @@ -367,7 +367,7 @@ func (t *TopClients) fetchVolumesWithActivityTrackingEnabled() (*set.Set, error) Filter([]string{"activity_tracking.state=on"}). Build() - if result, err = collectors.InvokeRestCall(t.client, href, t.SLogger); err != nil { + if result, err = collectors.InvokeRestCall(t.client, href); err != nil { return va, err } @@ -395,7 +395,7 @@ func (t *TopClients) fetchTopClients(volumes *set.Set, svms *set.Set, metric str Filter([]string{"top_metric=" + metric, "volume=" + strings.Join(volumes.Values(), "|"), "svm=" + strings.Join(svms.Values(), "|")}). Build() - if result, err = collectors.InvokeRestCall(t.client, href, t.SLogger); err != nil { + if result, err = collectors.InvokeRestCall(t.client, href); err != nil { return result, err } diff --git a/cmd/collectors/restperf/plugins/volumetopclients/volumetopclients_test.go b/cmd/collectors/restperf/plugins/volumetopclients/volumetopclients_test.go index 1c1565a86..a8ff51af3 100644 --- a/cmd/collectors/restperf/plugins/volumetopclients/volumetopclients_test.go +++ b/cmd/collectors/restperf/plugins/volumetopclients/volumetopclients_test.go @@ -18,7 +18,7 @@ type MockVolume struct { } func (mv *MockVolume) fetchTopClients(_ *set.Set, _ *set.Set, _ string) ([]gjson.Result, error) { - return collectors.InvokeRestCallWithTestFile(nil, "", nil, mv.testFilePath) + return collectors.InvokeRestCallWithTestFile(nil, "", mv.testFilePath) } func (mv *MockVolume) fetchVolumesWithActivityTrackingEnabled() (*set.Set, error) { diff --git a/cmd/collectors/restperf/restperf.go b/cmd/collectors/restperf/restperf.go index f7956d02a..99677926f 100644 --- a/cmd/collectors/restperf/restperf.go +++ b/cmd/collectors/restperf/restperf.go @@ -3,6 +3,7 @@ package restperf import ( "context" "fmt" + "github.com/netapp/harvest/v2/cmd/collectors" rest2 "github.com/netapp/harvest/v2/cmd/collectors/rest" "github.com/netapp/harvest/v2/cmd/collectors/restperf/plugins/disk" "github.com/netapp/harvest/v2/cmd/collectors/restperf/plugins/fabricpool" @@ -1624,9 +1625,13 @@ func (r *RestPerf) updateQosLabels(qos gjson.Result, instance *matrix.Instance, func (r *RestPerf) handleError(err error, href string) (map[string]*matrix.Matrix, error) { if errs.IsRestErr(err, errs.TableNotFound) || errs.IsRestErr(err, errs.APINotFound) { // the table or API does not exist. return ErrAPIRequestRejected so the task goes to stand-by - return nil, fmt.Errorf("polling href=[%s] err: %w", href, errs.New(errs.ErrAPIRequestRejected, err.Error())) + return nil, fmt.Errorf( + "polling href=[%s] err: %w", + collectors.TruncateURL(href), + errs.New(errs.ErrAPIRequestRejected, err.Error()), + ) } - return nil, fmt.Errorf("failed to fetch data. href=[%s] err: %w", href, err) + return nil, fmt.Errorf("failed to fetch data. href=[%s] err: %w", collectors.TruncateURL(href), err) } func (r *RestPerf) InitSchedule() { diff --git a/integration/test/counter_test.go b/integration/test/counter_test.go index c17f608a7..311f12955 100644 --- a/integration/test/counter_test.go +++ b/integration/test/counter_test.go @@ -92,7 +92,7 @@ func invokeRestCall(client *rest2.Client, counters map[string][]counterData) err CounterSchema(counterDetail.perfCounters). Build() - if _, err := collectors.InvokeRestCall(client, href, slog.Default()); err != nil { + if _, err := collectors.InvokeRestCall(client, href); err != nil { return fmt.Errorf("failed to invoke rest href=%s call: %w", href, err) } }