Skip to content

Conversation

@ChrsMark
Copy link
Member

@ChrsMark ChrsMark commented May 27, 2024

Description:

This PR adds the logging part from #31256.
With this addition every time that is identified that file is rotated
either by move/create or copy/truncate, proper logging takes place.

Link to tracking Issue: #31256

Testing:
Updated existing unit tests

How to test this manually

Using the following config:

receivers:
  filelog:
    start_at: beginning
    poll_interval: 5s
    include:
    - /var/log/busybox/monitoring/stable*.log

exporters:
  debug:
    verbosity: detailed

service:
  telemetry:
    logs:
      level: info
  pipelines:
    logs:
      receivers: [filelog]
      exporters: [debug]
      processors: []

Testing truncate (out of pattern)

echo "$(date '+%FT%H:%M:%S.%NZ') some line1" >> /var/log/busybox/monitoring/stable_trunc.log && 
echo "$(date '+%FT%H:%M:%S.%NZ') some line2" >> /var/log/busybox/monitoring/stable_trunc.log &&  
echo "$(date '+%FT%H:%M:%S.%NZ') some line3" >> /var/log/busybox/monitoring/stable_trunc.log && 
sleep 6 && 
cp /var/log/busybox/monitoring/stable_trunc.log /var/log/busybox/monitoring/stable_trunc.log.1 && 
: > /var/log/busybox/monitoring/stable_trunc.log && 
echo "$(date '+%FT%H:%M:%S.%NZ') some line new0" >> /var/log/busybox/monitoring/stable_trunc.log

Testing truncate (in pattern)

echo "$(date '+%FT%H:%M:%S.%NZ') some line1" >> /var/log/busybox/monitoring/stable_trunc.log &&
echo "$(date '+%FT%H:%M:%S.%NZ') some line2" >> /var/log/busybox/monitoring/stable_trunc.log && 
echo "$(date '+%FT%H:%M:%S.%NZ') some line3" >> /var/log/busybox/monitoring/stable_trunc.log &&
sleep 6 &&
cp /var/log/busybox/monitoring/stable_trunc.log /var/log/busybox/monitoring/stable_trunc_1.log &&
: > /var/log/busybox/monitoring/stable_trunc.log &&
echo "$(date '+%FT%H:%M:%S.%NZ') some line new1" >> /var/log/busybox/monitoring/stable_trunc.log

Testing move/create (out of pattern)

echo "$(date '+%FT%H:%M:%S.%NZ') some line1" >> /var/log/busybox/monitoring/stable_trunc.log &&
echo "$(date '+%FT%H:%M:%S.%NZ') some line2" >> /var/log/busybox/monitoring/stable_trunc.log && 
echo "$(date '+%FT%H:%M:%S.%NZ') some line3" >> /var/log/busybox/monitoring/stable_trunc.log &&
sleep 6 &&
mv /var/log/busybox/monitoring/stable_trunc.log /var/log/busybox/monitoring/stable_trunc.log.1 &&
echo "$(date '+%FT%H:%M:%S.%NZ') some line new0" >> /var/log/busybox/monitoring/stable_trunc.log

Testing move/create (in pattern)

echo "$(date '+%FT%H:%M:%S.%NZ') some line1" >> /var/log/busybox/monitoring/stable_trunc.log &&
echo "$(date '+%FT%H:%M:%S.%NZ') some line2" >> /var/log/busybox/monitoring/stable_trunc.log && 
echo "$(date '+%FT%H:%M:%S.%NZ') some line3" >> /var/log/busybox/monitoring/stable_trunc.log &&
sleep 6 &&
mv /var/log/busybox/monitoring/stable_trunc.log /var/log/busybox/monitoring/stable_trunc_1.log &&
echo "$(date '+%FT%H:%M:%S.%NZ') some line new0" >> /var/log/busybox/monitoring/stable_trunc.log

Documentation:
Add some extra notes in the design.md

@github-actions github-actions bot requested a review from djaglowski May 27, 2024 13:13
@ChrsMark ChrsMark force-pushed the add_filelog_logging branch 2 times, most recently from 08f16a6 to b7343dd Compare May 29, 2024 14:42
@ChrsMark ChrsMark force-pushed the add_filelog_logging branch from b7343dd to 147044a Compare May 29, 2024 15:25
@ChrsMark ChrsMark changed the title [wip] [pkg/stanza] log when files are moved/truncated [wip] [pkg/stanza] log when files are rotated/moved/truncated May 29, 2024
@ChrsMark ChrsMark changed the title [wip] [pkg/stanza] log when files are rotated/moved/truncated [pkg/stanza] log when files are rotated/moved/truncated May 29, 2024
@ChrsMark ChrsMark force-pushed the add_filelog_logging branch from 147044a to 8716076 Compare May 29, 2024 15:25
Copy link
Member

@djaglowski djaglowski left a comment

Choose a reason for hiding this comment

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

Should we add actual test cases to make sure we don't regress? We could use zaptest/observer to validated the expected logs.

Copy link
Member

Choose a reason for hiding this comment

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

I suppose it doesn't technically matter but do you think it would be slightly more readable to use oldReader here, simply because we are communicating to the reader about the old file that is no longer here?

@ChrsMark ChrsMark force-pushed the add_filelog_logging branch from 8716076 to 1f74fee Compare May 30, 2024 13:57
Comment on lines 213 to 220
Copy link
Member

Choose a reason for hiding this comment

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

Good explainations. Can I suggest we reverse the order so that we start with the simplest case (move/create within pattern) and progress to the most complex (copy/truncate out of pattern)?

Comment on lines 234 to 238
Copy link
Member

Choose a reason for hiding this comment

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

Here as well, I think move/create is simpler to understand since copy/truncate comes with a possible data loss scenario.

@ChrsMark ChrsMark force-pushed the add_filelog_logging branch 2 times, most recently from a698bda to 5bd7b4d Compare May 31, 2024 13:40
@ChrsMark ChrsMark force-pushed the add_filelog_logging branch from 5bd7b4d to 78f738a Compare May 31, 2024 13:50
@ChrsMark ChrsMark marked this pull request as ready for review May 31, 2024 14:16
@ChrsMark ChrsMark requested review from a team and TylerHelmuth May 31, 2024 14:16
@djaglowski djaglowski merged commit 0978757 into open-telemetry:main May 31, 2024
@github-actions github-actions bot added this to the next release milestone May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants