Skip to content

Commit 0ac75da

Browse files
committed
Tell collector to watch the .log.1 files to avoid missing records around rotation time.
Add comments around each components filelog receiver settings.
1 parent e19f3fe commit 0ac75da

File tree

7 files changed

+37
-3
lines changed

7 files changed

+37
-3
lines changed

internal/collector/patroni.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ func EnablePatroniLogging(ctx context.Context,
3939
// https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/-/receiver/filelogreceiver#readme
4040
outConfig.Receivers["filelog/patroni_jsonlog"] = map[string]any{
4141
// Read the JSON files and keep track of what has been processed.
42-
"include": []string{directory + "/*.log"},
42+
// When patroni rotates its log files, it renames the old .log file
43+
// to .log.1. We want the collector to ingest logs from both files
44+
// as it is possible that patroni will continue to write a log
45+
// record or two to the old file while rotation is occurring. The
46+
// collector knows not to create duplicate logs.
47+
"include": []string{
48+
directory + "/*.log", directory + "/*.log.1",
49+
},
4350
"storage": "file_storage/patroni_logs",
4451

4552
"operators": []map[string]any{

internal/collector/patroni_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ receivers:
8888
filelog/patroni_jsonlog:
8989
include:
9090
- /pgdata/patroni/log/*.log
91+
- /pgdata/patroni/log/*.log.1
9192
operators:
9293
- from: body
9394
to: body.original
@@ -183,6 +184,7 @@ receivers:
183184
filelog/patroni_jsonlog:
184185
include:
185186
- /pgdata/patroni/log/*.log
187+
- /pgdata/patroni/log/*.log.1
186188
operators:
187189
- from: body
188190
to: body.original

internal/collector/pgadmin.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ func EnablePgAdminLogging(ctx context.Context, spec *v1beta1.InstrumentationSpec
2929
"fsync": true,
3030
}
3131

32+
// PgAdmin/gunicorn logs are rotated by python -- python tries to emit a log
33+
// and if the file needs to rotate, it rotates first and then emits the log.
34+
// The collector therefore only needs to watch the single active log for
35+
// each component.
36+
// https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/-/receiver/filelogreceiver#readme
3237
otelConfig.Receivers["filelog/pgadmin"] = map[string]any{
3338
"include": []string{"/var/lib/pgadmin/logs/pgadmin.log"},
3439
"storage": "file_storage/pgadmin_data_logs",

internal/collector/pgbackrest.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@ func NewConfigForPgBackrestRepoHostPod(
5555
// https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/-/receiver/filelogreceiver#readme
5656
config.Receivers["filelog/pgbackrest_log"] = map[string]any{
5757
// Read the files and keep track of what has been processed.
58+
// We use logrotate to rotate the pgbackrest logs which renames the
59+
// old .log file to .log.1. We want the collector to ingest logs from
60+
// both files as it is possible that pgbackrest will continue to write
61+
// a log record or two to the old file while rotation is occurring.
62+
// The collector knows not to create duplicate logs.
5863
"include": []string{
59-
directory + "/*.log",
64+
directory + "/*.log", directory + "/*.log.1",
6065
},
6166
"storage": "file_storage/pgbackrest_logs",
6267
// pgBackRest prints logs with a log prefix, which includes a timestamp

internal/collector/pgbackrest_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ receivers:
9595
filelog/pgbackrest_log:
9696
include:
9797
- /pgbackrest/repo1/log/*.log
98+
- /pgbackrest/repo1/log/*.log.1
9899
multiline:
99100
line_start_pattern: ^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}|^-{19}
100101
storage: file_storage/pgbackrest_logs
@@ -195,6 +196,7 @@ receivers:
195196
filelog/pgbackrest_log:
196197
include:
197198
- /pgbackrest/repo1/log/*.log
199+
- /pgbackrest/repo1/log/*.log.1
198200
multiline:
199201
line_start_pattern: ^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}|^-{19}
200202
storage: file_storage/pgbackrest_logs

internal/collector/postgres.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ func EnablePostgresLogging(
142142
// https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/-/receiver/filelogreceiver#readme
143143
outConfig.Receivers["filelog/postgres_csvlog"] = map[string]any{
144144
// Read the CSV files and keep track of what has been processed.
145+
// The wildcard covers all potential log file names.
145146
"include": []string{directory + "/*.csv"},
146147
"storage": "file_storage/postgres_logs",
147148

@@ -173,6 +174,7 @@ func EnablePostgresLogging(
173174
// https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/-/receiver/filelogreceiver#readme
174175
outConfig.Receivers["filelog/postgres_jsonlog"] = map[string]any{
175176
// Read the JSON files and keep track of what has been processed.
177+
// The wildcard covers all potential log file names.
176178
"include": []string{directory + "/*.json"},
177179
"storage": "file_storage/postgres_logs",
178180

@@ -238,8 +240,17 @@ func EnablePostgresLogging(
238240
"fsync": true,
239241
}
240242

243+
// https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/-/receiver/filelogreceiver#readme
241244
outConfig.Receivers["filelog/pgbackrest_log"] = map[string]any{
242-
"include": []string{naming.PGBackRestPGDataLogPath + "/*.log"},
245+
// We use logrotate to rotate the pgbackrest logs which renames the
246+
// old .log file to .log.1. We want the collector to ingest logs from
247+
// both files as it is possible that pgbackrest will continue to write
248+
// a log record or two to the old file while rotation is occurring.
249+
// The collector knows not to create duplicate logs.
250+
"include": []string{
251+
naming.PGBackRestPGDataLogPath + "/*.log",
252+
naming.PGBackRestPGDataLogPath + "/*.log.1",
253+
},
243254
"storage": "file_storage/pgbackrest_logs",
244255

245256
// pgBackRest prints logs with a log prefix, which includes a timestamp

internal/collector/postgres_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ receivers:
197197
filelog/pgbackrest_log:
198198
include:
199199
- /pgdata/pgbackrest/log/*.log
200+
- /pgdata/pgbackrest/log/*.log.1
200201
multiline:
201202
line_start_pattern: ^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}|^-{19}
202203
storage: file_storage/pgbackrest_logs
@@ -438,6 +439,7 @@ receivers:
438439
filelog/pgbackrest_log:
439440
include:
440441
- /pgdata/pgbackrest/log/*.log
442+
- /pgdata/pgbackrest/log/*.log.1
441443
multiline:
442444
line_start_pattern: ^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}|^-{19}
443445
storage: file_storage/pgbackrest_logs

0 commit comments

Comments
 (0)