diff --git a/.github/workflows/nix-ci.yaml b/.github/workflows/nix-ci.yaml index c6dbbbbc7f6b9..70e418425b9c2 100644 --- a/.github/workflows/nix-ci.yaml +++ b/.github/workflows/nix-ci.yaml @@ -6,12 +6,30 @@ on: - "flake.nix" - "nix/**" jobs: - tests: + lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: cachix/install-nix-action@v22 with: nix_path: nixpkgs=channel:nixos-unstable - - run: nix run .#lint - - run: nix build --print-build-logs + - run: nix run --print-build-logs .#lint + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: cachix/install-nix-action@v22 + with: + nix_path: nixpkgs=channel:nixos-unstable + - run: nix run --print-build-logs .#test + packages: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: cachix/install-nix-action@v22 + with: + nix_path: nixpkgs=channel:nixos-unstable + - run: nix build --print-build-logs .#logcli + - run: nix build --print-build-logs .#loki + - run: nix build --print-build-logs .#loki-canary + - run: nix build --print-build-logs .#promtail diff --git a/.golangci.yml b/.golangci.yml index 8f0686445498d..fb3c1ab689d0e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -63,6 +63,10 @@ linters-settings: - desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log" pkg: github.com/go-kit/kit/log + misspell: + ignore-words: + - strat + linters: enable: - errcheck diff --git a/flake.lock b/flake.lock index a1f5c07467865..06c301936e4db 100644 --- a/flake.lock +++ b/flake.lock @@ -1,12 +1,15 @@ { "nodes": { "flake-utils": { + "inputs": { + "systems": "systems" + }, "locked": { - "lastModified": 1678901627, - "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=", + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", "owner": "numtide", "repo": "flake-utils", - "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", "type": "github" }, "original": { @@ -17,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1680487167, - "narHash": "sha256-9FNIqrxDZgSliGGN2XJJSvcDYmQbgOANaZA4UWnTdg4=", + "lastModified": 1699781429, + "narHash": "sha256-UYefjidASiLORAjIvVsUHG6WBtRhM67kTjEY4XfZOFs=", "owner": "nixos", "repo": "nixpkgs", - "rev": "53dad94e874c9586e71decf82d972dfb640ef044", + "rev": "e44462d6021bfe23dfb24b775cc7c390844f773d", "type": "github" }, "original": { @@ -36,6 +39,21 @@ "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index ba0399daf11ab..631488a20694d 100644 --- a/flake.nix +++ b/flake.nix @@ -14,19 +14,14 @@ in { overlays = { - golangci-lint = import ./nix/overlays/golangci-lint.nix; - helm-docs = import ./nix/overlays/helm-docs.nix; default = nix.overlay; }; } // flake-utils.lib.eachDefaultSystem (system: let - pkgs = import nixpkgs { inherit system; overlays = [ - (import ./nix/overlays/golangci-lint.nix) - (import ./nix/overlays/helm-docs.nix) nix.overlay ]; config = { allowUnfree = true; }; @@ -40,9 +35,12 @@ packages = with pkgs; { inherit + logcli loki + loki-canary loki-helm-test - loki-helm-test-docker; + loki-helm-test-docker + promtail; }; apps = { @@ -56,21 +54,30 @@ }/bin/lint.sh"; }; + test = { + type = "app"; + program = with pkgs; "${ + (writeShellScriptBin "test.sh" '' + ${loki.overrideAttrs(old: { doCheck = true; })}/bin/loki --version + '') + }/bin/test.sh"; + }; + loki = { type = "app"; - program = with pkgs; "${loki.overrideAttrs(old: rec { doCheck = false; })}/bin/loki"; + program = with pkgs; "${loki}/bin/loki"; }; promtail = { type = "app"; - program = with pkgs; "${loki.overrideAttrs(old: rec { doCheck = false; })}/bin/promtail"; + program = with pkgs; "${promtail}/bin/promtail"; }; logcli = { type = "app"; - program = with pkgs; "${loki.overrideAttrs(old: rec { doCheck = false; })}/bin/logcli"; + program = with pkgs; "${logcli}/bin/logcli"; }; loki-canary = { type = "app"; - program = with pkgs; "${loki.overrideAttrs(old: rec { doCheck = false; })}/bin/loki-canary"; + program = with pkgs; "${loki-canary}/bin/loki-canary"; }; loki-helm-test = { type = "app"; @@ -80,20 +87,22 @@ devShell = pkgs.mkShell { nativeBuildInputs = with pkgs; [ + (import ./packages/chart-releaser.nix { + inherit (prev) pkgs lib buildGoModule fetchFromGitHub; + }) + + chart-testing + faillint gcc go - systemd - yamllint - nixpkgs-fmt - statix - nettools - golangci-lint gotools helm-docs - faillint - chart-testing - chart-releaser + nettools + nixpkgs-fmt + statix + systemd + yamllint ]; }; }); diff --git a/nix/default.nix b/nix/default.nix index 5f07c26ee14dd..f9ae62ef73b43 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -30,21 +30,55 @@ rev = gitRevision; }; in - { + rec { inherit (loki-helm-test) loki-helm-test loki-helm-test-docker; - loki = prev.callPackage ./loki.nix { + loki = prev.callPackage ./packages/loki.nix { inherit imageTag; version = shortGitRevsion; pkgs = prev; }; - faillint = prev.callPackage ./faillint.nix { - inherit (prev) lib buildGoModule fetchFromGitHub; - }; + logcli = loki.overrideAttrs (oldAttrs: rec { + pname = "logcli"; - chart-releaser = prev.callPackage ./chart-releaser.nix { - inherit (prev) pkgs lib buildGoModule fetchFromGitHub; - }; + buildPhase = '' + export GOCACHE=$TMPDIR/go-cache + make clean logcli + ''; + + installPhase = '' + mkdir -p $out/bin + install -m755 cmd/logcli/logcli $out/bin/logcli + ''; + }); + + loki-canary = loki.overrideAttrs (oldAttrs: rec { + pname = "loki-canary"; + + buildPhase = '' + export GOCACHE=$TMPDIR/go-cache + make clean loki-canary + ''; + + installPhase = '' + mkdir -p $out/bin + install -m755 cmd/loki-canary/loki-canary $out/bin/loki-canary + ''; + }); + + promtail = loki.overrideAttrs (oldAttrs: rec { + pname = "promtail"; + + buildPhase = '' + export GOCACHE=$TMPDIR/go-cache + make clean promtail + ''; + + installPhase = '' + mkdir -p $out/bin + install -m755 clients/cmd/promtail/promtail $out/bin/promtail + ''; + }); }; } diff --git a/nix/overlays/golangci-lint.nix b/nix/overlays/golangci-lint.nix deleted file mode 100644 index abbfacf90b0ee..0000000000000 --- a/nix/overlays/golangci-lint.nix +++ /dev/null @@ -1,28 +0,0 @@ -final: prev: { - golangci-lint = prev.callPackage - "${prev.path}/pkgs/development/tools/golangci-lint" - { - buildGoModule = args: - prev.buildGoModule (args // rec { - version = "1.51.2"; - - src = prev.fetchFromGitHub rec { - owner = "golangci"; - repo = "golangci-lint"; - rev = "v${version}"; - sha256 = "F2rkVZ5ia9/wyTw1WIeizFnuaHoS2A8VzVOGDcshy64="; - }; - - vendorHash = - "sha256-JO/mRJB3gRTtBj6pW1267/xXUtalTJo0p3q5e34vqTs="; - - ldflags = [ - "-s" - "-w" - "-X main.version=${version}" - "-X main.commit=v${version}" - "-X main.date=19700101-00:00:00" - ]; - }); - }; -} diff --git a/nix/overlays/helm-docs.nix b/nix/overlays/helm-docs.nix deleted file mode 100644 index 8c4a851399f63..0000000000000 --- a/nix/overlays/helm-docs.nix +++ /dev/null @@ -1,25 +0,0 @@ -final: prev: { - helm-docs = prev.callPackage - "${prev.path}/pkgs/applications/networking/cluster/helm-docs" - { - buildGoModule = args: - prev.buildGoModule (args // rec { - version = "1.11.0"; - - src = prev.fetchFromGitHub { - owner = "norwoodj"; - repo = "helm-docs"; - rev = "v${version}"; - sha256 = "sha256-476ZhjRwHlNJFkHzY8qQ7WbAUUpFNSoxXLGX9esDA/E="; - }; - - vendorSha256 = "sha256-xXwunk9rmzZEtqmSo8biuXnAjPp7fqWdQ+Kt9+Di9N8="; - - ldflags = [ - "-w" - "-s" - "-X main.version=v${version}" - ]; - }); - }; -} diff --git a/nix/chart-releaser.nix b/nix/packages/chart-releaser.nix similarity index 100% rename from nix/chart-releaser.nix rename to nix/packages/chart-releaser.nix diff --git a/nix/faillint.nix b/nix/packages/faillint.nix similarity index 100% rename from nix/faillint.nix rename to nix/packages/faillint.nix diff --git a/nix/loki.nix b/nix/packages/loki.nix similarity index 60% rename from nix/loki.nix rename to nix/packages/loki.nix index 246a7dbb3236b..b083db6e4a7d4 100644 --- a/nix/loki.nix +++ b/nix/packages/loki.nix @@ -1,22 +1,38 @@ { pkgs, version, imageTag }: +let + lambda-promtail-gomod = pkgs.buildGoModule { + inherit version; + pname = "lambda-promtail"; + + src = ./../../tools/lambda-promtail; + vendorSha256 = "11yNeQb4k5/w0+r+LJOmjXUQRaWvWSXqM+zMHtMVxY8="; + + doCheck = false; + + installPhase = '' + runHook preInstall + cp -r --reflink=auto vendor $out + runHook postInstall + ''; + }; +in pkgs.stdenv.mkDerivation { inherit version; pname = "loki"; - src = ./..; + src = ./../..; buildInputs = with pkgs; [ bash gcc - go git - bash + go + golangci-lint + nettools systemd yamllint - nettools - golangci-lint (import ./faillint.nix { inherit (pkgs) lib buildGoModule fetchFromGitHub; }) @@ -27,9 +43,9 @@ pkgs.stdenv.mkDerivation { substituteInPlace Makefile \ --replace "SHELL = /usr/bin/env bash -o pipefail" "SHELL = ${bash}/bin/bash -o pipefail" \ - --replace "IMAGE_TAG := \$(shell ./tools/image-tag)" "IMAGE_TAG := ${imageTag}" \ + --replace "IMAGE_TAG ?= \$(shell ./tools/image-tag)" "IMAGE_TAG ?= ${imageTag}" \ --replace "GIT_REVISION := \$(shell git rev-parse --short HEAD)" "GIT_REVISION := ${version}" \ - --replace "GIT_BRANCH := \$(shell git rev-parse --abbrev-ref HEAD)" "GIT_BRANCH := nix" \ + --replace "GIT_BRANCH := \$(shell git rev-parse --abbrev-ref HEAD)" "GIT_BRANCH := nix" substituteInPlace clients/cmd/fluentd/Makefile \ --replace "SHELL = /usr/bin/env bash -o pipefail" "SHELL = ${bash}/bin/bash -o pipefail" @@ -37,21 +53,25 @@ pkgs.stdenv.mkDerivation { buildPhase = '' export GOCACHE=$TMPDIR/go-cache - make clean loki logcli loki-canary promtail + export GOMODCACHE=$TMPDIR/gomodcache + export GOPROXY=off + + cp -r ${lambda-promtail-gomod} tools/lambda-promtail/vendor + make clean loki ''; - doCheck = true; + doCheck = false; checkPhase = '' export GOCACHE=$TMPDIR/go-cache + export GOMODCACHE=$TMPDIR/gomodcache export GOLANGCI_LINT_CACHE=$TMPDIR/go-cache + export GOPROXY=off + make lint test ''; installPhase = '' mkdir -p $out/bin install -m755 cmd/loki/loki $out/bin/loki - install -m755 cmd/logcli/logcli $out/bin/logcli - install -m755 cmd/loki-canary/loki-canary $out/bin/loki-canary - install -m755 clients/cmd/promtail/promtail $out/bin/promtail ''; } diff --git a/pkg/analytics/seed_test.go b/pkg/analytics/seed_test.go index 6435fabb00151..4229c508d2dfe 100644 --- a/pkg/analytics/seed_test.go +++ b/pkg/analytics/seed_test.go @@ -36,7 +36,7 @@ func createMemberlist(t *testing.T, port, memberID int) *memberlist.KV { var cfg memberlist.KVConfig flagext.DefaultValues(&cfg) cfg.TCPTransport = memberlist.TCPTransportConfig{ - BindAddrs: []string{"0.0.0.0"}, + BindAddrs: []string{"127.0.0.1"}, BindPort: 0, } cfg.GossipInterval = 100 * time.Millisecond diff --git a/pkg/chunkenc/memchunk_test.go b/pkg/chunkenc/memchunk_test.go index 593b3d7de224f..151ad846ec041 100644 --- a/pkg/chunkenc/memchunk_test.go +++ b/pkg/chunkenc/memchunk_test.go @@ -714,6 +714,7 @@ func TestChunkStats(t *testing.T) { if err != nil { t.Fatal(err) } + //nolint:revive for it.Next() { } if err := it.Close(); err != nil { @@ -742,6 +743,7 @@ func TestChunkStats(t *testing.T) { if err != nil { t.Fatal(err) } + //nolint:revive for it.Next() { } if err := it.Close(); err != nil { diff --git a/pkg/compactor/compactor_test.go b/pkg/compactor/compactor_test.go index 79159d06d8284..854339ca6ecaf 100644 --- a/pkg/compactor/compactor_test.go +++ b/pkg/compactor/compactor_test.go @@ -21,6 +21,7 @@ import ( ) const indexTablePrefix = "table_" +const localhost = "localhost" func dayFromTime(t model.Time) config.DayTime { parsed, err := time.Parse("2006-01-02", t.Time().In(time.UTC).Format("2006-01-02")) @@ -41,6 +42,7 @@ func setupTestCompactor(t *testing.T, objectClients map[config.DayTime]client.Ob flagext.DefaultValues(&cfg) cfg.WorkingDirectory = filepath.Join(tempDir, workingDirName) cfg.RetentionEnabled = false + cfg.CompactorRing.InstanceAddr = localhost if loopbackIFace, err := loki_net.LoopbackInterfaceName(); err == nil { cfg.CompactorRing.InstanceInterfaceNames = append(cfg.CompactorRing.InstanceInterfaceNames, loopbackIFace) diff --git a/pkg/distributor/instance_count_test.go b/pkg/distributor/instance_count_test.go index 1103bc82f4a6a..92abf94c45061 100644 --- a/pkg/distributor/instance_count_test.go +++ b/pkg/distributor/instance_count_test.go @@ -102,6 +102,8 @@ func TestInstanceCountDelegate_CorrectlyInvokesOtherDelegates(t *testing.T) { delegate = &sentryDelegate{BasicLifecyclerDelegate: delegate, calls: sentry2} // sentry delegate AFTER newHealthyInstancesDelegate ringCfg := &RingConfig{} + ringCfg.InstanceAddr = "localhost" + logger := log.With(util_log.Logger, "component", "lifecycler") lifecyclerCfg, err := ringCfg.ToBasicLifecyclerConfig(logger) require.NoError(t, err) diff --git a/pkg/iter/entry_iterator_test.go b/pkg/iter/entry_iterator_test.go index 83bf6cbdd9f44..c900f898f1be4 100644 --- a/pkg/iter/entry_iterator_test.go +++ b/pkg/iter/entry_iterator_test.go @@ -606,6 +606,7 @@ func Test_DuplicateCount(t *testing.T) { _, ctx := stats.NewContext(context.Background()) it := NewMergeEntryIterator(ctx, test.iters, test.direction) defer it.Close() + //nolint:revive for it.Next() { } require.Equal(t, test.expectedDuplicates, stats.FromContext(ctx).Result(0, 0, 0).TotalDuplicates()) diff --git a/pkg/logql/range_vector_test.go b/pkg/logql/range_vector_test.go index 35bfdd2e72749..089bcff9e266a 100644 --- a/pkg/logql/range_vector_test.go +++ b/pkg/logql/range_vector_test.go @@ -368,6 +368,7 @@ func Test_RangeVectorIteratorBadLabels(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) go func() { defer cancel() + //nolint:revive for it.Next() { } }() @@ -410,6 +411,7 @@ func Test_InstantQueryRangeVectorAggregations(t *testing.T) { 3, 1, start, end, 0) require.NoError(t, err) + //nolint:revive for it.Next() { } _, value := it.At() diff --git a/pkg/loki/modules_test.go b/pkg/loki/modules_test.go index a1cb7335cdcf9..19980e2944120 100644 --- a/pkg/loki/modules_test.go +++ b/pkg/loki/modules_test.go @@ -396,6 +396,8 @@ func minimalWorkingConfig(t *testing.T, dir, target string, cfgTransformers ...f cfg.Distributor.DistributorRing.InstanceAddr = localhost cfg.IndexGateway.Mode = indexgateway.SimpleMode cfg.IndexGateway.Ring.InstanceAddr = localhost + cfg.BloomCompactor.Ring.InstanceAddr = localhost + cfg.BloomGateway.Ring.InstanceAddr = localhost cfg.CompactorConfig.CompactorRing.InstanceAddr = localhost cfg.CompactorConfig.WorkingDirectory = path.Join(dir, "compactor") diff --git a/pkg/querier/querier_test.go b/pkg/querier/querier_test.go index fd21ee47d063b..4c8ee491cde61 100644 --- a/pkg/querier/querier_test.go +++ b/pkg/querier/querier_test.go @@ -426,6 +426,7 @@ func TestQuerier_IngesterMaxQueryLookback(t *testing.T) { require.Nil(t, err) // since streams are loaded lazily, force iterators to exhaust + //nolint:revive for res.Next() { } queryClient.AssertExpectations(t) diff --git a/pkg/storage/batch_test.go b/pkg/storage/batch_test.go index 0e39edd86b625..1df906f7dcf2b 100644 --- a/pkg/storage/batch_test.go +++ b/pkg/storage/batch_test.go @@ -1742,6 +1742,7 @@ func TestBatchCancel(t *testing.T) { it, err := newLogBatchIterator(ctx, s, NilMetrics, chunks, 1, newMatchers(fooLabels.String()), log.NewNoopPipeline(), logproto.FORWARD, from, time.Now(), nil) require.NoError(t, err) defer require.NoError(t, it.Close()) + //nolint:revive for it.Next() { } require.Equal(t, context.Canceled, it.Error()) diff --git a/pkg/storage/chunk/client/local/boltdb_index_client_test.go b/pkg/storage/chunk/client/local/boltdb_index_client_test.go index 6e23bdbbaade3..2b26b5cc32cf9 100644 --- a/pkg/storage/chunk/client/local/boltdb_index_client_test.go +++ b/pkg/storage/chunk/client/local/boltdb_index_client_test.go @@ -299,6 +299,7 @@ func Benchmark_Query(b *testing.B) { for i := 0; i < b.N; i++ { err = indexClient.query(context.Background(), entry, func(_ index.Query, read index.ReadBatchResult) bool { iter := read.Iterator() + //nolint:revive for iter.Next() { } return true diff --git a/tools/tsdb/tsdb-map/main_test.go b/tools/tsdb/tsdb-map/main_test.go index 480c723431e22..bf8c802db8456 100644 --- a/tools/tsdb/tsdb-map/main_test.go +++ b/tools/tsdb/tsdb-map/main_test.go @@ -73,6 +73,7 @@ func BenchmarkQuery_PostingsForMatchers(b *testing.B) { for i := 0; i < b.N; i++ { p, _ := tsdb.PostingsForMatchers(reader, nil, bm.matchers...) + //nolint:revive for p.Next() { } }