Skip to content

Commit

Permalink
fluent-bit: add NixOS module
Browse files Browse the repository at this point in the history
  • Loading branch information
commiterate committed Dec 16, 2024
1 parent 5bc0af1 commit 3a9ac5a
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ci/OWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,13 @@ nixos/modules/installer/tools/nix-fallback-paths.nix @NixOS/nix-team @raitobeza
/nixos/tests/amazon-ssm-agent.nix @arianvp
/nixos/modules/system/boot/grow-partition.nix @arianvp

# Monitoring
/nixos/modules/services/monitoring/fluent-bit.nix @samrose @fpletz
/nixos/tests/fluent-bit.nix @samrose @fpletz

# nixos-rebuild-ng
/pkgs/by-name/ni/nixos-rebuild-ng @thiagokokada


# Updaters
## update.nix
/maintainers/scripts/update.nix @jtojnar
Expand Down
2 changes: 2 additions & 0 deletions nixos/doc/manual/release-notes/rl-2505.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

- [Amazon CloudWatch Agent](https://github.com/aws/amazon-cloudwatch-agent), the official telemetry collector for AWS CloudWatch and AWS X-Ray. Available as [services.amazon-cloudwatch-agent](#opt-services.amazon-cloudwatch-agent.enable).

- [Fluent Bit](https://github.com/fluent/fluent-bit), a fast Log, Metrics and Traces Processor and Forwarder. Available as [services.fluent-bit](#opt-services.fluent-bit.enable).

<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->

## Backward Incompatibilities {#sec-release-25.05-incompatibilities}
Expand Down
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@
./services/monitoring/das_watchdog.nix
./services/monitoring/datadog-agent.nix
./services/monitoring/do-agent.nix
./services/monitoring/fluent-bit.nix
./services/monitoring/fusion-inventory.nix
./services/monitoring/gatus.nix
./services/monitoring/glances.nix
Expand Down
105 changes: 105 additions & 0 deletions nixos/modules/services/monitoring/fluent-bit.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.fluent-bit;

yamlFormat = pkgs.formats.yaml { };

configurationFile =
if (cfg.configurationFile == null) then
(yamlFormat.generate "fluent-bit.yaml" cfg.configuration)
else
cfg.configurationFile;
in
{
options.services.fluent-bit = {
enable = lib.mkEnableOption "Fluent Bit";
package = lib.mkPackageOption pkgs "fluent-bit" { };
configurationFile = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = ''
Fluent Bit configuration. See
<https://docs.fluentbit.io/manual/administration/configuring-fluent-bit/yaml>
for supported values.
{option}`configurationFile` takes precedence over {option}`configuration`.
Note: Restricted evaluation blocks access to paths outside the Nix store.
This means detecting content changes for mutable paths (i.e. not input or content-addressed) can't be done.
As a result, `nixos-rebuild` won't reload/restart the systemd unit when mutable path contents change.
`systemctl restart fluent-bit.service` must be used instead.
'';
example = /etc/fluent-bit/fluent-bit.yaml;
};
configuration = lib.mkOption {
type = yamlFormat.type;
default = { };
description = ''
See {option}`configurationFile`.
{option}`configurationFile` takes precedence over {option}`configuration`.
'';
example = {
service = {
grace = 30;
};
pipeline = {
inputs = [
{
name = "systemd";
systemd_filter = "_SYSTEMD_UNIT=fluent-bit.service";
}
];
outputs = [
{
name = "stdout";
}
];
};
};
};
user = lib.mkOption {
type = lib.types.str;
default = "root";
description = ''
The user that runs Fluent Bit.
'';
example = "fluent-bit";
};
# See https://docs.fluentbit.io/manual/administration/configuring-fluent-bit/yaml/service-section.
grace = lib.mkOption {
type = lib.types.ints.positive;
default = 5;
description = ''
The grace time in `seconds` as an integer value. The engine loop uses a grace timeout to define the wait time before exiting.
The `service.grace` option in the Fluent Bit configuration should be ≤ this option.
'';
example = 30;
};
};

config = lib.mkIf cfg.enable {
# See https://github.com/fluent/fluent-bit/blob/v3.2.2/init/systemd.in.
systemd.services.fluent-bit = {
description = "Fluent Bit";
after = [ "network.target" ];
requires = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
User = cfg.user;
ExecStart = builtins.concatStringsSep " " [
"${cfg.package}/bin/fluent-bit"
"--config ${configurationFile}"
];
TimeoutStopSec = cfg.grace;
Restart = "always";
};
};
};
}
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ in {
flaresolverr = handleTest ./flaresolverr.nix {};
flood = handleTest ./flood.nix {};
floorp = handleTest ./firefox.nix { firefoxPackage = pkgs.floorp; };
fluent-bit = handleTest ./fluent-bit.nix {};
fluentd = handleTest ./fluentd.nix {};
fluidd = handleTest ./fluidd.nix {};
fontconfig-default-fonts = handleTest ./fontconfig-default-fonts.nix {};
Expand Down
40 changes: 40 additions & 0 deletions nixos/tests/fluent-bit.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import ./make-test-python.nix (
{ lib, pkgs, ... }:
{
name = "fluent-bit";

nodes.machine =
{ config, pkgs, ... }:
{
services.fluent-bit = {
enable = true;
configuration = {
pipeline = {
inputs = [
{
name = "systemd";
systemd_filter = "_SYSTEMD_UNIT=fluent-bit.service";
}
];
outputs = [
{
name = "file";
path = "/var/log/fluent-bit";
file = "fluent-bit.out";
}
];
};
};
};

systemd.services.fluent-bit.serviceConfig.LogsDirectory = "fluent-bit";
};

testScript = ''
start_all()
machine.wait_for_unit("fluent-bit.service")
machine.wait_for_file("/var/log/fluent-bit/fluent-bit.out")
'';
}
)

0 comments on commit 3a9ac5a

Please sign in to comment.