Skip to content

Commit

Permalink
chore: fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Oct 24, 2023
1 parent 8c9dd48 commit afc2a98
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ issues:
- linters: [revive]
text: "exported const .+ should have comment"

# It's okay for ytlocal to write files and exec binaries.
- path: (cmd|internal)/ytlocal
linters: [gosec]
text: "G(306|301|204)"

# False positive.
- path: internal/cmp
linters: [gocritic]
Expand All @@ -136,3 +141,6 @@ issues:
- path: internal/chstorage
linters: [goconst]
text: "int"
- path: internal/ytlocal
linters: [goconst]
text: ".yson"
6 changes: 6 additions & 0 deletions internal/logql/label.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package logql

import (
"regexp"

"github.com/go-faster/errors"

"github.com/go-faster/oteldb/internal/lexerql"
Expand Down Expand Up @@ -32,3 +34,7 @@ func IsValidLabel[S ~string | ~[]byte](s S, allowDot bool) error {
}
return nil
}

func compileLabelRegex(re string) (*regexp.Regexp, error) {
return regexp.Compile("^(?:" + re + ")$")
}
2 changes: 1 addition & 1 deletion internal/logql/logqlengine/json_unsafe.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import (
)

func decodeStr(s string) *jx.Decoder {
data := unsafe.Slice(unsafe.StringData(s), len(s))
data := unsafe.Slice(unsafe.StringData(s), len(s)) // #nosec: G103
return jx.DecodeBytes(data)
}
4 changes: 1 addition & 3 deletions internal/logql/parser_log_expr.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package logql

import (
"regexp"

"github.com/go-faster/errors"

"github.com/go-faster/oteldb/internal/logql/lexer"
Expand Down Expand Up @@ -86,7 +84,7 @@ func (p *parser) parseLabelMatcher() (m LabelMatcher, err error) {
}
switch m.Op {
case OpRe, OpNotRe:
m.Re, err = regexp.Compile("^(?:" + m.Value + ")$")
m.Re, err = compileLabelRegex(m.Value)
if err != nil {
return m, errors.Wrapf(err, "invalid regex in label matcher %q", m.Value)
}
Expand Down
4 changes: 1 addition & 3 deletions internal/logql/parser_metric_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package logql

import (
"math"
"regexp"

"github.com/go-faster/errors"

Expand Down Expand Up @@ -373,11 +372,10 @@ func (p *parser) parseLabelReplace() (lr *LabelReplaceExpr, err error) {
if err := readParam(&lr.SrcLabel); err != nil {
return nil, err
}
// TODO(tdakkota): compile regex?
if err := readParam(&lr.Regex); err != nil {
return nil, err
}
lr.Re, err = regexp.Compile("^(?:" + lr.Regex + ")$")
lr.Re, err = compileLabelRegex(lr.Regex)
if err != nil {
return nil, errors.Wrapf(err, "invalid regex in label_replace %q", lr.Regex)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/logql/parser_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (p *parser) parseLabelPredicate() (pred LabelPredicate, _ error) {
var re *regexp.Regexp
switch op {
case OpRe, OpNotRe:
re, err = regexp.Compile("^(?:" + v + ")$")
re, err = compileLabelRegex(v)
if err != nil {
return nil, errors.Wrapf(err, "invalid regex in label matcher predicate %q", v)
}
Expand Down

0 comments on commit afc2a98

Please sign in to comment.