Skip to content

Commit

Permalink
Add goimport local-prefixes configuration to .golangci.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
adityacs committed Feb 18, 2020
1 parent 45d40a5 commit 71c9b6b
Show file tree
Hide file tree
Showing 99 changed files with 259 additions and 141 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ output:
# print linter name in the end of issue text, default is true
print-linter-name: true

linters-settings:
goimports:
local-prefixes: github.com/grafana/loki/pkg

linters:
enable:
- deadcode
Expand Down
22 changes: 21 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Please follow the [Loki Helm Chart](./production/helm/README.md).

### Dependency management

We uses [Go modules](https://golang.org/cmd/go/#hdr-Modules__module_versions__and_more) to manage dependencies on external packages.
We use [Go modules](https://golang.org/cmd/go/#hdr-Modules__module_versions__and_more) to manage dependencies on external packages.
This requires a working Go environment with version 1.13 or greater and git installed.

To add or update a new dependency, use the `go get` command:
Expand All @@ -48,3 +48,23 @@ git commit
```

You have to commit the changes to `go.mod` and `go.sum` before submitting the pull request.

## Coding Standards

### go imports
imports should follow `std libs`, `externals libs` and `local packages` format

Example
```
import (
"fmt"
"math"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/logql"
)
```

2 changes: 1 addition & 1 deletion cmd/chunks-inspect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func printFile(filename string, blockDetails, printLines, storeBlocks bool) {
}
if len(lokiChunk.blocks) > 0 {
fmt.Println("Minimum time (from first block):", time.Unix(0, lokiChunk.blocks[0].minT).In(timezone).Format(format))
fmt.Println("Maximum time (from last block):", time.Unix(0, lokiChunk.blocks[len(lokiChunk.blocks) - 1].maxT).In(timezone).Format(format))
fmt.Println("Maximum time (from last block):", time.Unix(0, lokiChunk.blocks[len(lokiChunk.blocks)-1].maxT).In(timezone).Format(format))
}

if blockDetails {
Expand Down
3 changes: 2 additions & 1 deletion cmd/docker-driver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import (
"github.com/cortexproject/cortex/pkg/util/flagext"
"github.com/docker/docker/daemon/logger"
"github.com/docker/docker/daemon/logger/templates"
"github.com/prometheus/common/model"

"github.com/grafana/loki/pkg/helpers"
"github.com/grafana/loki/pkg/logentry/stages"
"github.com/grafana/loki/pkg/promtail/client"
"github.com/grafana/loki/pkg/promtail/targets"
"github.com/prometheus/common/model"
)

const (
Expand Down
5 changes: 3 additions & 2 deletions cmd/docker-driver/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"github.com/docker/docker/daemon/logger"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"

"github.com/grafana/loki/pkg/logentry/stages"
"github.com/grafana/loki/pkg/promtail/api"
"github.com/grafana/loki/pkg/promtail/client"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
)

var jobName = "docker"
Expand Down
3 changes: 2 additions & 1 deletion cmd/docker-driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"github.com/docker/go-plugins-helpers/sdk"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
_ "github.com/grafana/loki/pkg/build"
"github.com/prometheus/common/version"
"github.com/weaveworks/common/logging"

_ "github.com/grafana/loki/pkg/build"
)

const socketAddress = "/run/docker/plugins/loki.sock"
Expand Down
5 changes: 3 additions & 2 deletions cmd/fluent-bit/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
"time"

"github.com/cortexproject/cortex/pkg/util/flagext"
"github.com/prometheus/common/model"
"github.com/weaveworks/common/logging"

"github.com/grafana/loki/pkg/logql"
"github.com/grafana/loki/pkg/promtail/client"
lokiflag "github.com/grafana/loki/pkg/util/flagext"
"github.com/prometheus/common/model"
"github.com/weaveworks/common/logging"
)

var defaultClientCfg = client.Config{}
Expand Down
3 changes: 2 additions & 1 deletion cmd/fluent-bit/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
"github.com/prometheus/common/model"

"github.com/cortexproject/cortex/pkg/util/flagext"
"github.com/weaveworks/common/logging"

"github.com/grafana/loki/pkg/promtail/client"
lokiflag "github.com/grafana/loki/pkg/util/flagext"
"github.com/weaveworks/common/logging"
)

type fakeConfig map[string]string
Expand Down
3 changes: 2 additions & 1 deletion cmd/fluent-bit/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/grafana/loki/pkg/promtail/client"
jsoniter "github.com/json-iterator/go"
"github.com/prometheus/common/model"
"github.com/weaveworks/common/logging"

"github.com/grafana/loki/pkg/promtail/client"
)

type loki struct {
Expand Down
3 changes: 2 additions & 1 deletion cmd/fluent-bit/out_loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"github.com/fluent/fluent-bit-go/output"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
_ "github.com/grafana/loki/pkg/build"
"github.com/prometheus/common/version"
"github.com/weaveworks/common/logging"

_ "github.com/grafana/loki/pkg/build"
)

var (
Expand Down
5 changes: 3 additions & 2 deletions cmd/logcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"os"
"time"

"github.com/prometheus/common/config"
"github.com/prometheus/common/version"

_ "github.com/grafana/loki/pkg/build"
"github.com/grafana/loki/pkg/logcli/client"
"github.com/grafana/loki/pkg/logcli/labelquery"
"github.com/grafana/loki/pkg/logcli/output"
"github.com/grafana/loki/pkg/logcli/query"
"github.com/prometheus/common/config"
"github.com/prometheus/common/version"

"gopkg.in/alecthomas/kingpin.v2"
)
Expand Down
8 changes: 5 additions & 3 deletions cmd/loki/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import (
"reflect"

"github.com/go-kit/kit/log/level"
_ "github.com/grafana/loki/pkg/build"
"github.com/grafana/loki/pkg/cfg"
"github.com/grafana/loki/pkg/loki"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/version"
"github.com/weaveworks/common/logging"
"github.com/weaveworks/common/tracing"

_ "github.com/grafana/loki/pkg/build"
"github.com/grafana/loki/pkg/cfg"
"github.com/grafana/loki/pkg/loki"

"github.com/cortexproject/cortex/pkg/util"

"github.com/grafana/loki/pkg/util/validation"
)

Expand Down
5 changes: 3 additions & 2 deletions pkg/canary/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import (
"time"

"github.com/gorilla/websocket"
loghttp "github.com/grafana/loki/pkg/loghttp/legacy"
"github.com/grafana/loki/pkg/logproto"
json "github.com/json-iterator/go"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"

loghttp "github.com/grafana/loki/pkg/loghttp/legacy"
"github.com/grafana/loki/pkg/logproto"
)

var (
Expand Down
1 change: 1 addition & 0 deletions pkg/chunkenc/lazy_chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/cortexproject/cortex/pkg/chunk"

"github.com/grafana/loki/pkg/iter"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/logql"
Expand Down
3 changes: 2 additions & 1 deletion pkg/chunkenc/memchunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (
"github.com/stretchr/testify/assert"

"github.com/dustin/go-humanize"
"github.com/stretchr/testify/require"

"github.com/grafana/loki/pkg/chunkenc/testdata"
"github.com/grafana/loki/pkg/iter"
"github.com/grafana/loki/pkg/logproto"
"github.com/stretchr/testify/require"
)

var testEncoding = []Encoding{
Expand Down
1 change: 1 addition & 0 deletions pkg/distributor/ingestion_rate_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package distributor

import (
"github.com/cortexproject/cortex/pkg/util/limiter"

"github.com/grafana/loki/pkg/util/validation"
)

Expand Down
3 changes: 2 additions & 1 deletion pkg/distributor/ingestion_rate_strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"testing"

"github.com/cortexproject/cortex/pkg/util/limiter"
"github.com/grafana/loki/pkg/util/validation"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/grafana/loki/pkg/util/validation"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion pkg/distributor/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (

cortex_client "github.com/cortexproject/cortex/pkg/ingester/client"
cortex_validation "github.com/cortexproject/cortex/pkg/util/validation"
"github.com/weaveworks/common/httpgrpc"

"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/util"
"github.com/grafana/loki/pkg/util/flagext"
"github.com/weaveworks/common/httpgrpc"
)

type Validator struct {
Expand Down
5 changes: 3 additions & 2 deletions pkg/ingester/chunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/grafana/loki/pkg/chunkenc"
"github.com/grafana/loki/pkg/iter"
"github.com/grafana/loki/pkg/logproto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func testIteratorForward(t *testing.T, iter iter.EntryIterator, from, through int64) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/ingester/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (

cortex_client "github.com/cortexproject/cortex/pkg/ingester/client"
"github.com/cortexproject/cortex/pkg/util/grpcclient"
"github.com/grafana/loki/pkg/logproto"
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
opentracing "github.com/opentracing/opentracing-go"
"github.com/weaveworks/common/middleware"
"google.golang.org/grpc"
"google.golang.org/grpc/health/grpc_health_v1"

"github.com/grafana/loki/pkg/logproto"
)

// Config for an ingester client.
Expand Down
1 change: 1 addition & 0 deletions pkg/ingester/flush.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/cortexproject/cortex/pkg/chunk"
"github.com/cortexproject/cortex/pkg/util"

"github.com/grafana/loki/pkg/chunkenc"
loki_util "github.com/grafana/loki/pkg/util"
)
Expand Down
3 changes: 2 additions & 1 deletion pkg/ingester/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"testing"
"time"

"github.com/grafana/loki/pkg/util"
"github.com/prometheus/prometheus/pkg/labels"

"github.com/grafana/loki/pkg/util"

"github.com/grafana/loki/pkg/chunkenc"
"github.com/grafana/loki/pkg/logproto"

Expand Down
3 changes: 2 additions & 1 deletion pkg/ingester/limiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"math"
"testing"

"github.com/grafana/loki/pkg/util/validation"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/grafana/loki/pkg/util/validation"
)

func TestLimiter_maxStreamsPerUser(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/ingester/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (
"testing"
"time"

"github.com/grafana/loki/pkg/chunkenc"
"github.com/grafana/loki/pkg/logproto"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/stretchr/testify/require"
"github.com/weaveworks/common/httpgrpc"

"github.com/grafana/loki/pkg/chunkenc"
"github.com/grafana/loki/pkg/logproto"
)

func TestMaxReturnedStreamsErrors(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/ingester/tailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (

cortex_util "github.com/cortexproject/cortex/pkg/util"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/pkg/labels"

"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/logql"
"github.com/grafana/loki/pkg/util"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/pkg/labels"
)

const bufferSizeForTailResponse = 5
Expand Down
3 changes: 2 additions & 1 deletion pkg/ingester/tailer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"testing"
"time"

"github.com/grafana/loki/pkg/logproto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/grafana/loki/pkg/logproto"
)

func TestTailer_sendRaceConditionOnSendWhileClosing(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/ingester/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import (
"github.com/cortexproject/cortex/pkg/ring"
"github.com/cortexproject/cortex/pkg/util"
"github.com/go-kit/kit/log/level"
"github.com/grafana/loki/pkg/helpers"
"github.com/grafana/loki/pkg/logproto"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/weaveworks/common/user"
"golang.org/x/net/context"

"github.com/grafana/loki/pkg/helpers"
"github.com/grafana/loki/pkg/logproto"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion pkg/ingester/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import (
"github.com/stretchr/testify/require"
"github.com/weaveworks/common/user"

"golang.org/x/net/context"

"github.com/grafana/loki/pkg/ingester/client"
"github.com/grafana/loki/pkg/logproto"
"golang.org/x/net/context"
)

func TestTransferOut(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/iter/iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (

"github.com/stretchr/testify/require"

"github.com/grafana/loki/pkg/logproto"
"github.com/stretchr/testify/assert"

"github.com/grafana/loki/pkg/logproto"
)

const testSize = 10
Expand Down
Loading

0 comments on commit 71c9b6b

Please sign in to comment.