Skip to content

Commit

Permalink
feat: replace local otel-collector-builder with nixpkgs package (#35)
Browse files Browse the repository at this point in the history
* feat: replace local otel-collector-builder with nixpkgs package

* fix: type in har-to-otel mainProgram attribute

* tests: ignore flake.lock
  • Loading branch information
gaelreyrol authored Dec 21, 2024
1 parent 29f154b commit 9ce071b
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 255 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ result
output
.direnv
*.yaml
tests/flake.lock
7 changes: 3 additions & 4 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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=";
}
```

Expand All @@ -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"; }
];
};
}
Expand Down
44 changes: 30 additions & 14 deletions src/build-support/build-otel-collector.nix
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -70,7 +77,11 @@ stdenv.mkDerivation {

dontUnpack = true;

nativeBuildInputs = [ otelBuilderPackage otelBuilderPackage.go installShellFiles ];
nativeBuildInputs = [
otelBuilderPackage
otelBuilderPackage.go
installShellFiles
];

configurePhase = ''
runHook preConfigure
Expand Down Expand Up @@ -113,7 +124,12 @@ stdenv.mkDerivation {
'';

passthru = {
inherit otelBuilderPackage otelCollectorBuilderConfiguration otelCollectorBuilderModules vendorHash;
inherit
otelBuilderPackage
otelCollectorBuilderConfiguration
otelCollectorBuilderModules
vendorHash
;
};

meta = {
Expand Down
48 changes: 27 additions & 21 deletions src/build-support/mk-otel-collector-builder-configuration.nix
Original file line number Diff line number Diff line change
@@ -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
''
7 changes: 4 additions & 3 deletions src/lib.nix
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
3 changes: 1 addition & 2 deletions src/overlay.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
inputs:

final:
prev:
final: prev:

let
packages = import ./packages inputs final prev;
Expand Down
4 changes: 1 addition & 3 deletions src/packages/default.nix
Original file line number Diff line number Diff line change
@@ -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 { };
Expand Down
35 changes: 19 additions & 16 deletions src/packages/har-to-otel/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{ lib
, python3
, python3Packages
, fetchFromGitHub
, substituteAll
{
lib,
python3,
python3Packages,
fetchFromGitHub,
substituteAll,
}:

python3Packages.buildPythonApplication rec {
Expand All @@ -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
Expand All @@ -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";
};
}
}
70 changes: 0 additions & 70 deletions src/packages/otel-collector-builder.nix

This file was deleted.

33 changes: 18 additions & 15 deletions src/packages/tracepusher/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{ lib
, python3
, python3Packages
, fetchFromGitHub
, substituteAll
{
lib,
python3,
python3Packages,
fetchFromGitHub,
substituteAll,
}:

python3Packages.buildPythonApplication rec {
Expand All @@ -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
Expand All @@ -45,4 +48,4 @@ python3Packages.buildPythonApplication rec {
maintainers = with maintainers; [ gaelreyrol ];
mainProgram = "tracepusher";
};
}
}
16 changes: 10 additions & 6 deletions src/packages/tracetest/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{ lib
, buildNpmPackage
, buildGoModule
, fetchFromGitHub
, installShellFiles
{
lib,
buildNpmPackage,
buildGoModule,
fetchFromGitHub,
installShellFiles,
}:

let
Expand Down Expand Up @@ -43,7 +44,10 @@ buildGoModule rec {

nativeBuildInputs = [ installShellFiles ];

subPackages = [ "cli" "server" ];
subPackages = [
"cli"
"server"
];

ldflags = [
"-s"
Expand Down
Loading

0 comments on commit 9ce071b

Please sign in to comment.