-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkibana.nix
114 lines (100 loc) · 3.4 KB
/
kibana.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
{
inputs,
flake-parts-lib,
self,
...
}: {
imports = [
inputs.flake-parts.flakeModules.flakeModules
];
flake.flakeModules.services = {
options.perSystem = flake-parts-lib.mkPerSystemOption ({
lib,
pkgs,
config,
system,
...
}: let
inherit (lib) types mkOption;
inherit (import ../utils.nix {inherit lib;}) mkService;
cfg = config.snow-blower.services.elasticsearch.kibana;
elasticsearchCfg = config.snow-blower.services.elasticsearch;
in {
options.snow-blower.services.elasticsearch.kibana = mkService {
name = "Kibana";
package = self.packages."${system}".kibana;
port = 5601;
extraOptions = {
hosts = mkOption {
description = ''
The URLs of the Elasticsearch instances to use for all your queries.
All nodes listed here must be on the same cluster.
Defaults to <literal>[ "http://localhost:9200" ]</literal>.
This option is only valid when using kibana >= 6.6.
'';
default = [
"http://${elasticsearchCfg.settings.host}:${toString elasticsearchCfg.settings.port}"
];
type = types.nullOr (types.listOf types.str);
};
extraConf = mkOption {
description = "Extra configuration for elasticsearch.";
default = "";
type = types.str;
example = ''
node.name: "elasticsearch"
node.master: true
node.data: false
'';
};
extraCmdLineOptions = mkOption {
description = "Extra command line options for the elasticsearch launcher.";
default = [];
type = types.listOf types.str;
};
};
};
config = lib.mkIf cfg.enable {
snow-blower = {
packages = [
cfg.package
];
env = {
KIBANA_DATA = config.snow-blower.env.PROJECT_STATE + "/kibana";
};
processes.kibana = let
kibanaConfig = ''
server.host: ${cfg.settings.host}
server.port: ${toString cfg.settings.port}
elasticsearch.hosts: [ "http://${elasticsearchCfg.settings.host}:${toString elasticsearchCfg.settings.port}" ]
'';
kibanaYml = pkgs.writeTextFile {
name = "kibana.yml";
text = kibanaConfig;
};
startScript = pkgs.writeShellScript "kibana-startup" ''
set -e
mkdir -p "$KIBANA_DATA"
# Start it
exec ${cfg.package}/bin/kibana --config "${kibanaYml}" --path.data "$KIBANA_DATA" ${toString cfg.settings.extraCmdLineOptions}
'';
in {
exec = "${startScript}";
process-compose = {
readiness_probe = {
exec.command = "${pkgs.curl}/bin/curl -f -k http://${cfg.settings.host}:${toString cfg.settings.port}";
initial_delay_seconds = 15;
period_seconds = 10;
timeout_seconds = 2;
success_threshold = 1;
failure_threshold = 5;
};
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
availability.restart = "on_failure";
};
};
};
};
});
};
}