Add --days date wrapper argument for easier log collection

Summary

Introduces a new --days parameter that provides a more user-friendly way to specify log collection periods using the last N days, acting as a wrapper around the existing --after-date functionality.

Changes

  • New parameter: --days N collects logs from the last N days
    • --days 1 or --days today: Today's logs only (00:00:00 to 23:59:59)
    • --days 2: Yesterday and today's logs
    • --days 7: Last 7 days including today
  • Input validation: Accepts positive integers and the special string "today"
  • Conflict prevention: Cannot be used together with --after-date or --before-date
  • Disabled method complexity on parse method. (See below)

Method Complexity on parse method

Added RuboCop disable/enable comments around the parse method for:

  • Metrics/AbcSize
  • Metrics/CyclomaticComplexity
  • Metrics/MethodLength
  • Metrics/PerceivedComplexity

The parse method needs to handle many different options, so it's only going to grow in complexity.

Usage Examples

# Collect today's logs only
./gitlabsos.rb --days 1
./gitlabsos.rb --days today

# Collect last week's logs
./gitlabsos.rb --days 7

# Collect last 30 days of logs
./gitlabsos.rb --days 30

Motivation

This change makes it easier for users to collect logs for common time periods without having to calculate specific dates, improving the overall user experience.

How to test

cd /tmp
git clone https://gitlab.com/gitlab-com/support/toolbox/gitlabsos
cd gitlabsos/

git switch date-wrapper

# These cases should succeed
sudo /opt/gitlab/embedded/bin/ruby ./gitlabsos.rb --skip-schema --skip-rake --days today
sudo /opt/gitlab/embedded/bin/ruby ./gitlabsos.rb --skip-schema --skip-rake --days 1
sudo /opt/gitlab/embedded/bin/ruby ./gitlabsos.rb --skip-schema --skip-rake --days 7

# These cases should fail
sudo /opt/gitlab/embedded/bin/ruby ./gitlabsos.rb --skip-schema --skip-rake --days today --after-date 2025-09-20
sudo /opt/gitlab/embedded/bin/ruby ./gitlabsos.rb --skip-schema --skip-rake --days 0
sudo /opt/gitlab/embedded/bin/ruby ./gitlabsos.rb --skip-schema --skip-rake --days -1
sudo /opt/gitlab/embedded/bin/ruby ./gitlabsos.rb --skip-schema --skip-rake --days circle
Edited by Katrin Leinweber

Merge request reports

Loading