Skip to content

Apply the documented EventRetentionPeriod setting to event retention - #5974

Open
johnsimons wants to merge 1 commit into
masterfrom
john/events_retention_key
Open

johnsimons wants to merge 1 commit into
masterfrom
john/events_retention_key

Conversation

@johnsimons

Copy link
Copy Markdown
Member

The documented setting for how long event log items are kept is ServiceControl/EventRetentionPeriod. The instance reads and validates it, and the usage report shows it as Retention.EventsHours, but neither persister applies it. Since 5.0.0 the RavenDB persister has read its own ServiceControl/EventsRetentionPeriod key with a 14 day default, and the EF Core persisters copied that key. A customer who sets the documented key keeps 14 days of events, while configuration validation and the usage report suggest their value applies.

Before 5.0 the instance passed its own value to the persister. #3682 moved the setting into the persister's configuration and spelled it with an extra s.

Change

  • PersistenceConfiguration, the base class of both persister configurations, gets ReadEventsRetentionPeriod. It reads EventRetentionPeriod first, then EventsRetentionPeriod, then the persister's default. The RavenDB and EF Core configurations use it.
  • The documented key is parsed with TimeSpan.TryParse, as the instance already does, so a value the instance ignores today does not stop the persister from starting.
  • The instance's Settings also falls back to EventsRetentionPeriod before the 14 day default, so Retention.EventsHours matches the applied retention on installs that set only the older spelling. Validation still applies only to the documented key, so an install whose older-spelling value is outside 1 hour to 200 days still starts.
  • docs/eventlog-design.md names the documented key.
  • Document the usage report contents and add a coverage decision #5944 adds docs/usage-report.md, which describes this mismatch under Retention.EventsHours. That note needs updating once this merges.

Upgrade impact

A customer who set EventRetentionPeriod gets that retention after upgrading. On RavenDB, an item's expiry is set when the item is written, so the new period applies to new events only. Installs that set EventsRetentionPeriod keep their value. This needs a release note.

Testing

  • New tests set each spelling through environment variables and read the settings back: EventsRetentionConfigurationTests (EF Core, runs on SQL Server and PostgreSQL), RavenEventsRetentionConfigurationTests, and EventRetentionPeriodSettingsTests for the instance. Against the old code, the documented-key tests fail on both persisters and the older-spelling test fails for the instance.
  • ServiceControl.UnitTests: 453/453.
  • ServiceControl.Persistence.Tests.SqlServer 655/655 and ServiceControl.Persistence.Tests.PostgreSql 643/643.
  • ServiceControl.Persistence.Tests.RavenDB: 353/355. The two failures happen in SetUp with "Connection refused" from the shared embedded server, hit different tests on each run, pass when run alone, and fail the same way on master.

Existing installs may already have the older EventsRetentionPeriod spelling
set, so keep honouring it as a fallback. The new EventRetentionPeriod name
takes precedence when both are configured.
@johnsimons
johnsimons requested review from warwickschroeder and a balanced review from Copilot October 9, 2026 02:53
@johnsimons johnsimons self-assigned this Oct 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The explicitly supported malformed-value fallback lacks regression coverage in both the persister and instance paths.

2 open findings
What changed in this PR

Aligns event retention with the documented setting while preserving compatibility with the legacy spelling.

Changes:

  • Adds documented-key precedence with legacy fallback.
  • Applies retention consistently across RavenDB, EF Core, and usage reporting.
  • Documents and tests the configuration behavior.
File Description
src/​ServiceControl/​Infrastructure/​Settings/​Settings.cs Adds legacy fallback for reporting.
src/​ServiceControl.UnitTests/​Infrastructure/​Settings/​EventRetentionPeriodSettingsTests.cs Tests instance setting precedence.
src/​ServiceControl.Persistence/​PersistenceConfiguration.cs Centralizes retention-setting resolution.
src/​ServiceControl.Persistence.Tests/​EFCore/​EventsRetentionConfigurationTests.cs Tests EF Core configuration.
src/​ServiceControl.Persistence.Tests.RavenDB/​EventsRetentionConfigurationTests.cs Tests RavenDB configuration.
src/​ServiceControl.Persistence.RavenDB/​RavenPersistenceConfiguration.cs Uses shared retention resolution.
src/​ServiceControl.Persistence.EFCore/​Abstractions/​EFPersistenceConfigurationBase.cs Uses shared retention resolution.
docs/​eventlog-design.md Documents precedence and compatibility.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +64 to +71
[Test]
public void Prefers_the_documented_setting_over_the_existing_spelling()
{
Environment.SetEnvironmentVariable(DocumentedVariable, "3.00:00:00");
Environment.SetEnvironmentVariable(LegacyVariable, "5.00:00:00");

Assert.That(CreateSettings().EventsRetentionPeriod, Is.EqualTo(TimeSpan.FromDays(3)));
}
Comment on lines +29 to +36
[Test]
public void Prefers_the_documented_setting_over_the_existing_spelling()
{
Environment.SetEnvironmentVariable(DocumentedVariable, "3.00:00:00");
Environment.SetEnvironmentVariable(LegacyVariable, "5.00:00:00");

Assert.That(new Settings().EventsRetentionPeriod, Is.EqualTo(TimeSpan.FromDays(3)));
}
@johnsimons
johnsimons requested a review from rbev October 9, 2026 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants