Skip to content

Tell collector to watch the .log.1 files to avoid missing records aro… #4135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/collector/patroni.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ func EnablePatroniLogging(ctx context.Context,
// https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/-/receiver/filelogreceiver#readme
outConfig.Receivers["filelog/patroni_jsonlog"] = map[string]any{
// Read the JSON files and keep track of what has been processed.
"include": []string{directory + "/*.log"},
// When patroni rotates its log files, it renames the old .log file
// to .log.1. We want the collector to ingest logs from both files
// as it is possible that patroni will continue to write a log
// record or two to the old file while rotation is occurring. The
// collector knows not to create duplicate logs.
"include": []string{
directory + "/*.log", directory + "/*.log.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think extra security here is fine, though I think Patroni's filehandler inherits the Python rotating behavior: queue a log to emit; check if you have to rotate; rotate if necessary; finish emitting the log.

},
"storage": "file_storage/patroni_logs",

"operators": []map[string]any{
Expand Down
2 changes: 2 additions & 0 deletions internal/collector/patroni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ receivers:
filelog/patroni_jsonlog:
include:
- /pgdata/patroni/log/*.log
- /pgdata/patroni/log/*.log.1
operators:
- from: body
to: body.original
Expand Down Expand Up @@ -183,6 +184,7 @@ receivers:
filelog/patroni_jsonlog:
include:
- /pgdata/patroni/log/*.log
- /pgdata/patroni/log/*.log.1
operators:
- from: body
to: body.original
Expand Down
5 changes: 5 additions & 0 deletions internal/collector/pgadmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ func EnablePgAdminLogging(ctx context.Context, spec *v1beta1.InstrumentationSpec
"fsync": true,
}

// PgAdmin/gunicorn logs are rotated by python -- python tries to emit a log
// and if the file needs to rotate, it rotates first and then emits the log.
// The collector therefore only needs to watch the single active log for
// each component.
// https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/-/receiver/filelogreceiver#readme
otelConfig.Receivers["filelog/pgadmin"] = map[string]any{
"include": []string{"/var/lib/pgadmin/logs/pgadmin.log"},
"storage": "file_storage/pgadmin_data_logs",
Expand Down
7 changes: 6 additions & 1 deletion internal/collector/pgbackrest.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ func NewConfigForPgBackrestRepoHostPod(
// https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/-/receiver/filelogreceiver#readme
config.Receivers["filelog/pgbackrest_log"] = map[string]any{
// Read the files and keep track of what has been processed.
// We use logrotate to rotate the pgbackrest logs which renames the
// old .log file to .log.1. We want the collector to ingest logs from
// both files as it is possible that pgbackrest will continue to write
// a log record or two to the old file while rotation is occurring.
// The collector knows not to create duplicate logs.
"include": []string{
directory + "/*.log",
directory + "/*.log", directory + "/*.log.1",
},
"storage": "file_storage/pgbackrest_logs",
// pgBackRest prints logs with a log prefix, which includes a timestamp
Expand Down
2 changes: 2 additions & 0 deletions internal/collector/pgbackrest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ receivers:
filelog/pgbackrest_log:
include:
- /pgbackrest/repo1/log/*.log
- /pgbackrest/repo1/log/*.log.1
multiline:
line_start_pattern: ^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}|^-{19}
storage: file_storage/pgbackrest_logs
Expand Down Expand Up @@ -195,6 +196,7 @@ receivers:
filelog/pgbackrest_log:
include:
- /pgbackrest/repo1/log/*.log
- /pgbackrest/repo1/log/*.log.1
multiline:
line_start_pattern: ^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}|^-{19}
storage: file_storage/pgbackrest_logs
Expand Down
13 changes: 12 additions & 1 deletion internal/collector/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func EnablePostgresLogging(
// https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/-/receiver/filelogreceiver#readme
outConfig.Receivers["filelog/postgres_csvlog"] = map[string]any{
// Read the CSV files and keep track of what has been processed.
// The wildcard covers all potential log file names.
"include": []string{directory + "/*.csv"},
"storage": "file_storage/postgres_logs",

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

Expand Down Expand Up @@ -238,8 +240,17 @@ func EnablePostgresLogging(
"fsync": true,
}

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

// pgBackRest prints logs with a log prefix, which includes a timestamp
Expand Down
2 changes: 2 additions & 0 deletions internal/collector/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ receivers:
filelog/pgbackrest_log:
include:
- /pgdata/pgbackrest/log/*.log
- /pgdata/pgbackrest/log/*.log.1
multiline:
line_start_pattern: ^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}|^-{19}
storage: file_storage/pgbackrest_logs
Expand Down Expand Up @@ -438,6 +439,7 @@ receivers:
filelog/pgbackrest_log:
include:
- /pgdata/pgbackrest/log/*.log
- /pgdata/pgbackrest/log/*.log.1
multiline:
line_start_pattern: ^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}|^-{19}
storage: file_storage/pgbackrest_logs
Expand Down