From 269e7c8091e1dfcff05d3b4275c8c6b5a2c7d1fd Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Mon, 23 Mar 2020 15:47:11 +0100 Subject: [PATCH] Fix golint issues. Signed-off-by: Ben Kochie --- cmd/prometheus/main.go | 2 +- pkg/labels/labels.go | 6 ++---- pkg/runtime/limits_windows.go | 4 ++-- pkg/runtime/vmlimits_default.go | 4 ++-- pkg/runtime/vmlimits_openbsd.go | 4 ++-- pkg/textparse/openmetricslex.l | 2 +- pkg/textparse/openmetricslex.l.go | 2 +- pkg/textparse/openmetricsparse.go | 2 +- pkg/textparse/promparse.go | 4 ++-- promql/functions.go | 2 +- promql/parser/ast.go | 3 +-- promql/parser/lex.go | 2 +- promql/parser/parse.go | 24 +++++++++++------------- promql/parser/printer.go | 2 +- tsdb/db.go | 1 + tsdb/querier_test.go | 2 +- tsdb/tsdbblockutil.go | 4 ++-- tsdb/wal/wal.go | 1 + web/api/v2/api.go | 2 +- web/ui/ui.go | 2 +- 20 files changed, 36 insertions(+), 39 deletions(-) diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index 1a4635122..13b5b2691 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -334,7 +334,7 @@ func main() { level.Info(logger).Log("build_context", version.BuildContext()) level.Info(logger).Log("host_details", prom_runtime.Uname()) level.Info(logger).Log("fd_limits", prom_runtime.FdLimits()) - level.Info(logger).Log("vm_limits", prom_runtime.VmLimits()) + level.Info(logger).Log("vm_limits", prom_runtime.VMLimits()) var ( localStorage = &readyStorage{} diff --git a/pkg/labels/labels.go b/pkg/labels/labels.go index 757d96847..138691e5a 100644 --- a/pkg/labels/labels.go +++ b/pkg/labels/labels.go @@ -301,16 +301,14 @@ func Compare(a, b Labels) int { if a[i].Name != b[i].Name { if a[i].Name < b[i].Name { return -1 - } else { - return 1 } + return 1 } if a[i].Value != b[i].Value { if a[i].Value < b[i].Value { return -1 - } else { - return 1 } + return 1 } } // If all labels so far were in common, the set with fewer labels comes first. diff --git a/pkg/runtime/limits_windows.go b/pkg/runtime/limits_windows.go index 32387131d..d947e132e 100644 --- a/pkg/runtime/limits_windows.go +++ b/pkg/runtime/limits_windows.go @@ -20,7 +20,7 @@ func FdLimits() string { return "N/A" } -// VmLimits not supported on Windows -func VmLimits() string { +// VMLimits not supported on Windows +func VMLimits() string { return "N/A" } diff --git a/pkg/runtime/vmlimits_default.go b/pkg/runtime/vmlimits_default.go index 60ab7757b..47c4dd7c9 100644 --- a/pkg/runtime/vmlimits_default.go +++ b/pkg/runtime/vmlimits_default.go @@ -20,7 +20,7 @@ import ( "syscall" ) -// VmLimits returns the soft and hard limits for virtual memory. -func VmLimits() string { +// VMLimits returns the soft and hard limits for virtual memory. +func VMLimits() string { return getLimits(syscall.RLIMIT_AS, "b") } diff --git a/pkg/runtime/vmlimits_openbsd.go b/pkg/runtime/vmlimits_openbsd.go index 981f1bcf8..f2117fe06 100644 --- a/pkg/runtime/vmlimits_openbsd.go +++ b/pkg/runtime/vmlimits_openbsd.go @@ -19,7 +19,7 @@ import ( "syscall" ) -// VmLimits returns the soft and hard limits for virtual memory. -func VmLimits() string { +// VMLimits returns the soft and hard limits for virtual memory. +func VMLimits() string { return getLimits(syscall.RLIMIT_DATA, "b") } diff --git a/pkg/textparse/openmetricslex.l b/pkg/textparse/openmetricslex.l index b02e97583..91e443942 100644 --- a/pkg/textparse/openmetricslex.l +++ b/pkg/textparse/openmetricslex.l @@ -49,7 +49,7 @@ S [ ] HELP{S} l.state = sMeta1; return tHelp TYPE{S} l.state = sMeta1; return tType UNIT{S} l.state = sMeta1; return tUnit -"EOF"\n? l.state = sInit; return tEofWord +"EOF"\n? l.state = sInit; return tEOFWord {M}({M}|{D})* l.state = sMeta2; return tMName {S}{C}*\n l.state = sInit; return tText diff --git a/pkg/textparse/openmetricslex.l.go b/pkg/textparse/openmetricslex.l.go index e20d127cd..6093c9f59 100644 --- a/pkg/textparse/openmetricslex.l.go +++ b/pkg/textparse/openmetricslex.l.go @@ -635,7 +635,7 @@ yyrule4: // UNIT{S} yyrule5: // "EOF"\n? { l.state = sInit - return tEofWord + return tEOFWord goto yystate0 } yyrule6: // {M}({M}|{D})* diff --git a/pkg/textparse/openmetricsparse.go b/pkg/textparse/openmetricsparse.go index 35ef1d5c4..6cfdd8391 100644 --- a/pkg/textparse/openmetricsparse.go +++ b/pkg/textparse/openmetricsparse.go @@ -233,7 +233,7 @@ func (p *OpenMetricsParser) Next() (Entry, error) { p.hasExemplarTs = false switch t := p.nextToken(); t { - case tEofWord: + case tEOFWord: if t := p.nextToken(); t != tEOF { return EntryInvalid, errors.New("unexpected data after # EOF") } diff --git a/pkg/textparse/promparse.go b/pkg/textparse/promparse.go index 6c254b526..3c885af0b 100644 --- a/pkg/textparse/promparse.go +++ b/pkg/textparse/promparse.go @@ -51,7 +51,7 @@ const ( tHelp tType tUnit - tEofWord + tEOFWord tText tComment tBlank @@ -82,7 +82,7 @@ func (t token) String() string { return "TYPE" case tUnit: return "UNIT" - case tEofWord: + case tEOFWord: return "EOFWORD" case tText: return "TEXT" diff --git a/promql/functions.go b/promql/functions.go index 367c965a5..49efadaf3 100644 --- a/promql/functions.go +++ b/promql/functions.go @@ -870,7 +870,7 @@ func funcYear(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) }) } -// Functions is a list of all functions supported by PromQL, including their types. +// FunctionCalls is a list of all functions supported by PromQL, including their types. var FunctionCalls = map[string]FunctionCall{ "abs": funcAbs, "absent": funcAbsent, diff --git a/promql/parser/ast.go b/promql/parser/ast.go index ccb5e0a17..cd7c91c9f 100644 --- a/promql/parser/ast.go +++ b/promql/parser/ast.go @@ -399,9 +399,8 @@ func (e Expressions) PositionRange() PositionRange { Start: -1, End: -1, } - } else { - return mergeRanges(e[0], e[len(e)-1]) } + return mergeRanges(e[0], e[len(e)-1]) } func (e *MatrixSelector) PositionRange() PositionRange { return PositionRange{ diff --git a/promql/parser/lex.go b/promql/parser/lex.go index 111b0cb53..c68300442 100644 --- a/promql/parser/lex.go +++ b/promql/parser/lex.go @@ -122,7 +122,7 @@ var key = map[string]ItemType{ "bool": BOOL, } -// These are the default string representations for common Items. It does not +// ItemTypeStr is the default string representations for common Items. It does not // imply that those are the only character sequences that can be lexed to such an Item. var ItemTypeStr = map[ItemType]string{ LEFT_PAREN: "(", diff --git a/promql/parser/parse.go b/promql/parser/parse.go index 1b6d8a930..1cdfd75da 100644 --- a/promql/parser/parse.go +++ b/promql/parser/parse.go @@ -94,12 +94,11 @@ type ParseErrors []ParseErr func (errs ParseErrors) Error() string { if len(errs) != 0 { return errs[0].Error() - } else { - // Should never happen - // Panicking while printing an error seems like a bad idea, so the - // situation is explained in the error message instead. - return "error contains no error message" } + // Should never happen + // Panicking while printing an error seems like a bad idea, so the + // situation is explained in the error message instead. + return "error contains no error message" } // ParseExpr returns the expression parsed from the input. @@ -295,14 +294,13 @@ func (p *parser) Lex(lval *yySymType) int { if p.injecting { p.injecting = false return int(p.inject) - } else { - // Skip comments. - for { - p.lex.NextItem(&lval.item) - typ = lval.item.Typ - if typ != COMMENT { - break - } + } + // Skip comments. + for { + p.lex.NextItem(&lval.item) + typ = lval.item.Typ + if typ != COMMENT { + break } } diff --git a/promql/parser/printer.go b/promql/parser/printer.go index c31d78e65..e187000af 100644 --- a/promql/parser/printer.go +++ b/promql/parser/printer.go @@ -113,7 +113,7 @@ func (node *Call) String() string { func (node *MatrixSelector) String() string { // Copy the Vector selector before changing the offset - var vecSelector VectorSelector = *node.VectorSelector.(*VectorSelector) + vecSelector := *node.VectorSelector.(*VectorSelector) offset := "" if vecSelector.Offset != time.Duration(0) { offset = fmt.Sprintf(" offset %s", model.Duration(vecSelector.Offset)) diff --git a/tsdb/db.go b/tsdb/db.go index 3cd75bae3..2a78a0b1a 100644 --- a/tsdb/db.go +++ b/tsdb/db.go @@ -39,6 +39,7 @@ import ( "github.com/prometheus/prometheus/tsdb/chunkenc" tsdb_errors "github.com/prometheus/prometheus/tsdb/errors" "github.com/prometheus/prometheus/tsdb/fileutil" + // Load the package into main to make sure minium Go version is met. _ "github.com/prometheus/prometheus/tsdb/goversion" "github.com/prometheus/prometheus/tsdb/wal" "golang.org/x/sync/errgroup" diff --git a/tsdb/querier_test.go b/tsdb/querier_test.go index 9668a21fe..e4c06d6ca 100644 --- a/tsdb/querier_test.go +++ b/tsdb/querier_test.go @@ -234,7 +234,7 @@ func createIdxChkReaders(t *testing.T, tc []seriesSamples) (IndexReader, ChunkRe app.Append(smpl.t, smpl.v) } chkReader[chunkRef] = chunk - chunkRef += 1 + chunkRef++ } ls := labels.FromMap(s.lset) diff --git a/tsdb/tsdbblockutil.go b/tsdb/tsdbblockutil.go index 297dc3107..5246edd64 100644 --- a/tsdb/tsdbblockutil.go +++ b/tsdb/tsdbblockutil.go @@ -23,7 +23,7 @@ import ( "github.com/prometheus/prometheus/pkg/labels" ) -var InvalidTimesError = fmt.Errorf("max time is lesser than min time") +var ErrInvalidTimes = fmt.Errorf("max time is lesser than min time") type MetricSample struct { TimestampMs int64 @@ -58,7 +58,7 @@ func CreateBlock(samples []*MetricSample, dir string, mint, maxt int64, logger l chunkRange = DefaultBlockDuration } if chunkRange < 0 { - return "", InvalidTimesError + return "", ErrInvalidTimes } head, err := CreateHead(samples, chunkRange, logger) if err != nil { diff --git a/tsdb/wal/wal.go b/tsdb/wal/wal.go index e4c198f68..30d8b002e 100644 --- a/tsdb/wal/wal.go +++ b/tsdb/wal/wal.go @@ -837,6 +837,7 @@ type segmentBufReader struct { off int // Offset of read data into current segment. } +// nolint:golint // TODO: Consider exporting segmentBufReader func NewSegmentBufReader(segs ...*Segment) *segmentBufReader { return &segmentBufReader{ buf: bufio.NewReaderSize(segs[0], 16*pageSize), diff --git a/web/api/v2/api.go b/web/api/v2/api.go index f657b3064..fe28e09d6 100644 --- a/web/api/v2/api.go +++ b/web/api/v2/api.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package api_v2 +package apiv2 import ( "context" diff --git a/web/ui/ui.go b/web/ui/ui.go index 6e6978f16..4aa39734b 100644 --- a/web/ui/ui.go +++ b/web/ui/ui.go @@ -26,7 +26,7 @@ import ( ) // Assets contains the project's assets. -var Assets http.FileSystem = func() http.FileSystem { +var Assets = func() http.FileSystem { wd, err := os.Getwd() if err != nil { panic(err)