Update nix configuration (#8452)

Fix nix configuration (mainly failing test), and break up various binaries (ie. logcli, promtail, loki, etc.) into their own pakcages.

---------

Co-authored-by: Trevor Whitney <trevorjwhitney@gmail.com>
pull/11240/head^2
Angus Dippenaar 2 years ago committed by GitHub
parent 8328345a8b
commit 258a8b3108
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      .github/workflows/nix-ci.yaml
  2. 4
      .golangci.yml
  3. 30
      flake.lock
  4. 47
      flake.nix
  5. 50
      nix/default.nix
  6. 28
      nix/overlays/golangci-lint.nix
  7. 25
      nix/overlays/helm-docs.nix
  8. 0
      nix/packages/chart-releaser.nix
  9. 0
      nix/packages/faillint.nix
  10. 44
      nix/packages/loki.nix
  11. 2
      pkg/analytics/seed_test.go
  12. 2
      pkg/chunkenc/memchunk_test.go
  13. 2
      pkg/compactor/compactor_test.go
  14. 2
      pkg/distributor/instance_count_test.go
  15. 1
      pkg/iter/entry_iterator_test.go
  16. 2
      pkg/logql/range_vector_test.go
  17. 2
      pkg/loki/modules_test.go
  18. 1
      pkg/querier/querier_test.go
  19. 1
      pkg/storage/batch_test.go
  20. 1
      pkg/storage/chunk/client/local/boltdb_index_client_test.go
  21. 1
      tools/tsdb/tsdb-map/main_test.go

@ -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

@ -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

@ -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",

@ -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
];
};
});

@ -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
'';
});
};
}

@ -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"
];
});
};
}

@ -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}"
];
});
};
}

@ -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
'';
}

@ -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

@ -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 {

@ -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)

@ -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)

@ -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())

@ -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()

@ -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")

@ -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)

@ -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())

@ -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

@ -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() {
}
}

Loading…
Cancel
Save