Skip to content

Use a DurationField for heartbeats#1962

Merged
hmpf merged 2 commits into
mainfrom
duration-field-for-heartbeats
Jun 23, 2026
Merged

Use a DurationField for heartbeats#1962
hmpf merged 2 commits into
mainfrom
duration-field-for-heartbeats

Conversation

@hmpf

@hmpf hmpf commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Scope and purpose

Turns out the math on the database-side gets trickier if we store heartbeat frequency in seconds as an integer. See #1954, compare 78794b0 (IntegerField) with 043f69d (DurationField).

The downside of using a DurationField lies in the frontend forms needing polish, both on display and validation. For that reason, there's an additional commit that shows the frequency in the source pages. This could be split out into its own PR as it needs some polish, especially in the form.

This pull request

  • changes the database

Note that this PR replaces a migration. Before checking out the branch, return to the migration before this one with python manage.py migrate argus_incident 0002_s. Then check out this branch and run migrations as usual.

Doing it as an additional migration would necessitate adding a column, doing a data migration, dropping the old column, renaming the new column to the old name.

Open questions

  • Should we have an upper bound? If so, what? It is currently set to one day.
    Conclusion: yes
  • Should the built-in help-text be changed?
    Good as is, admin is admin.
  • Should the source form help text be changed? If yes, as part of this PR?
    Conclusion: keep as current.
  • Should there be a placeholder in the source form? (In admin is deffo a follow-up issue ;) )
    Conclusion: yes to frontend, laters for admin

If it seems to take too long to agree on looks for the frontend this PR will be split into two, since other features are waiting for the field to exist.

Screenshots

Admin

image

Source list

image

Source-form page

image

Contributor Checklist

Every pull request should have this checklist filled out, no matter how small it is.
More information about contributing to Argus can be found in the
Development docs.

  • Added a changelog fragment for towncrier
  • Added/amended tests for new/changed code
  • Added/changed documentation, including updates to the user manual if feature flow or UI is considerably changed
  • Linted/formatted the code with ruff and djLint, easiest by using pre-commit
  • The first line of the commit message continues the sentence "If applied, this commit will ...", starts with a capital letter, does not end with punctuation and is 50 characters or less long. See our how-to
  • If applicable: Created new issues if this PR does not fix the issue completely/there is further work to be done
  • If this results in changes in the UI: Added screenshots of the before and after
  • If this results in changes to the database model: Updated the ER diagram

@hmpf hmpf added frontend Affects frontend data model Affects the data model and/or SQL schema labels Jun 18, 2026
@hmpf hmpf requested a review from a team June 18, 2026 11:41
@hmpf hmpf moved this from 📋 Backlog to ❓ Ready for review in Argus development, public Jun 18, 2026
@hmpf hmpf self-assigned this Jun 18, 2026
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown

Test results

    8 files  1 736 suites   3m 14s ⏱️
  942 tests   941 ✅ 1 💤 0 ❌
7 536 runs  7 528 ✅ 8 💤 0 ❌

Results for commit 2526843.

♻️ This comment has been updated with latest results.

@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.58%. Comparing base (dedf0dd) to head (2526843).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1962      +/-   ##
==========================================
+ Coverage   88.56%   88.58%   +0.02%     
==========================================
  Files         148      148              
  Lines        7152     7168      +16     
==========================================
+ Hits         6334     6350      +16     
  Misses        818      818              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/argus/incident/models.py
Comment thread src/argus/htmx/templatetags/argus_htmx.py
@hmpf hmpf force-pushed the duration-field-for-heartbeats branch from 78794b0 to 88c2efa Compare June 22, 2026 10:39
@lunkwill42 lunkwill42 self-requested a review June 22, 2026 11:33

@lunkwill42 lunkwill42 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  • Should we have an upper bound? If so, what? It is currently set to one day.

Yes. The whole feature becomes moot if heartbeats are configured to be days apart. 1 days seems fine for now.

  • Should the built-in help-text be changed?

The message seems pretty confusing in the admin interface, but I guess that isn't the primary place for most users to edit after the source list page was added.

  • Should the source form help text be changed? If yes, as part of this PR?

I guess it's formatting is ok for the form as is.

  • Should there be a placeholder in the source form? (In admin is deffo a follow-up issue ;) )

Huh?

My only gripe atm. is that "last seen" for a source is editable in Django admin. Is that intentional?

@hmpf

hmpf commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author
  • Should there be a placeholder in the source form? (In admin is deffo a follow-up issue ;) )

Huh?

A "placeholder" would mean that there is a fake value in the form field to illustrate what the value looks like. This is more work in the admin than in a form we control ourselves.

My only gripe atm. is that "last seen" for a source is editable in Django admin. Is that intentional?

Out of scope. Know problem with the source admin, adding more readonly fields leads to "500 Server Error".

@hmpf hmpf requested a review from lunkwill42 June 22, 2026 13:30
@lunkwill42

Copy link
Copy Markdown
Member

A "placeholder" would mean that there is a fake value in the form field to illustrate what the value looks like. This is more work in the admin than in a form we control ourselves.

Ah, that kind of placeholder (backend engineer laugh) That seems reasonable to ask for (even though the input format seems quite flexible, according to the help text)

hmpf added 2 commits June 23, 2026 14:02
This means easier database queries but trickier frontend display.
@hmpf hmpf force-pushed the duration-field-for-heartbeats branch from 9819f90 to 2526843 Compare June 23, 2026 12:13
@hmpf hmpf marked this pull request as ready for review June 23, 2026 12:14
@hmpf hmpf requested a review from a team June 23, 2026 12:14
@hmpf

hmpf commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

/../ (even though the input format seems quite flexible, according to the help text)

Too flexible, I could have made the table in the frontend much bigger..

@github-project-automation github-project-automation Bot moved this from ❓ Ready for review to 👍 Reviewer approved in Argus development, public Jun 23, 2026
@hmpf hmpf merged commit 980c8e3 into main Jun 23, 2026
20 checks passed
@github-project-automation github-project-automation Bot moved this from 👍 Reviewer approved to ✅ Done in Argus development, public Jun 23, 2026
@hmpf hmpf deleted the duration-field-for-heartbeats branch June 23, 2026 12:49
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data model Affects the data model and/or SQL schema frontend Affects frontend

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants