Skip to content

Commit

Permalink
Merge pull request #8 from elegaanz/Colmet
Browse files Browse the repository at this point in the history
Colmet
  • Loading branch information
elegaanz committed Mar 7, 2024
2 parents b8e094f + 60b156b commit 7e0a09c
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 25 deletions.
48 changes: 48 additions & 0 deletions colmet.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{ lib, pkgs, config, ... }:

let
cfg-collector = config.services.colmet-collector;
cfg-node = config.services.colmet-node;
auth-file = pkgs.writeText "colmet-opensearch-auth" "admin:admin";
in
with lib;
{
config.environment.systemPackages = with pkgs; [ nur.repos.kapack.colmet ];

#option to enable the colmet collector
options.services.colmet-collector = {
enable = mkEnableOption (mdDoc "Enable the Colmet collector service");
};

#option to enable colmet nodes
options.services.colmet-node = {
enable = mkEnableOption (mdDoc "Enable the Colmet node service");
};

#if colmet-collector is enable
config.systemd.services.colmet-collector = mkIf cfg-collector.enable {
description = "Colmet collector";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" (mkIf config.services.opensearch.enable "opensearch.service") ];
serviceConfig = {
ExecStart = "${pkgs.nur.repos.kapack.colmet}/bin/colmet-collector -vvv " +
"--zeromq-bind-uri tcp://0.0.0.0:5556 " +
"--buffer-size 5000 " +
"--sample-period 3 " +
"--elastic-host https://127.0.0.1:9200 " +
"--elastic-index-prefix colmet_dahu_ " +
"--http-credentials ${auth-file} " +
"--no-check-certificates";
};
};

#if colmet-node is enable
config.systemd.services.colmet-node = mkIf cfg-node.enable {
description = "Colmet node";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" (mkIf config.services.opensearch.enable "opensearch.service") ];
serviceConfig = {
ExecStart = "${pkgs.nur.repos.kapack.colmet}/bin/colmet-node -vvv --zeromq-uri tcp://127.0.0.1:5556";
};
};
}
39 changes: 27 additions & 12 deletions opensearch-mono/composition.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, ... }:
{ pkgs, enable-colmet ? true, enable-vector ? true, ... }:
let
keystore-password = "usAe#%EX92R7UHSYwJ";
truststore-password = "*!YWptTiu3&okU%E9a";
Expand All @@ -13,10 +13,10 @@ in
roles = {
opensearch = { pkgs, config, lib, ... }:
{
imports = [ ../opensearch-dashboards.nix ];
imports = [ ../opensearch-dashboards.nix ../colmet.nix ];

environment.noXlibs = false;
environment.systemPackages = with pkgs; [ opensearch-fixed vector jq ];
environment.systemPackages = with pkgs; [ opensearch-fixed jq ] ++ (if enable-vector then [ vector ] else []);

systemd.services.opensearch.serviceConfig.ExecStartPre = [
"${pkgs.writeShellScript
Expand Down Expand Up @@ -105,9 +105,10 @@ in
];
};


# Vector est système de gestion de logs
services.vector = {
enable = true;
enable = enable-vector;
journaldAccess = true;
settings = {
sources = {
Expand Down Expand Up @@ -140,10 +141,11 @@ in
};
};
};

services.opensearch-dashboards.enable = true;
services.colmet-collector.enable = enable-colmet;
services.colmet-node.enable = enable-colmet;

environment.variables = {
environment.variables = lib.mkIf enable-vector {
# La variable "VECTOR_CONFIG" défini le chemin de la configuration à utiliser quand on
# lance la commande `vector`. Le service Systemd génère une config à partir de `services.vector.settings`
# et s'assure que le service utilise bien ce fichier. Mais il faut aussi indiquer où ce trouve
Expand All @@ -159,6 +161,7 @@ in
dockerPorts.opensearch = [ "5601:5601" "9200:9200" ];

testScript = ''
import time
opensearch.start()
opensearch.wait_for_unit("opensearch.service")
opensearch.wait_for_open_port(9200)
Expand All @@ -167,6 +170,15 @@ in
"curl -k -u admin:admin --fail https://localhost:9200"
)
opensearch.wait_for_unit("opensearch-dashboards.service")
opensearch.wait_for_open_port(5601)
# When starting, opensearch-dashboards binds the port but need some time to start
time.sleep(10)
opensearch.succeed(
"curl --fail http://localhost:5601/"
)
'' + (if enable-vector then ''
opensearch.wait_for_unit("vector.service")
# The inner curl command uses the Opensearch API and JQ to get the name of the Vector index
Expand All @@ -176,10 +188,13 @@ in
opensearch.succeed(
"curl -k -u admin:admin --fail https://localhost:9200/$(curl -k -u admin:admin --fail https://localhost:9200/_stats | jq -r '.indices | keys[]' | grep vector | tail -n 1)/_search | jq '.hits.hits[0]._source'"
)
opensearch.wait_for_unit("opensearch-dashboards.service")
opensearch.succeed(
"curl --fail http://localhost:5601/"
)
'';
'' else "") + (if enable-colmet then ''
# Check that colmet runs…
opensearch.wait_for_unit("colmet-node.service")
opensearch.wait_for_unit("colmet-collector.service")
# That the collector has set up a ZeroMQ server…
opensearch.succeed("netstat -tlnp | grep :5556")
# And that the index was created in OpenSearch
opensearch.succeed("curl -ku admin:admin https://localhost:9200/_cat/indices | grep colmet")
'' else "");
}
109 changes: 97 additions & 12 deletions opensearch-mono/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion opensearch-mono/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
nxc.url = "github:elegaanz/nixos-compose/fix-vde-switch-groups";
kapack.url = "github:oar-team/nur-kapack";
nur.url = "github:nix-community/nur";
};

outputs = { self, nixpkgs, nxc }:
outputs = { self, nixpkgs, nxc, kapack, nur }:
let
system = "x86_64-linux";
in
{
packages.${system} = nxc.lib.compose {
inherit nixpkgs system;
NUR = nur;
repoOverrides = { inherit kapack; };
composition = ./composition.nix;
};

Expand Down

0 comments on commit 7e0a09c

Please sign in to comment.