Skip to content

quick fix to update the default TTL from 7 days to 14 days#1136

Open
ajzobro wants to merge 1 commit into
mainfrom
feature/quickfix-extend-data-ttl
Open

quick fix to update the default TTL from 7 days to 14 days#1136
ajzobro wants to merge 1 commit into
mainfrom
feature/quickfix-extend-data-ttl

Conversation

@ajzobro

@ajzobro ajzobro commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Description

  • Problem: Jobs, logs, artifacts, agents, and advertised queues could expire after 7 days, which is too short for reservations that remain active beyond that window. This could make agents or jobs disappear while still relevant to a reservation.
  • Approach: Increased the shared default MongoDB TTL in server/src/testflinger/database.py from 7 days to 14 days and updated the related index comments to match. The existing TTL index structure is unchanged; only the expiration duration is extended.

Resolved issues

N/A

Documentation

N/A — this is an internal TTL configuration change in the server database setup. No public documentation changes are required.

Web service API changes

  • No new or changed web service endpoints.

… agents and jobs from disappearing within a given reservation time
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.90%. Comparing base (099dd1f) to head (bb92788).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1136   +/-   ##
=======================================
  Coverage   77.90%   77.90%           
=======================================
  Files         118      118           
  Lines       12350    12350           
  Branches     1018     1018           
=======================================
  Hits         9621     9621           
  Misses       2508     2508           
  Partials      221      221           
Flag Coverage Δ *Carryforward flag
agent 75.78% <ø> (ø) Carriedforward from 099dd1f
cli 91.85% <ø> (ø) Carriedforward from 099dd1f
device 63.76% <ø> (ø) Carriedforward from 099dd1f
server 88.99% <100.00%> (ø)

*This pull request uses carry forward flags. Click here to find out more.

Components Coverage Δ
Agent 75.78% <ø> (ø)
CLI 91.85% <ø> (ø)
Common ∅ <ø> (∅)
Device Connectors 63.76% <ø> (ø)
Server 88.99% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Pull request overview

This PR increases the server’s default MongoDB TTL window from 7 days to 14 days to reduce the likelihood that jobs/logs/artifacts/agents/advertised queues expire while still relevant to longer-running reservations.

Changes:

  • Updated the shared DEFAULT_EXPIRATION TTL constant from 7 days to 14 days.
  • Updated inline comments describing TTL behavior to match the new 14-day expiration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 80 to 85
def create_indexes():
"""Initialize collections and indexes in case they don't exist already."""
# Automatically expire jobs after 7 days if nothing runs them
# Automatically expire jobs after 14 days if nothing runs them
mongo.db.jobs.create_index(
"created_at", expireAfterSeconds=DEFAULT_EXPIRATION
)
Comment on lines +92 to 95
# Remove logs after 14 days
mongo.db.logs.create_index(
"updated_at", expireAfterSeconds=DEFAULT_EXPIRATION
)
Comment on lines +97 to 103
# Remove artifacts after 14 days
mongo.db["fs.chunks"].create_index(
"uploadDate", expireAfterSeconds=DEFAULT_EXPIRATION
)
mongo.db["fs.files"].create_index(
"uploadDate", expireAfterSeconds=DEFAULT_EXPIRATION
)
Comment on lines +105 to 108
# Remove agents that haven't checked in for 14 days
mongo.db.agents.create_index(
"updated_at", expireAfterSeconds=DEFAULT_EXPIRATION
)
Comment on lines +110 to 113
# Remove advertised queues that haven't updated in over 14 days
mongo.db.queues.create_index(
"updated_at", expireAfterSeconds=DEFAULT_EXPIRATION
)

@rene-oromtz rene-oromtz 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.

Thanks for the quick fix, increasing to 14 days makes sense, following Copilot suggestion, can you please use collMod instead. This is also the suggestion from MongoDB Docs:
https://www.mongodb.com/docs/manual/tutorial/manage-indexes/#modify-an-index

@ajzobro

ajzobro commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

Please use collMod instead. This is also the suggestion from MongoDB Docs: https://www.mongodb.com/docs/manual/tutorial/manage-indexes/#modify-an-index

The issue that I'm having with this suggestion is that the code we have in place appears to be for creating the db schema in cases where it does not yet exist, yet the use of collMod sounds like it is only applicable when the schema is already in place and needs to be modified.

The two cases: create vs modify should be differentiated better and proper hooks be put in place such that they are called at the right time. In a k8s environment, only the very first workload in the pod needs to configure the database, and even then if the database exists the actions would be different than when the database doesn't exist.

@rene-oromtz

Copy link
Copy Markdown
Contributor

I think the proposal of a helper ensure_ttl_index make sense for this scenario.

  1. If it doesn't exist create it
  2. If it does and its the same, do nothing
  3. If it does and it changed, use collMod

Perhaps this could be helpful in case we ever want to tweak any other TTL

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