From 9ce071b8db674853a6d3bbeb1f2f570e07e8dbe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Reyrol?= Date: Sat, 21 Dec 2024 17:20:01 +0100 Subject: [PATCH] feat: replace local otel-collector-builder with nixpkgs package (#35) * feat: replace local otel-collector-builder with nixpkgs package * fix: type in har-to-otel mainProgram attribute * tests: ignore flake.lock --- .gitignore | 1 + ReadMe.md | 7 +- src/build-support/build-otel-collector.nix | 44 ++++++--- ...k-otel-collector-builder-configuration.nix | 48 +++++---- src/lib.nix | 7 +- src/overlay.nix | 3 +- src/packages/default.nix | 4 +- src/packages/har-to-otel/default.nix | 35 ++++--- src/packages/otel-collector-builder.nix | 70 ------------- src/packages/tracepusher/default.nix | 33 ++++--- src/packages/tracetest/default.nix | 16 +-- tests/flake.lock | 98 ------------------- tests/flake.nix | 11 ++- 13 files changed, 122 insertions(+), 255 deletions(-) delete mode 100644 src/packages/otel-collector-builder.nix delete mode 100644 tests/flake.lock diff --git a/.gitignore b/.gitignore index dd8eae9..10c7836 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ result output .direnv *.yaml +tests/flake.lock diff --git a/ReadMe.md b/ReadMe.md index 093464c..e318fce 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -10,7 +10,6 @@ ## Packages -- [otel-collector-builder](https://github.com/open-telemetry/opentelemetry-collector/tree/main/cmd/builder) - Generates a custom OpenTelemetry Collector binary based on a given configuration - [tracetest](https://github.com/kubeshop/tracetest) - Build integration and end-to-end tests in minutes using OpenTelemetry and trace-based testing - [tracepusher](https://github.com/agardnerIT/tracepusher) - Generate and push OpenTelemetry Trace data to an OTEL collector in JSON format - [har-to-otel](https://github.com/agardnerIT/tracepusher/tree/main/har-to-otel) - Chrome DevTools HAR file to OpenTelemetry converter @@ -77,10 +76,10 @@ packages.x86_64-linux.default = pkgs.buildOtelCollector { version = "1.0.0"; config = { exporters = [ - { gomod = "go.opentelemetry.io/collector/exporter/debugexporter v0.90.0"; } + { gomod = "go.opentelemetry.io/collector/exporter/debugexporter v0.115.0"; } ]; }; - vendorHash = "sha256-2g0xe9kLJEbgU9m+2jmWA5Gym7EYHlelsyU0hfLViUY="; + vendorHash = "sha256-sq3T9bOWDeJMZD9+LE4nPc9fqF3tkEaGEy4dJ/qgkgA="; } ``` @@ -102,7 +101,7 @@ packages.x86_64-linux.default = pkgs.mkOtelCollectorBuilderConfiguration { version = "1.0.0"; config = { exporters = [ - { gomod = "go.opentelemetry.io/collector/exporter/debugexporter v0.90.0"; } + { gomod = "go.opentelemetry.io/collector/exporter/debugexporter v0.115.0"; } ]; }; } diff --git a/src/build-support/build-otel-collector.nix b/src/build-support/build-otel-collector.nix index 32f8ca4..6abc716 100644 --- a/src/build-support/build-otel-collector.nix +++ b/src/build-support/build-otel-collector.nix @@ -1,25 +1,32 @@ -{ lib -, stdenv -, mkOtelCollectorBuilderConfiguration -, installShellFiles -, otel-collector-builder +{ + lib, + stdenv, + mkOtelCollectorBuilderConfiguration, + installShellFiles, + opentelemetry-collector-builder, }: -{ name ? args'.pname -, vendorHash ? (throw "builOtelCollector: vendorHash is missing") -, otelBuilderPackage ? otel-collector-builder -, meta ? { } -, ... +{ + name ? args'.pname, + vendorHash ? (throw "builOtelCollector: vendorHash is missing"), + otelBuilderPackage ? opentelemetry-collector-builder, + meta ? { }, + ... }@args': let args = removeAttrs args' [ "vendorHash" ]; - otelCollectorBuilderConfiguration = mkOtelCollectorBuilderConfiguration (args // { goPackage = otelBuilderPackage.go; }); + otelCollectorBuilderConfiguration = mkOtelCollectorBuilderConfiguration ( + args // { goPackage = otelBuilderPackage.go; } + ); otelCollectorBuilderModules = stdenv.mkDerivation { pname = "${name}-modules"; inherit (args') version; src = otelCollectorBuilderConfiguration; - nativeBuildInputs = [ otelBuilderPackage otelBuilderPackage.go ]; + nativeBuildInputs = [ + otelBuilderPackage + otelBuilderPackage.go + ]; dontUnpack = true; @@ -70,7 +77,11 @@ stdenv.mkDerivation { dontUnpack = true; - nativeBuildInputs = [ otelBuilderPackage otelBuilderPackage.go installShellFiles ]; + nativeBuildInputs = [ + otelBuilderPackage + otelBuilderPackage.go + installShellFiles + ]; configurePhase = '' runHook preConfigure @@ -113,7 +124,12 @@ stdenv.mkDerivation { ''; passthru = { - inherit otelBuilderPackage otelCollectorBuilderConfiguration otelCollectorBuilderModules vendorHash; + inherit + otelBuilderPackage + otelCollectorBuilderConfiguration + otelCollectorBuilderModules + vendorHash + ; }; meta = { diff --git a/src/build-support/mk-otel-collector-builder-configuration.nix b/src/build-support/mk-otel-collector-builder-configuration.nix index 6276b9c..6fc9dbb 100644 --- a/src/build-support/mk-otel-collector-builder-configuration.nix +++ b/src/build-support/mk-otel-collector-builder-configuration.nix @@ -1,30 +1,36 @@ -{ lib -, writeTextFile -, runCommand -, go -, remarshal +{ + lib, + writeTextFile, + runCommand, + go, + remarshal, }: -{ name ? "${args'.pname}-${args'.version}-builder-configuration" -, config ? { } -, goPackage ? go -, ... +{ + name ? "${args'.pname}-${args'.version}-builder-configuration", + config ? { }, + goPackage ? go, + ... }@args': let jsonFile = writeTextFile { name = "${name}.json"; - text = builtins.toJSON ({ - dist = { - name = args'.pname; - go = "${goPackage}/bin/go"; - output_path = "output"; - }; - } // args'.config); + text = builtins.toJSON ( + { + dist = { + name = args'.pname; + go = "${goPackage}/bin/go"; + output_path = "output"; + }; + } + // args'.config + ); }; in runCommand "${name}.yaml" -{ - nativeBuildInputs = [ remarshal ]; -} '' - ${remarshal}/bin/remarshal ${jsonFile} --of yaml > $out -'' + { + nativeBuildInputs = [ remarshal ]; + } + '' + ${remarshal}/bin/remarshal ${jsonFile} --of yaml > $out + '' diff --git a/src/lib.nix b/src/lib.nix index c31f62e..541145a 100644 --- a/src/lib.nix +++ b/src/lib.nix @@ -1,10 +1,11 @@ inputs: -final: -prev: +final: prev: let - mkOtelCollectorBuilderConfiguration = prev.callPackage ./build-support/mk-otel-collector-builder-configuration.nix { }; + mkOtelCollectorBuilderConfiguration = + prev.callPackage ./build-support/mk-otel-collector-builder-configuration.nix + { }; buildOtelCollector = prev.callPackage ./build-support/build-otel-collector.nix { }; in { diff --git a/src/overlay.nix b/src/overlay.nix index 9f05467..04faa1d 100644 --- a/src/overlay.nix +++ b/src/overlay.nix @@ -1,7 +1,6 @@ inputs: -final: -prev: +final: prev: let packages = import ./packages inputs final prev; diff --git a/src/packages/default.nix b/src/packages/default.nix index 765afa5..44a5c0a 100644 --- a/src/packages/default.nix +++ b/src/packages/default.nix @@ -1,10 +1,8 @@ inputs: -final: -prev: +final: prev: { - otel-collector-builder = prev.callPackage ./otel-collector-builder.nix { }; # Remove when merged: https://github.com/NixOS/nixpkgs/pull/275406 tracetest = prev.callPackage ./tracetest { }; tracepusher = prev.callPackage ./tracepusher { }; diff --git a/src/packages/har-to-otel/default.nix b/src/packages/har-to-otel/default.nix index bc5fb61..ef0273f 100644 --- a/src/packages/har-to-otel/default.nix +++ b/src/packages/har-to-otel/default.nix @@ -1,8 +1,9 @@ -{ lib -, python3 -, python3Packages -, fetchFromGitHub -, substituteAll +{ + lib, + python3, + python3Packages, + fetchFromGitHub, + substituteAll, }: python3Packages.buildPythonApplication rec { @@ -21,15 +22,17 @@ python3Packages.buildPythonApplication rec { patches = [ ./shebang.patch ]; - postPatch = let - setup = substituteAll { - src = ./setup.py; - desc = meta.description; - inherit pname version; - }; - in '' - ln -s ${setup} setup.py - ''; + postPatch = + let + setup = substituteAll { + src = ./setup.py; + desc = meta.description; + inherit pname version; + }; + in + '' + ln -s ${setup} setup.py + ''; propagatedBuildInputs = [ python3Packages.requests @@ -43,6 +46,6 @@ python3Packages.buildPythonApplication rec { homepage = "https://github.com/agardnerIT/tracepusher/tree/main/har-to-otel"; license = licenses.asl20; maintainers = with maintainers; [ gaelreyrol ]; - mainProgrom = "har-to-otel.py"; + mainProgram = "har-to-otel.py"; }; -} \ No newline at end of file +} diff --git a/src/packages/otel-collector-builder.nix b/src/packages/otel-collector-builder.nix deleted file mode 100644 index eb252dc..0000000 --- a/src/packages/otel-collector-builder.nix +++ /dev/null @@ -1,70 +0,0 @@ -{ lib -, buildGoModule -, fetchFromGitHub -, makeWrapper -, installShellFiles -, go -}: - -buildGoModule rec { - pname = "otel-collector-builder"; - version = "0.97.0"; - - src = fetchFromGitHub { - owner = "open-telemetry"; - repo = "opentelemetry-collector"; - rev = "v${version}"; - hash = "sha256-0zTEaSylZEU7mCCrMf9aV8V0MMD4Au4y0zacWSLcujg="; - }; - - sourceRoot = "source/cmd/builder"; - - vendorHash = "sha256-QAtg9mB7+ltIOWzJJ7WIFXVZAWUhEnenwoixpx5b6Rc="; - - nativeBuildInputs = [ makeWrapper installShellFiles ]; - - allowGoReference = false; - - ldflags = [ - "-s" - "-w" - "-X go.opentelemetry.io/collector/cmd/builder/internal.version=${version}" - "-X go.opentelemetry.io/collector/cmd/builder/internal.date=now" - ]; - - CGO_ENABLED = 0; - - installPhase = '' - runHook preInstall - - mkdir -p $out/bin - cp $GOPATH/bin/builder $out/bin/ocb - # wrapProgram $out/bin/ocb \ - # --prefix PATH : ${lib.makeBinPath [ go ]} - - runHook postInstall - ''; - - postInstall = '' - installShellCompletion --cmd ocb \ - --bash <($out/bin/ocb completion bash) \ - --fish <($out/bin/ocb completion fish) \ - --zsh <($out/bin/ocb completion zsh) - ''; - - # GenerateAndCompile test run `go get`. - checkFlags = [ "-skip=TestGenerateAndCompile" ]; - - passthru = { - inherit version go; - }; - - meta = with lib; { - changelog = "https://github.com/open-telemetry/opentelemetry-collector/releases/tag/cmd/builder/v${version}"; - description = "Generates a custom OpenTelemetry Collector binary based on a given configuration"; - homepage = "https://github.com/open-telemetry/opentelemetry-collector/tree/main/cmd/builder"; - license = licenses.asl20; - mainProgram = "ocb"; - maintainers = with maintainers; [ gaelreyrol ]; - }; -} diff --git a/src/packages/tracepusher/default.nix b/src/packages/tracepusher/default.nix index 059a498..2a93d9b 100644 --- a/src/packages/tracepusher/default.nix +++ b/src/packages/tracepusher/default.nix @@ -1,8 +1,9 @@ -{ lib -, python3 -, python3Packages -, fetchFromGitHub -, substituteAll +{ + lib, + python3, + python3Packages, + fetchFromGitHub, + substituteAll, }: python3Packages.buildPythonApplication rec { @@ -21,15 +22,17 @@ python3Packages.buildPythonApplication rec { patches = [ ./shebang.patch ]; - postPatch = let - setup = substituteAll { - src = ./setup.py; - desc = meta.description; - inherit pname version; - }; - in '' - ln -s ${setup} setup.py - ''; + postPatch = + let + setup = substituteAll { + src = ./setup.py; + desc = meta.description; + inherit pname version; + }; + in + '' + ln -s ${setup} setup.py + ''; propagatedBuildInputs = [ python3Packages.requests @@ -45,4 +48,4 @@ python3Packages.buildPythonApplication rec { maintainers = with maintainers; [ gaelreyrol ]; mainProgram = "tracepusher"; }; -} \ No newline at end of file +} diff --git a/src/packages/tracetest/default.nix b/src/packages/tracetest/default.nix index 0277f2f..4839629 100644 --- a/src/packages/tracetest/default.nix +++ b/src/packages/tracetest/default.nix @@ -1,8 +1,9 @@ -{ lib -, buildNpmPackage -, buildGoModule -, fetchFromGitHub -, installShellFiles +{ + lib, + buildNpmPackage, + buildGoModule, + fetchFromGitHub, + installShellFiles, }: let @@ -43,7 +44,10 @@ buildGoModule rec { nativeBuildInputs = [ installShellFiles ]; - subPackages = [ "cli" "server" ]; + subPackages = [ + "cli" + "server" + ]; ldflags = [ "-s" diff --git a/tests/flake.lock b/tests/flake.lock deleted file mode 100644 index 4afc756..0000000 --- a/tests/flake.lock +++ /dev/null @@ -1,98 +0,0 @@ -{ - "nodes": { - "flake-parts": { - "inputs": { - "nixpkgs-lib": "nixpkgs-lib" - }, - "locked": { - "lastModified": 1698882062, - "narHash": "sha256-HkhafUayIqxXyHH1X8d9RDl1M2CkFgZLjKD3MzabiEo=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "8c9fa2545007b49a5db5f650ae91f227672c3877", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1711523803, - "narHash": "sha256-UKcYiHWHQynzj6CN/vTcix4yd1eCu1uFdsuarupdCQQ=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "2726f127c15a4cc9810843b96cad73c7eb39e443", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-lib": { - "locked": { - "dir": "lib", - "lastModified": 1698611440, - "narHash": "sha256-jPjHjrerhYDy3q9+s5EAsuhyhuknNfowY6yt6pjn9pc=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "0cbe9f69c234a7700596e943bfae7ef27a31b735", - "type": "github" - }, - "original": { - "dir": "lib", - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "opentelemetry-nix": { - "inputs": { - "flake-parts": "flake-parts", - "nixpkgs": [ - "nixpkgs" - ], - "systems": "systems" - }, - "locked": { - "lastModified": 0, - "narHash": "sha256-UG1lUmZkrhgEBTSejY+B6jboR7Sw03gU6MpOx6ZvlPo=", - "path": "/nix/store/mdmgxfg3l21k5083i17dp3igpp2r6v8l-source", - "type": "path" - }, - "original": { - "path": "/nix/store/mdmgxfg3l21k5083i17dp3igpp2r6v8l-source", - "type": "path" - } - }, - "root": { - "inputs": { - "nixpkgs": "nixpkgs", - "opentelemetry-nix": "opentelemetry-nix" - } - }, - "systems": { - "locked": { - "lastModified": 1680978846, - "narHash": "sha256-Gtqg8b/v49BFDpDetjclCYXm8mAnTrUzR0JnE2nv5aw=", - "owner": "nix-systems", - "repo": "x86_64-linux", - "rev": "2ecfcac5e15790ba6ce360ceccddb15ad16d08a8", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "x86_64-linux", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/tests/flake.nix b/tests/flake.nix index 3f83818..4928df4 100644 --- a/tests/flake.nix +++ b/tests/flake.nix @@ -7,7 +7,12 @@ }; }; - outputs = { self, nixpkgs, opentelemetry-nix }: + outputs = + { + self, + nixpkgs, + opentelemetry-nix, + }: let system = "x86_64-linux"; pkgs = import nixpkgs { @@ -18,7 +23,7 @@ version = "1.0.0"; config = { exporters = [ - { gomod = "go.opentelemetry.io/collector/exporter/debugexporter v0.97.0"; } + { gomod = "go.opentelemetry.io/collector/exporter/debugexporter v0.115.0"; } ]; }; in @@ -26,7 +31,7 @@ packages.x86_64-linux = { debug-otel-collector = pkgs.buildOtelCollector { inherit pname version config; - vendorHash = "sha256-3PHOiaDs2E07PMS0n2sR3BCFpFCdnKNErGspHwdo/sk="; + vendorHash = "sha256-sq3T9bOWDeJMZD9+LE4nPc9fqF3tkEaGEy4dJ/qgkgA="; }; debug-otel-config = pkgs.mkOtelCollectorBuilderConfiguration { inherit pname version config;