diff --git a/app/vlinsert/elasticsearch/elasticsearch_test.go b/app/vlinsert/elasticsearch/elasticsearch_test.go index 09d1bf770..e5169f246 100644 --- a/app/vlinsert/elasticsearch/elasticsearch_test.go +++ b/app/vlinsert/elasticsearch/elasticsearch_test.go @@ -120,10 +120,10 @@ func compressData(s string) string { var bb bytes.Buffer zw := gzip.NewWriter(&bb) if _, err := zw.Write([]byte(s)); err != nil { - panic(fmt.Errorf("unexpected error when compressing data: %s", err)) + panic(fmt.Errorf("unexpected error when compressing data: %w", err)) } if err := zw.Close(); err != nil { - panic(fmt.Errorf("unexpected error when closing gzip writer: %s", err)) + panic(fmt.Errorf("unexpected error when closing gzip writer: %w", err)) } return bb.String() } diff --git a/app/vlinsert/elasticsearch/elasticsearch_timing_test.go b/app/vlinsert/elasticsearch/elasticsearch_timing_test.go index 9a50fe0eb..1c4de3cb4 100644 --- a/app/vlinsert/elasticsearch/elasticsearch_timing_test.go +++ b/app/vlinsert/elasticsearch/elasticsearch_timing_test.go @@ -43,7 +43,7 @@ func benchmarkReadBulkRequest(b *testing.B, isGzip bool) { r.Reset(dataBytes) _, err := readBulkRequest(r, isGzip, timeField, msgField, processLogMessage) if err != nil { - panic(fmt.Errorf("unexpected error: %s", err)) + panic(fmt.Errorf("unexpected error: %w", err)) } } }) diff --git a/app/vlinsert/loki/loki_json_timing_test.go b/app/vlinsert/loki/loki_json_timing_test.go index 9c51f593a..af7c29697 100644 --- a/app/vlinsert/loki/loki_json_timing_test.go +++ b/app/vlinsert/loki/loki_json_timing_test.go @@ -29,7 +29,7 @@ func benchmarkParseJSONRequest(b *testing.B, streams, rows, labels int) { for pb.Next() { _, err := parseJSONRequest(data, func(timestamp int64, fields []logstorage.Field) {}) if err != nil { - panic(fmt.Errorf("unexpected error: %s", err)) + panic(fmt.Errorf("unexpected error: %w", err)) } } }) diff --git a/app/vlinsert/loki/loki_protobuf.go b/app/vlinsert/loki/loki_protobuf.go index af489329b..fe171e6d4 100644 --- a/app/vlinsert/loki/loki_protobuf.go +++ b/app/vlinsert/loki/loki_protobuf.go @@ -84,7 +84,7 @@ func parseProtobufRequest(data []byte, processLogMessage func(timestamp int64, f err = req.Unmarshal(bb.B) if err != nil { - return 0, fmt.Errorf("cannot parse request body: %s", err) + return 0, fmt.Errorf("cannot parse request body: %w", err) } var commonFields []logstorage.Field @@ -97,7 +97,7 @@ func parseProtobufRequest(data []byte, processLogMessage func(timestamp int64, f // Labels are same for all entries in the stream. commonFields, err = parsePromLabels(commonFields[:0], stream.Labels) if err != nil { - return rowsIngested, fmt.Errorf("cannot parse stream labels %q: %s", stream.Labels, err) + return rowsIngested, fmt.Errorf("cannot parse stream labels %q: %w", stream.Labels, err) } fields := commonFields diff --git a/app/vlinsert/loki/loki_protobuf_timing_test.go b/app/vlinsert/loki/loki_protobuf_timing_test.go index 1b7cbd647..1e4d16048 100644 --- a/app/vlinsert/loki/loki_protobuf_timing_test.go +++ b/app/vlinsert/loki/loki_protobuf_timing_test.go @@ -31,7 +31,7 @@ func benchmarkParseProtobufRequest(b *testing.B, streams, rows, labels int) { for pb.Next() { _, err := parseProtobufRequest(body, func(timestamp int64, fields []logstorage.Field) {}) if err != nil { - panic(fmt.Errorf("unexpected error: %s", err)) + panic(fmt.Errorf("unexpected error: %w", err)) } } }) diff --git a/app/vmalert/config/config.go b/app/vmalert/config/config.go index da02b4de4..4d8232d06 100644 --- a/app/vmalert/config/config.go +++ b/app/vmalert/config/config.go @@ -236,7 +236,7 @@ func ParseSilent(pathPatterns []string, validateTplFn ValidateTplFn, validateExp files, err := readFromFS(pathPatterns) if err != nil { - return nil, fmt.Errorf("failed to read from the config: %s", err) + return nil, fmt.Errorf("failed to read from the config: %w", err) } return parse(files, validateTplFn, validateExpressions) } @@ -245,11 +245,11 @@ func ParseSilent(pathPatterns []string, validateTplFn ValidateTplFn, validateExp func Parse(pathPatterns []string, validateTplFn ValidateTplFn, validateExpressions bool) ([]Group, error) { files, err := readFromFS(pathPatterns) if err != nil { - return nil, fmt.Errorf("failed to read from the config: %s", err) + return nil, fmt.Errorf("failed to read from the config: %w", err) } groups, err := parse(files, validateTplFn, validateExpressions) if err != nil { - return nil, fmt.Errorf("failed to parse %s: %s", pathPatterns, err) + return nil, fmt.Errorf("failed to parse %s: %w", pathPatterns, err) } if len(groups) < 1 { cLogger.Warnf("no groups found in %s", strings.Join(pathPatterns, ";")) diff --git a/app/vmalert/config/fsurl/url.go b/app/vmalert/config/fsurl/url.go index 6cb99ee73..fe6701479 100644 --- a/app/vmalert/config/fsurl/url.go +++ b/app/vmalert/config/fsurl/url.go @@ -49,7 +49,7 @@ func (fs *FS) Read(files []string) (map[string][]byte, error) { path, resp.StatusCode, http.StatusOK, data) } if err != nil { - return nil, fmt.Errorf("cannot read %q: %s", path, err) + return nil, fmt.Errorf("cannot read %q: %w", path, err) } result[path] = data } diff --git a/app/vmalert/datasource/init.go b/app/vmalert/datasource/init.go index 1cd5dcb78..92433433e 100644 --- a/app/vmalert/datasource/init.go +++ b/app/vmalert/datasource/init.go @@ -117,7 +117,7 @@ func Init(extraParams url.Values) (QuerierBuilder, error) { } _, err = authCfg.GetAuthHeader() if err != nil { - return nil, fmt.Errorf("failed to set request auth header to datasource %q: %s", *addr, err) + return nil, fmt.Errorf("failed to set request auth header to datasource %q: %w", *addr, err) } return &VMStorage{ diff --git a/app/vmalert/datasource/vm.go b/app/vmalert/datasource/vm.go index a4c9a9a07..0fa384d75 100644 --- a/app/vmalert/datasource/vm.go +++ b/app/vmalert/datasource/vm.go @@ -219,7 +219,7 @@ func (s *VMStorage) do(ctx context.Context, req *http.Request) (*http.Response, func (s *VMStorage) newQueryRangeRequest(query string, start, end time.Time) (*http.Request, error) { req, err := s.newRequest() if err != nil { - return nil, fmt.Errorf("cannot create query_range request to datasource %q: %s", s.datasourceURL, err) + return nil, fmt.Errorf("cannot create query_range request to datasource %q: %w", s.datasourceURL, err) } s.setPrometheusRangeReqParams(req, query, start, end) return req, nil @@ -228,7 +228,7 @@ func (s *VMStorage) newQueryRangeRequest(query string, start, end time.Time) (*h func (s *VMStorage) newQueryRequest(query string, ts time.Time) (*http.Request, error) { req, err := s.newRequest() if err != nil { - return nil, fmt.Errorf("cannot create query request to datasource %q: %s", s.datasourceURL, err) + return nil, fmt.Errorf("cannot create query request to datasource %q: %w", s.datasourceURL, err) } switch s.dataSourceType { case "", datasourcePrometheus: diff --git a/app/vmalert/datasource/vm_prom_api.go b/app/vmalert/datasource/vm_prom_api.go index 3e68bd009..b968aa667 100644 --- a/app/vmalert/datasource/vm_prom_api.go +++ b/app/vmalert/datasource/vm_prom_api.go @@ -112,14 +112,14 @@ func parsePrometheusResponse(req *http.Request, resp *http.Response) (res Result return res, fmt.Errorf("response error, query: %s, errorType: %s, error: %s", req.URL.Redacted(), r.ErrorType, r.Error) } if r.Status != statusSuccess { - return res, fmt.Errorf("unknown status: %s, Expected success or error ", r.Status) + return res, fmt.Errorf("unknown status: %s, Expected success or error", r.Status) } var parseFn func() ([]Metric, error) switch r.Data.ResultType { case rtVector: var pi promInstant if err := json.Unmarshal(r.Data.Result, &pi.Result); err != nil { - return res, fmt.Errorf("umarshal err %s; \n %#v", err, string(r.Data.Result)) + return res, fmt.Errorf("unmarshal err %w; \n %#v", err, string(r.Data.Result)) } parseFn = pi.metrics case rtMatrix: diff --git a/app/vmalert/notifier/config_watcher.go b/app/vmalert/notifier/config_watcher.go index 1172152a4..3189cb55a 100644 --- a/app/vmalert/notifier/config_watcher.go +++ b/app/vmalert/notifier/config_watcher.go @@ -87,7 +87,7 @@ func (cw *configWatcher) reload(path string) error { func (cw *configWatcher) add(typeK TargetType, interval time.Duration, labelsFn getLabels) error { targets, errors := targetsFromLabels(labelsFn, cw.cfg, cw.genFn) for _, err := range errors { - return fmt.Errorf("failed to init notifier for %q: %s", typeK, err) + return fmt.Errorf("failed to init notifier for %q: %w", typeK, err) } cw.setTargets(typeK, targets) @@ -107,7 +107,7 @@ func (cw *configWatcher) add(typeK TargetType, interval time.Duration, labelsFn } updateTargets, errors := targetsFromLabels(labelsFn, cw.cfg, cw.genFn) for _, err := range errors { - logger.Errorf("failed to init notifier for %q: %s", typeK, err) + logger.Errorf("failed to init notifier for %q: %w", typeK, err) } cw.setTargets(typeK, updateTargets) } @@ -118,7 +118,7 @@ func (cw *configWatcher) add(typeK TargetType, interval time.Duration, labelsFn func targetsFromLabels(labelsFn getLabels, cfg *Config, genFn AlertURLGenerator) ([]Target, []error) { metaLabels, err := labelsFn() if err != nil { - return nil, []error{fmt.Errorf("failed to get labels: %s", err)} + return nil, []error{fmt.Errorf("failed to get labels: %w", err)} } var targets []Target var errors []error @@ -167,11 +167,11 @@ func (cw *configWatcher) start() error { for _, target := range cfg.Targets { address, labels, err := parseLabels(target, nil, cw.cfg) if err != nil { - return fmt.Errorf("failed to parse labels for target %q: %s", target, err) + return fmt.Errorf("failed to parse labels for target %q: %w", target, err) } notifier, err := NewAlertManager(address, cw.genFn, httpCfg, cw.cfg.parsedAlertRelabelConfigs, cw.cfg.Timeout.Duration()) if err != nil { - return fmt.Errorf("failed to init alertmanager for addr %q: %s", address, err) + return fmt.Errorf("failed to init alertmanager for addr %q: %w", address, err) } targets = append(targets, Target{ Notifier: notifier, @@ -189,14 +189,14 @@ func (cw *configWatcher) start() error { sdc := &cw.cfg.ConsulSDConfigs[i] targetLabels, err := sdc.GetLabels(cw.cfg.baseDir) if err != nil { - return nil, fmt.Errorf("got labels err: %s", err) + return nil, fmt.Errorf("got labels err: %w", err) } labels = append(labels, targetLabels...) } return labels, nil }) if err != nil { - return fmt.Errorf("failed to start consulSD discovery: %s", err) + return fmt.Errorf("failed to start consulSD discovery: %w", err) } } @@ -207,14 +207,14 @@ func (cw *configWatcher) start() error { sdc := &cw.cfg.DNSSDConfigs[i] targetLabels, err := sdc.GetLabels(cw.cfg.baseDir) if err != nil { - return nil, fmt.Errorf("got labels err: %s", err) + return nil, fmt.Errorf("got labels err: %w", err) } labels = append(labels, targetLabels...) } return labels, nil }) if err != nil { - return fmt.Errorf("failed to start DNSSD discovery: %s", err) + return fmt.Errorf("failed to start DNSSD discovery: %w", err) } } return nil diff --git a/app/vmalert/notifier/init.go b/app/vmalert/notifier/init.go index dc4a6e4e7..f1e5cabca 100644 --- a/app/vmalert/notifier/init.go +++ b/app/vmalert/notifier/init.go @@ -90,7 +90,7 @@ func Init(gen AlertURLGenerator, extLabels map[string]string, extURL string) (fu externalLabels = extLabels eu, err := url.Parse(externalURL) if err != nil { - return nil, fmt.Errorf("failed to parse external URL: %s", err) + return nil, fmt.Errorf("failed to parse external URL: %w", err) } templates.UpdateWithFuncs(templates.FuncsWithExternalURL(eu)) @@ -116,7 +116,7 @@ func Init(gen AlertURLGenerator, extLabels map[string]string, extURL string) (fu if len(*addrs) > 0 { notifiers, err := notifiersFromFlags(gen) if err != nil { - return nil, fmt.Errorf("failed to create notifier from flag values: %s", err) + return nil, fmt.Errorf("failed to create notifier from flag values: %w", err) } staticNotifiersFn = func() []Notifier { return notifiers @@ -126,7 +126,7 @@ func Init(gen AlertURLGenerator, extLabels map[string]string, extURL string) (fu cw, err = newWatcher(*configPath, gen) if err != nil { - return nil, fmt.Errorf("failed to init config watcher: %s", err) + return nil, fmt.Errorf("failed to init config watcher: %w", err) } return cw.notifiers, nil } diff --git a/app/vmalert/replay.go b/app/vmalert/replay.go index 1e4654c7d..ca85a72f9 100644 --- a/app/vmalert/replay.go +++ b/app/vmalert/replay.go @@ -36,11 +36,11 @@ func replay(groupsCfg []config.Group, qb datasource.QuerierBuilder, rw remotewri } tFrom, err := time.Parse(time.RFC3339, *replayFrom) if err != nil { - return fmt.Errorf("failed to parse %q: %s", *replayFrom, err) + return fmt.Errorf("failed to parse %q: %w", *replayFrom, err) } tTo, err := time.Parse(time.RFC3339, *replayTo) if err != nil { - return fmt.Errorf("failed to parse %q: %s", *replayTo, err) + return fmt.Errorf("failed to parse %q: %w", *replayTo, err) } if !tTo.After(tFrom) { return fmt.Errorf("replay.timeTo must be bigger than replay.timeFrom") diff --git a/app/vmalert/rule/alerting.go b/app/vmalert/rule/alerting.go index a1a6e34dc..a5a2cabdb 100644 --- a/app/vmalert/rule/alerting.go +++ b/app/vmalert/rule/alerting.go @@ -269,7 +269,7 @@ func (ar *AlertingRule) toLabels(m datasource.Metric, qFn templates.QueryFn) (*l Expr: ar.Expr, }) if err != nil { - return nil, fmt.Errorf("failed to expand labels: %s", err) + return nil, fmt.Errorf("failed to expand labels: %w", err) } for k, v := range extraLabels { ls.processed[k] = v @@ -310,7 +310,7 @@ func (ar *AlertingRule) execRange(ctx context.Context, start, end time.Time) ([] for _, s := range res.Data { a, err := ar.newAlert(s, nil, time.Time{}, qFn) // initial alert if err != nil { - return nil, fmt.Errorf("failed to create alert: %s", err) + return nil, fmt.Errorf("failed to create alert: %w", err) } if ar.For == 0 { // if alert is instant a.State = notifier.StateFiring @@ -388,7 +388,7 @@ func (ar *AlertingRule) exec(ctx context.Context, ts time.Time, limit int) ([]pr for _, m := range res.Data { ls, err := ar.toLabels(m, qFn) if err != nil { - curState.Err = fmt.Errorf("failed to expand labels: %s", err) + curState.Err = fmt.Errorf("failed to expand labels: %w", err) return nil, curState.Err } h := hash(ls.processed) @@ -513,7 +513,7 @@ func (ar *AlertingRule) newAlert(m datasource.Metric, ls *labelSet, start time.T if ls == nil { ls, err = ar.toLabels(m, qFn) if err != nil { - return nil, fmt.Errorf("failed to expand labels: %s", err) + return nil, fmt.Errorf("failed to expand labels: %w", err) } } a := ¬ifier.Alert{ diff --git a/app/vmalert/rule/rule.go b/app/vmalert/rule/rule.go index 6240fb430..10728cff6 100644 --- a/app/vmalert/rule/rule.go +++ b/app/vmalert/rule/rule.go @@ -166,7 +166,7 @@ func replayRule(r Rule, start, end time.Time, rw remotewrite.RWClient, replayRul var n int for _, ts := range tss { if err := rw.Push(ts); err != nil { - return n, fmt.Errorf("remote write failure: %s", err) + return n, fmt.Errorf("remote write failure: %w", err) } n += len(ts.Samples) } diff --git a/app/vmalert/web.go b/app/vmalert/web.go index b93ebc067..f34bad197 100644 --- a/app/vmalert/web.go +++ b/app/vmalert/web.go @@ -147,11 +147,11 @@ func (rh *requestHandler) handler(w http.ResponseWriter, r *http.Request) bool { func (rh *requestHandler) getRule(r *http.Request) (apiRule, error) { groupID, err := strconv.ParseUint(r.FormValue(paramGroupID), 10, 64) if err != nil { - return apiRule{}, fmt.Errorf("failed to read %q param: %s", paramGroupID, err) + return apiRule{}, fmt.Errorf("failed to read %q param: %w", paramGroupID, err) } ruleID, err := strconv.ParseUint(r.FormValue(paramRuleID), 10, 64) if err != nil { - return apiRule{}, fmt.Errorf("failed to read %q param: %s", paramRuleID, err) + return apiRule{}, fmt.Errorf("failed to read %q param: %w", paramRuleID, err) } obj, err := rh.m.ruleAPI(groupID, ruleID) if err != nil { @@ -163,11 +163,11 @@ func (rh *requestHandler) getRule(r *http.Request) (apiRule, error) { func (rh *requestHandler) getAlert(r *http.Request) (*apiAlert, error) { groupID, err := strconv.ParseUint(r.FormValue(paramGroupID), 10, 64) if err != nil { - return nil, fmt.Errorf("failed to read %q param: %s", paramGroupID, err) + return nil, fmt.Errorf("failed to read %q param: %w", paramGroupID, err) } alertID, err := strconv.ParseUint(r.FormValue(paramAlertID), 10, 64) if err != nil { - return nil, fmt.Errorf("failed to read %q param: %s", paramAlertID, err) + return nil, fmt.Errorf("failed to read %q param: %w", paramAlertID, err) } a, err := rh.m.alertAPI(groupID, alertID) if err != nil { diff --git a/app/vmbackup/main.go b/app/vmbackup/main.go index 602e9275f..40c5c8bf4 100644 --- a/app/vmbackup/main.go +++ b/app/vmbackup/main.go @@ -168,7 +168,7 @@ See the docs at https://docs.victoriametrics.com/vmbackup.html . func newSrcFS() (*fslocal.FS, error) { if err := snapshot.Validate(*snapshotName); err != nil { - return nil, fmt.Errorf("invalid -snapshotName=%q: %s", *snapshotName, err) + return nil, fmt.Errorf("invalid -snapshotName=%q: %w", *snapshotName, err) } snapshotPath := filepath.Join(*storageDataPath, "snapshots", *snapshotName) diff --git a/app/vmselect/graphite/functions_api.go b/app/vmselect/graphite/functions_api.go index 97932bcef..c7bb7cccc 100644 --- a/app/vmselect/graphite/functions_api.go +++ b/app/vmselect/graphite/functions_api.go @@ -81,7 +81,7 @@ var funcs = func() map[string]*funcInfo { var m map[string]*funcInfo if err := json.Unmarshal(funcsJSON, &m); err != nil { // Do not use logger.Panicf, since it isn't ready yet. - panic(fmt.Errorf("cannot parse funcsJSON: %s", err)) + panic(fmt.Errorf("cannot parse funcsJSON: %w", err)) } return m }() diff --git a/app/vmselect/prometheus/prometheus.go b/app/vmselect/prometheus/prometheus.go index f4ce705e7..a624a8ccc 100644 --- a/app/vmselect/prometheus/prometheus.go +++ b/app/vmselect/prometheus/prometheus.go @@ -197,7 +197,7 @@ func ExportCSVHandler(startTime time.Time, w http.ResponseWriter, r *http.Reques return err } if err := b.UnmarshalData(); err != nil { - return fmt.Errorf("cannot unmarshal block during export: %s", err) + return fmt.Errorf("cannot unmarshal block during export: %w", err) } xb := exportBlockPool.Get().(*exportBlock) xb.mn = mn @@ -407,7 +407,7 @@ func exportHandler(qt *querytracer.Tracer, w http.ResponseWriter, cp *commonPara return err } if err := b.UnmarshalData(); err != nil { - return fmt.Errorf("cannot unmarshal block during export: %s", err) + return fmt.Errorf("cannot unmarshal block during export: %w", err) } xb := exportBlockPool.Get().(*exportBlock) xb.mn = mn diff --git a/lib/fs/fs.go b/lib/fs/fs.go index 373c59fbd..22e5bce1d 100644 --- a/lib/fs/fs.go +++ b/lib/fs/fs.go @@ -418,7 +418,7 @@ func ReadFileOrHTTP(path string) ([]byte, error) { return nil, fmt.Errorf("unexpected status code when fetching %q: %d, expecting %d; response: %q", path, resp.StatusCode, http.StatusOK, data) } if err != nil { - return nil, fmt.Errorf("cannot read %q: %s", path, err) + return nil, fmt.Errorf("cannot read %q: %w", path, err) } return data, nil } diff --git a/lib/httpserver/httpserver.go b/lib/httpserver/httpserver.go index 75b5940e0..4d1d00042 100644 --- a/lib/httpserver/httpserver.go +++ b/lib/httpserver/httpserver.go @@ -204,7 +204,7 @@ func gzipHandler(s *server, rh RequestHandler) http.HandlerFunc { var gzipHandlerWrapper = func() func(http.Handler) http.HandlerFunc { hw, err := gzhttp.NewWrapper(gzhttp.CompressionLevel(1)) if err != nil { - panic(fmt.Errorf("BUG: cannot initialize gzip http wrapper: %s", err)) + panic(fmt.Errorf("BUG: cannot initialize gzip http wrapper: %w", err)) } return hw }() diff --git a/lib/logstorage/indexdb.go b/lib/logstorage/indexdb.go index 04a1b82f5..3504b563b 100644 --- a/lib/logstorage/indexdb.go +++ b/lib/logstorage/indexdb.go @@ -899,7 +899,7 @@ func unmarshalCommonPrefix(dstTenantID *TenantID, src []byte) ([]byte, byte, err src = src[1:] tail, err := dstTenantID.unmarshal(src) if err != nil { - return nil, 0, fmt.Errorf("cannot unmarshal tenantID: %s", err) + return nil, 0, fmt.Errorf("cannot unmarshal tenantID: %w", err) } return tail, prefix, nil } diff --git a/lib/logstorage/storage_search_test.go b/lib/logstorage/storage_search_test.go index 63404838c..98b8f902a 100644 --- a/lib/logstorage/storage_search_test.go +++ b/lib/logstorage/storage_search_test.go @@ -310,7 +310,7 @@ func TestStorageRunQuery(t *testing.T) { func mustParseQuery(query string) *Query { q, err := ParseQuery(query) if err != nil { - panic(fmt.Errorf("BUG: cannot parse %s: %s", query, err)) + panic(fmt.Errorf("BUG: cannot parse %s: %w", query, err)) } return q } @@ -657,7 +657,7 @@ func TestStorageSearch(t *testing.T) { func mustNewStreamFilter(s string) *StreamFilter { sf, err := newStreamFilter(s) if err != nil { - panic(fmt.Errorf("unexpected error in newStreamFilter(%q): %s", s, err)) + panic(fmt.Errorf("unexpected error in newStreamFilter(%q): %w", s, err)) } return sf } diff --git a/lib/netutil/proxyprotocol.go b/lib/netutil/proxyprotocol.go index e0a95c548..dedb6a028 100644 --- a/lib/netutil/proxyprotocol.go +++ b/lib/netutil/proxyprotocol.go @@ -19,7 +19,7 @@ func newProxyProtocolConn(c net.Conn) (net.Conn, error) { // Limit the time needed for reading the proxy protocol header. d := time.Now().Add(5 * time.Second) if err := c.SetReadDeadline(d); err != nil { - return nil, fmt.Errorf("cannot set deadline for reading proxy protocol header: %s", err) + return nil, fmt.Errorf("cannot set deadline for reading proxy protocol header: %w", err) } remoteAddr, err := readProxyProto(c) @@ -32,7 +32,7 @@ func newProxyProtocolConn(c net.Conn) (net.Conn, error) { // Reset the read deadline. if err := c.SetReadDeadline(time.Time{}); err != nil { - return nil, fmt.Errorf("cannot reset deadline after reading proxy protocol header: %s", err) + return nil, fmt.Errorf("cannot reset deadline after reading proxy protocol header: %w", err) } return &proxyProtocolConn{ diff --git a/lib/promauth/config.go b/lib/promauth/config.go index aac56b2b4..e52c86afa 100644 --- a/lib/promauth/config.go +++ b/lib/promauth/config.go @@ -599,7 +599,7 @@ func (actx *authContext) initFromAuthorization(baseDir string, az *Authorization actx.getAuthHeader = func() (string, error) { token, err := readPasswordFromFile(filePath) if err != nil { - return "", fmt.Errorf("cannot read credentials from `credentials_file`=%q: %s", az.CredentialsFile, err) + return "", fmt.Errorf("cannot read credentials from `credentials_file`=%q: %w", az.CredentialsFile, err) } return azType + " " + token, nil } @@ -628,7 +628,7 @@ func (actx *authContext) initFromBasicAuthConfig(baseDir string, ba *BasicAuthCo actx.getAuthHeader = func() (string, error) { password, err := readPasswordFromFile(filePath) if err != nil { - return "", fmt.Errorf("cannot read password from `password_file`=%q set in `basic_auth` section: %s", ba.PasswordFile, err) + return "", fmt.Errorf("cannot read password from `password_file`=%q set in `basic_auth` section: %w", ba.PasswordFile, err) } // See https://en.wikipedia.org/wiki/Basic_access_authentication token := ba.Username + ":" + password @@ -644,7 +644,7 @@ func (actx *authContext) initFromBearerTokenFile(baseDir string, bearerTokenFile actx.getAuthHeader = func() (string, error) { token, err := readPasswordFromFile(filePath) if err != nil { - return "", fmt.Errorf("cannot read bearer token from `bearer_token_file`=%q: %s", bearerTokenFile, err) + return "", fmt.Errorf("cannot read bearer token from `bearer_token_file`=%q: %w", bearerTokenFile, err) } return "Bearer " + token, nil } @@ -672,11 +672,11 @@ func (actx *authContext) initFromOAuth2Config(baseDir string, o *OAuth2Config) e } ts, err := oi.getTokenSource() if err != nil { - return "", fmt.Errorf("cannot get OAuth2 tokenSource: %s", err) + return "", fmt.Errorf("cannot get OAuth2 tokenSource: %w", err) } t, err := ts.Token() if err != nil { - return "", fmt.Errorf("cannot get OAuth2 token: %s", err) + return "", fmt.Errorf("cannot get OAuth2 token: %w", err) } return t.Type() + " " + t.AccessToken, nil } diff --git a/lib/promrelabel/config.go b/lib/promrelabel/config.go index 58cd4095f..137ff4b58 100644 --- a/lib/promrelabel/config.go +++ b/lib/promrelabel/config.go @@ -204,7 +204,7 @@ var ( defaultPromRegex = func() *regexutil.PromRegex { pr, err := regexutil.NewPromRegex(".*") if err != nil { - panic(fmt.Errorf("BUG: unexpected error: %s", err)) + panic(fmt.Errorf("BUG: unexpected error: %w", err)) } return pr }() diff --git a/lib/promrelabel/debug.go b/lib/promrelabel/debug.go index 956777d04..9ed0d8732 100644 --- a/lib/promrelabel/debug.go +++ b/lib/promrelabel/debug.go @@ -28,13 +28,13 @@ func writeRelabelDebug(w io.Writer, isTargetRelabel bool, targetID, metric, rela } labels, err := promutils.NewLabelsFromString(metric) if err != nil { - err = fmt.Errorf("cannot parse metric: %s", err) + err = fmt.Errorf("cannot parse metric: %w", err) WriteRelabelDebugSteps(w, targetURL, targetID, format, nil, metric, relabelConfigs, err) return } pcs, err := ParseRelabelConfigsData([]byte(relabelConfigs)) if err != nil { - err = fmt.Errorf("cannot parse relabel configs: %s", err) + err = fmt.Errorf("cannot parse relabel configs: %w", err) WriteRelabelDebugSteps(w, targetURL, targetID, format, nil, metric, relabelConfigs, err) return } diff --git a/lib/promrelabel/relabel_test.go b/lib/promrelabel/relabel_test.go index df8080af4..0f77b2607 100644 --- a/lib/promrelabel/relabel_test.go +++ b/lib/promrelabel/relabel_test.go @@ -927,7 +927,7 @@ func newTestRegexRelabelConfig(pattern string) *parsedRelabelConfig { } prc, err := parseRelabelConfig(rc) if err != nil { - panic(fmt.Errorf("unexpected error in parseRelabelConfig: %s", err)) + panic(fmt.Errorf("unexpected error in parseRelabelConfig: %w", err)) } return prc } diff --git a/lib/promscrape/client.go b/lib/promscrape/client.go index 2f7a7a31b..8c380b746 100644 --- a/lib/promscrape/client.go +++ b/lib/promscrape/client.go @@ -119,7 +119,7 @@ func newClient(ctx context.Context, sw *ScrapeWork) (*client, error) { dialAddr = addMissingPort(dialAddr, isTLS) dialFunc, err := newStatDialFunc(proxyURL, sw.ProxyAuthConfig) if err != nil { - return nil, fmt.Errorf("cannot create dial func: %s", err) + return nil, fmt.Errorf("cannot create dial func: %w", err) } hc := &fasthttp.HostClient{ Addr: dialAddr, @@ -199,12 +199,12 @@ func (c *client) GetStreamReader() (*streamReader, error) { err = c.setHeaders(req) if err != nil { cancel() - return nil, fmt.Errorf("failed to create request to %q: %s", c.scrapeURL, err) + return nil, fmt.Errorf("failed to create request to %q: %w", c.scrapeURL, err) } err = c.setProxyHeaders(req) if err != nil { cancel() - return nil, fmt.Errorf("failed to create request to %q: %s", c.scrapeURL, err) + return nil, fmt.Errorf("failed to create request to %q: %w", c.scrapeURL, err) } scrapeRequests.Inc() resp, err := c.sc.Do(req) @@ -254,11 +254,11 @@ func (c *client) ReadData(dst []byte) ([]byte, error) { req.Header.Set("X-Prometheus-Scrape-Timeout-Seconds", c.scrapeTimeoutSecondsStr) err := c.setFasthttpHeaders(req) if err != nil { - return nil, fmt.Errorf("failed to create request to %q: %s", c.scrapeURL, err) + return nil, fmt.Errorf("failed to create request to %q: %w", c.scrapeURL, err) } err = c.setFasthttpProxyHeaders(req) if err != nil { - return nil, fmt.Errorf("failed to create request to %q: %s", c.scrapeURL, err) + return nil, fmt.Errorf("failed to create request to %q: %w", c.scrapeURL, err) } if !*disableCompression && !c.disableCompression { req.Header.Set("Accept-Encoding", "gzip") diff --git a/lib/promscrape/discovery/digitalocean/digitalocean.go b/lib/promscrape/discovery/digitalocean/digitalocean.go index aa4534c58..defdb41d1 100644 --- a/lib/promscrape/discovery/digitalocean/digitalocean.go +++ b/lib/promscrape/discovery/digitalocean/digitalocean.go @@ -110,7 +110,7 @@ func (r *listDropletResponse) nextURLPath() (string, error) { } u, err := url.Parse(r.Links.Pages.Next) if err != nil { - return "", fmt.Errorf("cannot parse digital ocean next url: %s, err: %s", r.Links.Pages.Next, err) + return "", fmt.Errorf("cannot parse digital ocean next url: %s: %w", r.Links.Pages.Next, err) } return u.RequestURI(), nil } diff --git a/lib/promscrape/discovery/http/api.go b/lib/promscrape/discovery/http/api.go index 49f1dde28..5233e4801 100644 --- a/lib/promscrape/discovery/http/api.go +++ b/lib/promscrape/discovery/http/api.go @@ -85,7 +85,7 @@ func getHTTPTargets(cfg *apiConfig) ([]httpGroupTarget, error) { func parseAPIResponse(data []byte, path string) ([]httpGroupTarget, error) { var r []httpGroupTarget if err := json.Unmarshal(data, &r); err != nil { - return nil, fmt.Errorf("cannot parse http_sd api response path: %s, err: %w", path, err) + return nil, fmt.Errorf("cannot parse http_sd api response path=%q: %w", path, err) } return r, nil } diff --git a/lib/promscrape/discovery/kubernetes/pod_timing_test.go b/lib/promscrape/discovery/kubernetes/pod_timing_test.go index 6f9841f4d..17db2ff7f 100644 --- a/lib/promscrape/discovery/kubernetes/pod_timing_test.go +++ b/lib/promscrape/discovery/kubernetes/pod_timing_test.go @@ -10,7 +10,7 @@ func BenchmarkPodGetTargetLabels(b *testing.B) { r := bytes.NewBufferString(testPodsList) objectsByKey, _, err := parsePodList(r) if err != nil { - panic(fmt.Errorf("BUG: unexpected error: %s", err)) + panic(fmt.Errorf("BUG: unexpected error: %w", err)) } var o object for _, srcObject := range objectsByKey { diff --git a/lib/promscrape/scrapework.go b/lib/promscrape/scrapework.go index 2b684e1b9..272902063 100644 --- a/lib/promscrape/scrapework.go +++ b/lib/promscrape/scrapework.go @@ -579,7 +579,7 @@ func (sw *scrapeWork) scrapeStream(scrapeTimestamp, realTimestamp int64) error { samplesDropped := 0 sr, err := sw.GetStreamReader() if err != nil { - err = fmt.Errorf("cannot read data: %s", err) + err = fmt.Errorf("cannot read data: %w", err) } else { var mu sync.Mutex err = sbr.Init(sr) @@ -827,7 +827,7 @@ func (sw *scrapeWork) sendStaleSeries(lastScrape, currScrape string, timestamp i return nil }, sw.logError) if err != nil { - sw.logError(fmt.Errorf("cannot send stale markers: %s", err).Error()) + sw.logError(fmt.Errorf("cannot send stale markers: %w", err).Error()) } } if addAutoSeries { diff --git a/lib/protoparser/datadog/stream/streamparser.go b/lib/protoparser/datadog/stream/streamparser.go index 5a6c7e04f..d79f0b84a 100644 --- a/lib/protoparser/datadog/stream/streamparser.go +++ b/lib/protoparser/datadog/stream/streamparser.go @@ -64,7 +64,7 @@ func Parse(r io.Reader, contentEncoding string, callback func(series []datadog.S defer putRequest(req) if err := req.Unmarshal(ctx.reqBuf.B); err != nil { unmarshalErrors.Inc() - return fmt.Errorf("cannot unmarshal DataDog POST request with size %d bytes: %s", len(ctx.reqBuf.B), err) + return fmt.Errorf("cannot unmarshal DataDog POST request with size %d bytes: %w", len(ctx.reqBuf.B), err) } rows := 0 series := req.Series diff --git a/lib/protoparser/newrelic/parser_timing_test.go b/lib/protoparser/newrelic/parser_timing_test.go index 7a5641271..f51a434b7 100644 --- a/lib/protoparser/newrelic/parser_timing_test.go +++ b/lib/protoparser/newrelic/parser_timing_test.go @@ -58,7 +58,7 @@ func BenchmarkRowsUnmarshal(b *testing.B) { var r Rows for pb.Next() { if err := r.Unmarshal(reqBody); err != nil { - panic(fmt.Errorf("unmarshal error: %s", err)) + panic(fmt.Errorf("unmarshal error: %w", err)) } if len(r.Rows) != 1 { panic(fmt.Errorf("unexpected number of items unmarshaled; got %d; want %d", len(r.Rows), 1)) diff --git a/lib/protoparser/opentelemetry/stream/streamparser_test.go b/lib/protoparser/opentelemetry/stream/streamparser_test.go index 6b4f4c9f8..f56783efb 100644 --- a/lib/protoparser/opentelemetry/stream/streamparser_test.go +++ b/lib/protoparser/opentelemetry/stream/streamparser_test.go @@ -132,10 +132,10 @@ func checkParseStream(data []byte, checkSeries func(tss []prompbmarshal.TimeSeri var bb bytes.Buffer zw := gzip.NewWriter(&bb) if _, err := zw.Write(data); err != nil { - return fmt.Errorf("cannot compress data: %s", err) + return fmt.Errorf("cannot compress data: %w", err) } if err := zw.Close(); err != nil { - return fmt.Errorf("cannot close gzip writer: %s", err) + return fmt.Errorf("cannot close gzip writer: %w", err) } if err := ParseStream(&bb, true, checkSeries); err != nil { return fmt.Errorf("error when parsing compressed data: %w", err) diff --git a/lib/proxy/proxy.go b/lib/proxy/proxy.go index 02bd2f3c9..e063033b0 100644 --- a/lib/proxy/proxy.go +++ b/lib/proxy/proxy.go @@ -173,7 +173,7 @@ func (u *URL) NewDialFunc(ac *promauth.Config) (fasthttp.DialFunc, error) { } authHeader, err := u.getAuthHeader(ac) if err != nil { - return nil, fmt.Errorf("cannot get auth header: %s", err) + return nil, fmt.Errorf("cannot get auth header: %w", err) } if authHeader != "" { authHeader = "Proxy-Authorization: " + authHeader + "\r\n" diff --git a/lib/querytracer/tracer.go b/lib/querytracer/tracer.go index 1b3dde722..1d7e00e5c 100644 --- a/lib/querytracer/tracer.go +++ b/lib/querytracer/tracer.go @@ -141,7 +141,7 @@ func (t *Tracer) AddJSON(jsonTrace []byte) error { } var s *span if err := json.Unmarshal(jsonTrace, &s); err != nil { - return fmt.Errorf("cannot unmarshal json trace: %s", err) + return fmt.Errorf("cannot unmarshal json trace: %w", err) } child := &Tracer{ span: s, diff --git a/lib/regexutil/promregex_timing_test.go b/lib/regexutil/promregex_timing_test.go index d2705822d..f34938759 100644 --- a/lib/regexutil/promregex_timing_test.go +++ b/lib/regexutil/promregex_timing_test.go @@ -87,7 +87,7 @@ func BenchmarkPromRegexMatchString(b *testing.B) { func benchmarkPromRegexMatchString(b *testing.B, expr, s string, resultExpected bool) { pr, err := NewPromRegex(expr) if err != nil { - panic(fmt.Errorf("unexpected error: %s", err)) + panic(fmt.Errorf("unexpected error: %w", err)) } re := regexp.MustCompile("^(?:" + expr + ")$") f := func(b *testing.B, matchString func(s string) bool) { diff --git a/lib/storage/block_test.go b/lib/storage/block_test.go index e1bbfa63f..012d4db5b 100644 --- a/lib/storage/block_test.go +++ b/lib/storage/block_test.go @@ -112,7 +112,7 @@ func getTimestampsForPrecisionBits(timestamps []int64, precisionBits uint8) []in data, marshalType, firstTimestamp := encoding.MarshalTimestamps(nil, timestamps, precisionBits) timestampsAdjusted, err := encoding.UnmarshalTimestamps(nil, data, marshalType, firstTimestamp, len(timestamps)) if err != nil { - panic(fmt.Errorf("BUG: cannot unmarshal timestamps with precisionBits %d: %s", precisionBits, err)) + panic(fmt.Errorf("BUG: cannot unmarshal timestamps with precisionBits %d: %w", precisionBits, err)) } minTimestamp := timestamps[0] maxTimestamp := timestamps[len(timestamps)-1] @@ -124,7 +124,7 @@ func getValuesForPrecisionBits(values []int64, precisionBits uint8) []int64 { data, marshalType, firstValue := encoding.MarshalValues(nil, values, precisionBits) valuesAdjusted, err := encoding.UnmarshalValues(nil, data, marshalType, firstValue, len(values)) if err != nil { - panic(fmt.Errorf("BUG: cannot unmarshal values with precisionBits %d: %s", precisionBits, err)) + panic(fmt.Errorf("BUG: cannot unmarshal values with precisionBits %d: %w", precisionBits, err)) } return valuesAdjusted } diff --git a/lib/storage/index_db.go b/lib/storage/index_db.go index 62777d7fa..c3e2785b8 100644 --- a/lib/storage/index_db.go +++ b/lib/storage/index_db.go @@ -747,7 +747,7 @@ func (is *indexSearch) getLabelNamesForMetricIDs(qt *querytracer.Tracer, metricI continue } if err := mn.Unmarshal(buf); err != nil { - logger.Panicf("FATAL: cannot unmarshal metricName %q: %w", buf, err) + logger.Panicf("FATAL: cannot unmarshal metricName %q: %s", buf, err) } for _, tag := range mn.Tags { if _, ok := lns[string(tag.Key)]; !ok { @@ -1610,7 +1610,7 @@ func (db *indexDB) searchMetricIDs(qt *querytracer.Tracer, tfss []*TagFilters, t localMetricIDs, err := is.searchMetricIDs(qtChild, tfss, tr, maxMetrics) db.putIndexSearch(is) if err != nil { - return nil, fmt.Errorf("error when searching for metricIDs in the current indexdb: %s", err) + return nil, fmt.Errorf("error when searching for metricIDs in the current indexdb: %w", err) } qtChild.Done() @@ -1635,7 +1635,7 @@ func (db *indexDB) searchMetricIDs(qt *querytracer.Tracer, tfss []*TagFilters, t extDB.putMetricIDsToTagFiltersCache(qtChild, extMetricIDs, tfKeyExtBuf.B) }) if err != nil { - return nil, fmt.Errorf("error when searching for metricIDs in the previous indexdb: %s", err) + return nil, fmt.Errorf("error when searching for metricIDs in the previous indexdb: %w", err) } // Merge localMetricIDs with extMetricIDs. @@ -1834,7 +1834,7 @@ func (is *indexSearch) searchMetricName(dst []byte, metricID uint64) ([]byte, bo if err == io.EOF { return dst, false } - logger.Panicf("FATAL: error when searching metricName by metricID; searchPrefix %q: %w", kb.B, err) + logger.Panicf("FATAL: error when searching metricName by metricID; searchPrefix %q: %s", kb.B, err) } v := ts.Item[len(kb.B):] dst = append(dst, v...) diff --git a/lib/storage/part_search_timing_test.go b/lib/storage/part_search_timing_test.go index cacd73bd7..4c3feb474 100644 --- a/lib/storage/part_search_timing_test.go +++ b/lib/storage/part_search_timing_test.go @@ -50,7 +50,7 @@ func benchmarkPartSearch(b *testing.B, p *part, tsids []TSID, tr TimeRange, spar blocksRead++ } if err := ps.Error(); err != nil { - panic(fmt.Errorf("BUG: unexpected error: %s", err)) + panic(fmt.Errorf("BUG: unexpected error: %w", err)) } blocksWant := len(tsids) / sparseness if blocksRead != blocksWant {