tangled
alpha
login
or
join now
tjh.dev
/
nixpkgs
0
fork
atom
Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
0
fork
atom
overview
issues
pulls
pipelines
nixos/vector: Add journald+ClickHouse test
Jonathan Davies
10 months ago
8932afec
64f67b99
+158
2 changed files
expand all
collapse all
unified
split
nixos
tests
vector
default.nix
journald-clickhouse.nix
+1
nixos/tests/vector/default.nix
···
8
8
file-sink = import ./file-sink.nix { inherit system pkgs; };
9
9
api = import ./api.nix { inherit system pkgs; };
10
10
dnstap = import ./dnstap.nix { inherit system pkgs; };
11
11
+
journald-clickhouse = import ./journald-clickhouse.nix { inherit system pkgs; };
11
12
nginx-clickhouse = import ./nginx-clickhouse.nix { inherit system pkgs; };
12
13
syslog-quickwit = import ./syslog-quickwit.nix { inherit system pkgs; };
13
14
}
+157
nixos/tests/vector/journald-clickhouse.nix
···
1
1
+
import ../make-test-python.nix (
2
2
+
{ lib, pkgs, ... }:
3
3
+
let
4
4
+
# Take the original journald message and create a new payload which only
5
5
+
# contains the relevant fields - these must match the database columns.
6
6
+
journalVrlRemapTransform = {
7
7
+
journald_remap = {
8
8
+
inputs = [ "journald" ];
9
9
+
type = "remap";
10
10
+
source = ''
11
11
+
m = {}
12
12
+
m.app = .SYSLOG_IDENTIFIER
13
13
+
m.host = .host
14
14
+
m.severity = to_int(.PRIORITY) ?? 0
15
15
+
m.level = to_syslog_level(m.severity) ?? ""
16
16
+
m.message = strip_ansi_escape_codes!(.message)
17
17
+
m.timestamp = .timestamp
18
18
+
m.uid = to_int(._UID) ?? 0
19
19
+
m.pid = to_int(._PID) ?? 0
20
20
+
. = [m]
21
21
+
'';
22
22
+
};
23
23
+
};
24
24
+
in
25
25
+
{
26
26
+
name = "vector-journald-clickhouse";
27
27
+
meta.maintainers = [ pkgs.lib.maintainers.happysalada ];
28
28
+
29
29
+
nodes = {
30
30
+
clickhouse =
31
31
+
{ config, pkgs, ... }:
32
32
+
{
33
33
+
virtualisation.diskSize = 5 * 1024;
34
34
+
virtualisation.memorySize = 4096;
35
35
+
36
36
+
networking.firewall.allowedTCPPorts = [ 6000 ];
37
37
+
38
38
+
services.vector = {
39
39
+
enable = true;
40
40
+
journaldAccess = true;
41
41
+
42
42
+
settings = {
43
43
+
sources = {
44
44
+
journald = {
45
45
+
type = "journald";
46
46
+
};
47
47
+
48
48
+
vector_source = {
49
49
+
type = "vector";
50
50
+
address = "[::]:6000";
51
51
+
};
52
52
+
};
53
53
+
54
54
+
transforms = journalVrlRemapTransform;
55
55
+
56
56
+
sinks = {
57
57
+
clickhouse = {
58
58
+
type = "clickhouse";
59
59
+
inputs = [
60
60
+
"journald_remap"
61
61
+
"vector_source"
62
62
+
];
63
63
+
endpoint = "http://localhost:8123";
64
64
+
database = "journald";
65
65
+
table = "logs";
66
66
+
date_time_best_effort = true;
67
67
+
};
68
68
+
};
69
69
+
};
70
70
+
71
71
+
};
72
72
+
73
73
+
services.clickhouse = {
74
74
+
enable = true;
75
75
+
};
76
76
+
};
77
77
+
78
78
+
vector =
79
79
+
{ config, pkgs, ... }:
80
80
+
{
81
81
+
services.vector = {
82
82
+
enable = true;
83
83
+
journaldAccess = true;
84
84
+
85
85
+
settings = {
86
86
+
sources = {
87
87
+
journald = {
88
88
+
type = "journald";
89
89
+
};
90
90
+
};
91
91
+
92
92
+
transforms = journalVrlRemapTransform;
93
93
+
94
94
+
sinks = {
95
95
+
vector_sink = {
96
96
+
type = "vector";
97
97
+
inputs = [ "journald_remap" ];
98
98
+
address = "clickhouse:6000";
99
99
+
};
100
100
+
};
101
101
+
};
102
102
+
};
103
103
+
};
104
104
+
};
105
105
+
106
106
+
testScript =
107
107
+
let
108
108
+
# work around quote/substitution complexity by Nix, Perl, bash and SQL.
109
109
+
databaseDDL = pkgs.writeText "database.sql" "CREATE DATABASE IF NOT EXISTS journald";
110
110
+
111
111
+
# https://clickhouse.com/blog/storing-log-data-in-clickhouse-fluent-bit-vector-open-telemetry
112
112
+
tableDDL = pkgs.writeText "table.sql" ''
113
113
+
CREATE TABLE IF NOT EXISTS journald.logs (
114
114
+
timestamp DateTime64(6),
115
115
+
app LowCardinality(String),
116
116
+
host LowCardinality(String),
117
117
+
level LowCardinality(String),
118
118
+
severity UInt8,
119
119
+
message String,
120
120
+
uid UInt16,
121
121
+
pid UInt32,
122
122
+
)
123
123
+
ENGINE = MergeTree()
124
124
+
ORDER BY (host, app, timestamp)
125
125
+
PARTITION BY toYYYYMM(timestamp)
126
126
+
'';
127
127
+
128
128
+
selectQuery = pkgs.writeText "select.sql" ''
129
129
+
SELECT COUNT(host) FROM journald.logs
130
130
+
WHERE message LIKE '%Vector has started%'
131
131
+
'';
132
132
+
in
133
133
+
''
134
134
+
clickhouse.wait_for_unit("clickhouse")
135
135
+
clickhouse.wait_for_open_port(6000)
136
136
+
clickhouse.wait_for_open_port(8123)
137
137
+
138
138
+
clickhouse.succeed(
139
139
+
"cat ${databaseDDL} | clickhouse-client"
140
140
+
)
141
141
+
142
142
+
clickhouse.succeed(
143
143
+
"cat ${tableDDL} | clickhouse-client"
144
144
+
)
145
145
+
146
146
+
for machine in clickhouse, vector:
147
147
+
machine.wait_for_unit("vector")
148
148
+
machine.wait_until_succeeds(
149
149
+
"journalctl -o cat -u vector.service | grep 'Vector has started'"
150
150
+
)
151
151
+
152
152
+
clickhouse.wait_until_succeeds(
153
153
+
"cat ${selectQuery} | clickhouse-client | grep 2"
154
154
+
)
155
155
+
'';
156
156
+
}
157
157
+
)