Skip to content

Commit

Permalink
Address new golangci-lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ntap-fge committed Oct 18, 2024
1 parent 4d3f462 commit 45c2f81
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ issues:
exclude:
- Error return value of .*log\.Logger\)\.Log\x60 is not checked
- Error return value of .*.Log.* is not checked
- '"io/ioutil" has been deprecated'
- rand.Seed has been deprecated
2 changes: 1 addition & 1 deletion pkg/ingester/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (i *instance) getOrCreateStream(pushReqStream logproto.Stream, lock bool, r
"stream", pushReqStream.Labels,
)
}
return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}
fp := i.getHashForLabels(labels)

Expand Down
2 changes: 1 addition & 1 deletion pkg/ingester/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (s *stream) Push(

fmt.Fprintf(&buf, "total ignored: %d out of %d", len(failedEntriesWithError), len(entries))

return bytesAdded, httpgrpc.Errorf(http.StatusBadRequest, buf.String())
return bytesAdded, httpgrpc.Errorf(http.StatusBadRequest, "%s", buf.String())
}
return bytesAdded, lastEntryWithErr.e
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ingester/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestMaxReturnedStreamsErrors(t *testing.T) {
}

fmt.Fprintf(&expected, "total ignored: %d out of %d", numLogs, numLogs)
expectErr := httpgrpc.Errorf(http.StatusBadRequest, expected.String())
expectErr := httpgrpc.Errorf(http.StatusBadRequest, "%s", expected.String())

_, err = s.Push(context.Background(), newLines, recordPool.GetRecord())
require.Error(t, err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/logentry/stages/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ func validateMatcherConfig(cfg *MatcherConfig) (logql.LogSelectorExpr, error) {
return nil, errors.New(ErrUnknownMatchAction)
}

if cfg.Action == MatchActionKeep && (cfg.Stages == nil || len(cfg.Stages) == 0) {
if cfg.Action == MatchActionKeep && len(cfg.Stages) == 0 {
return nil, errors.New(ErrMatchRequiresStages)
}
if cfg.Action == MatchActionDrop && (cfg.Stages != nil && len(cfg.Stages) != 0) {
if cfg.Action == MatchActionDrop && len(cfg.Stages) != 0 {
return nil, errors.New(ErrStagesWithDropLine)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/logql/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ func (q *query) evalSample(ctx context.Context, expr SampleExpr) (promql_parser.
return result, stepEvaluator.Error()
}

// nolint: unparam
func (q *query) evalLiteral(_ context.Context, expr *literalExpr) (promql_parser.Value, error) {
s := promql.Scalar{
T: q.params.Start().UnixNano() / int64(time.Millisecond),
Expand Down
4 changes: 2 additions & 2 deletions pkg/logql/log/jsonexpr/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewScanner(r io.Reader, debug bool) *Scanner {
}

func (sc *Scanner) Error(s string) {
sc.err = fmt.Errorf(s)
sc.err = fmt.Errorf("%s", s)
fmt.Printf("syntax error: %s\n", s)
}

Expand Down Expand Up @@ -53,7 +53,7 @@ func (sc *Scanner) lex(lval *JSONExprSymType) int {
sc.unread()
val, err := sc.scanInt()
if err != nil {
sc.err = fmt.Errorf(err.Error())
sc.err = fmt.Errorf("%s", err.Error())
return 0
}

Expand Down
18 changes: 9 additions & 9 deletions pkg/querier/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (q *Querier) RangeQueryHandler(w http.ResponseWriter, r *http.Request) {

request, err := loghttp.ParseRangeQuery(r)
if err != nil {
serverutil.WriteError(httpgrpc.Errorf(http.StatusBadRequest, err.Error()), w)
serverutil.WriteError(httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error()), w)
return
}

Expand Down Expand Up @@ -78,7 +78,7 @@ func (q *Querier) InstantQueryHandler(w http.ResponseWriter, r *http.Request) {

request, err := loghttp.ParseInstantQuery(r)
if err != nil {
serverutil.WriteError(httpgrpc.Errorf(http.StatusBadRequest, err.Error()), w)
serverutil.WriteError(httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error()), w)
return
}

Expand Down Expand Up @@ -118,12 +118,12 @@ func (q *Querier) LogQueryHandler(w http.ResponseWriter, r *http.Request) {

request, err := loghttp.ParseRangeQuery(r)
if err != nil {
serverutil.WriteError(httpgrpc.Errorf(http.StatusBadRequest, err.Error()), w)
serverutil.WriteError(httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error()), w)
return
}
request.Query, err = parseRegexQuery(r)
if err != nil {
serverutil.WriteError(httpgrpc.Errorf(http.StatusBadRequest, err.Error()), w)
serverutil.WriteError(httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error()), w)
return
}

Expand Down Expand Up @@ -172,7 +172,7 @@ func (q *Querier) LogQueryHandler(w http.ResponseWriter, r *http.Request) {
func (q *Querier) LabelHandler(w http.ResponseWriter, r *http.Request) {
req, err := loghttp.ParseLabelQuery(r)
if err != nil {
serverutil.WriteError(httpgrpc.Errorf(http.StatusBadRequest, err.Error()), w)
serverutil.WriteError(httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error()), w)
return
}

Expand Down Expand Up @@ -202,13 +202,13 @@ func (q *Querier) TailHandler(w http.ResponseWriter, r *http.Request) {

req, err := loghttp.ParseTailQuery(r)
if err != nil {
serverutil.WriteError(httpgrpc.Errorf(http.StatusBadRequest, err.Error()), w)
serverutil.WriteError(httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error()), w)
return
}

req.Query, err = parseRegexQuery(r)
if err != nil {
serverutil.WriteError(httpgrpc.Errorf(http.StatusBadRequest, err.Error()), w)
serverutil.WriteError(httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error()), w)
return
}

Expand Down Expand Up @@ -309,7 +309,7 @@ func (q *Querier) TailHandler(w http.ResponseWriter, r *http.Request) {
func (q *Querier) SeriesHandler(w http.ResponseWriter, r *http.Request) {
req, err := loghttp.ParseSeriesQuery(r)
if err != nil {
serverutil.WriteError(httpgrpc.Errorf(http.StatusBadRequest, err.Error()), w)
serverutil.WriteError(httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error()), w)
return
}

Expand Down Expand Up @@ -348,7 +348,7 @@ func parseRegexQuery(httpRequest *http.Request) (string, error) {
func (q *Querier) validateEntriesLimits(ctx context.Context, query string, limit uint32) error {
userID, err := user.ExtractOrgID(ctx)
if err != nil {
return httpgrpc.Errorf(http.StatusBadRequest, err.Error())
return httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}

expr, err := logql.ParseExpr(query)
Expand Down
12 changes: 6 additions & 6 deletions pkg/querier/queryrange/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ func (*ValiLabelNamesRequest) GetCachingOptions() (res queryrange.CachingOptions

func (codec) DecodeRequest(_ context.Context, r *http.Request) (queryrange.Request, error) {
if err := r.ParseForm(); err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}

switch op := getOperation(r.URL.Path); op {
case QueryRangeOp:
req, err := loghttp.ParseRangeQuery(r)
if err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}
return &ValiRequest{
Query: req.Query,
Expand All @@ -174,7 +174,7 @@ func (codec) DecodeRequest(_ context.Context, r *http.Request) (queryrange.Reque
case SeriesOp:
req, err := loghttp.ParseSeriesQuery(r)
if err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}
return &ValiSeriesRequest{
Match: req.Groups,
Expand All @@ -185,15 +185,15 @@ func (codec) DecodeRequest(_ context.Context, r *http.Request) (queryrange.Reque
case LabelNamesOp:
req, err := loghttp.ParseLabelQuery(r)
if err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}
return &ValiLabelNamesRequest{
StartTs: *req.Start,
EndTs: *req.End,
Path: r.URL.Path,
}, nil
default:
return nil, httpgrpc.Errorf(http.StatusBadRequest, fmt.Sprintf("unknown request path: %s", r.URL.Path))
return nil, httpgrpc.Errorf(http.StatusBadRequest, "unknown request path: %s", r.URL.Path)
}

}
Expand Down Expand Up @@ -273,7 +273,7 @@ func (codec) EncodeRequest(ctx context.Context, r queryrange.Request) (*http.Req
func (codec) DecodeResponse(ctx context.Context, r *http.Response, req queryrange.Request) (queryrange.Response, error) {
if r.StatusCode/100 != 2 {
body, _ := ioutil.ReadAll(r.Body)
return nil, httpgrpc.Errorf(r.StatusCode, string(body))
return nil, httpgrpc.Errorf(r.StatusCode, "%s", string(body))
}

sp, _ := opentracing.StartSpanFromContext(ctx, "codec.DecodeResponse")
Expand Down
4 changes: 2 additions & 2 deletions pkg/querier/queryrange/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (rt limitedRoundTripper) RoundTrip(r *http.Request) (*http.Response, error)
}
userid, err := user.ExtractOrgID(ctx)
if err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}

parallelism := rt.limits.MaxQueryParallelism(userid)
Expand Down Expand Up @@ -255,7 +255,7 @@ func (rt limitedRoundTripper) do(ctx context.Context, r queryrange.Request) (que
}

if err := user.InjectOrgIDIntoHTTPRequest(ctx, request); err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}

response, err := rt.next.RoundTrip(request)
Expand Down
14 changes: 7 additions & 7 deletions pkg/querier/queryrange/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,26 @@ func newRoundTripper(next, log, metric, series, labels http.RoundTripper, limits
func (r roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
err := req.ParseForm()
if err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}

switch op := getOperation(req.URL.Path); op {
case QueryRangeOp:
rangeQuery, err := loghttp.ParseRangeQuery(req)
if err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}
expr, err := logql.ParseExpr(rangeQuery.Query)
if err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}
switch e := expr.(type) {
case logql.SampleExpr:
return r.metric.RoundTrip(req)
case logql.LogSelectorExpr:
expr, err := transformRegexQuery(req, e)
if err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}
if err := validateLimits(req, rangeQuery.Limit, r.limits); err != nil {
return nil, err
Expand All @@ -142,13 +142,13 @@ func (r roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
case SeriesOp:
_, err := loghttp.ParseSeriesQuery(req)
if err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}
return r.series.RoundTrip(req)
case LabelNamesOp:
_, err := loghttp.ParseLabelQuery(req)
if err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}
return r.labels.RoundTrip(req)
default:
Expand Down Expand Up @@ -179,7 +179,7 @@ func transformRegexQuery(req *http.Request, expr logql.LogSelectorExpr) (logql.L
func validateLimits(req *http.Request, reqLimit uint32, limits Limits) error {
userID, err := user.ExtractOrgID(req.Context())
if err != nil {
return httpgrpc.Errorf(http.StatusBadRequest, err.Error())
return httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}

maxEntriesLimit := limits.MaxEntriesLimitPerQuery(userID)
Expand Down
2 changes: 1 addition & 1 deletion pkg/querier/queryrange/split_by_interval.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (h *splitByInterval) loop(ctx context.Context, ch <-chan *valiResult, next
func (h *splitByInterval) Do(ctx context.Context, r queryrange.Request) (queryrange.Response, error) {
userid, err := user.ExtractOrgID(ctx)
if err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}

interval := h.limits.QuerySplitDuration(userid)
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/server/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func Test_writeError(t *testing.T) {
{"orgid", user.ErrNoOrgID, user.ErrNoOrgID.Error(), http.StatusBadRequest},
{"deadline", context.DeadlineExceeded, ErrDeadlineExceeded, http.StatusGatewayTimeout},
{"parse error", logql.ParseError{}, "parse error : ", http.StatusBadRequest},
{"httpgrpc", httpgrpc.Errorf(http.StatusBadRequest, errors.New("foo").Error()), "foo", http.StatusBadRequest},
{"httpgrpc", httpgrpc.Errorf(http.StatusBadRequest, "%s", errors.New("foo").Error()), "foo", http.StatusBadRequest},
{"internal", errors.New("foo"), "foo", http.StatusInternalServerError},
{"query error", chunk.ErrQueryMustContainMetricName, chunk.ErrQueryMustContainMetricName.Error(), http.StatusBadRequest},
{"wrapped query error", fmt.Errorf("wrapped: %w", chunk.ErrQueryMustContainMetricName), "wrapped: " + chunk.ErrQueryMustContainMetricName.Error(), http.StatusBadRequest},
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/server/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func NewPrepopulateMiddleware() middleware.Interface {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
err := req.ParseForm()
if err != nil {
WriteError(httpgrpc.Errorf(http.StatusBadRequest, err.Error()), w)
WriteError(httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error()), w)
return

}
Expand Down

0 comments on commit 45c2f81

Please sign in to comment.