Skip to content

Add last_seen field to SourceSystem model#1820

Merged
hmpf merged 1 commit intomainfrom
start-of-heartbeat
Apr 27, 2026
Merged

Add last_seen field to SourceSystem model#1820
hmpf merged 1 commit intomainfrom
start-of-heartbeat

Conversation

@hmpf
Copy link
Copy Markdown
Contributor

@hmpf hmpf commented Feb 27, 2026

Scope and purpose

For #1160

This only adds the minimum alteration possible to the SourceSystem model. Baby steps!

This pull request

  • changes the database

NOTE!

The last_seen field should be read only in the admin. BUT: if we do that, then suddenly tests fail because the admin stops honoring the exclude = ["user"] in the AddSourceSystemForm (which is used by the admin). WAAT? Visiting the admin shows that the "user" field is shown in the add-form if "last_seen" is read only, and not shown if "last_seen" is editable.

This might be a bug in the Django admin itself, and needs at least its own issue.

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

@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 27, 2026

Test results

    6 files  1 182 suites   2m 22s ⏱️
  862 tests   861 ✅ 1 💤 0 ❌
5 172 runs  5 166 ✅ 6 💤 0 ❌

Results for commit 9e13baa.

♻️ This comment has been updated with latest results.

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.96%. Comparing base (39fceb8) to head (9e13baa).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1820   +/-   ##
=======================================
  Coverage   87.96%   87.96%           
=======================================
  Files         139      139           
  Lines        6848     6849    +1     
=======================================
+ Hits         6024     6025    +1     
  Misses        824      824           

☔ View full report in Codecov by Sentry.
📢 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.

@hmpf hmpf added data model Affects the data model and/or SQL schema API Affects Argus' REST API admin Django admin API v3 Ideas for API v3, backwards incompatible OK frontend Affects frontend labels Feb 27, 2026
@hmpf hmpf self-assigned this Mar 2, 2026
@hmpf hmpf force-pushed the start-of-heartbeat branch 3 times, most recently from 3775cb1 to 9cdf079 Compare April 24, 2026 06:37
@hmpf hmpf marked this pull request as ready for review April 24, 2026 06:38
@hmpf
Copy link
Copy Markdown
Contributor Author

hmpf commented Apr 24, 2026

Different PRs:

  • API changes, when source says anything, update last seen
  • API changes, separate endpoint for heart beat
  • Changes in frontend
  • Docs, when API changes are in

@hmpf hmpf requested review from a team and aleksfl April 24, 2026 06:47
@hmpf hmpf added the nonews No news fragment is necessary for this PR (e.g. refactoring, cleanups, workflow/development changes) label Apr 24, 2026
Copy link
Copy Markdown
Contributor

@aleksfl aleksfl left a comment

Choose a reason for hiding this comment

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

Looks good, not much to comment.

Comment thread src/argus/incident/admin.py Outdated
@hmpf hmpf requested a review from johannaengland April 24, 2026 08:15
help_text="Base url to combine with an incident's relative url to point to more info in the source system.",
blank=True,
)
last_seen = models.DateTimeField(null=True, blank=True)
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.

Should this field also have help text, e.g. "Timestamp of last seen heartbeat" ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

At this point it is not strictly a heartbeat =)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There will never under any circumstances be a form field for this field, so in that context, a help text is never needed.

text_input_form_fields = ("name",)
raw_id_fields = ("user",)
readonly_fields = ("last_seen",)
date_hierarchy = "last_seen"
Copy link
Copy Markdown
Contributor

@Simrayz Simrayz Apr 24, 2026

Choose a reason for hiding this comment

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

How will this behave when most values are initially null?
Edit: Meant to only mark line 63

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.

You can test it yourself in the admin - nothing is different until it is set for at least one source and then you can navigate into the different dates and if you click on "All dates" then the ones without a date are shown

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.

The easiest way to test is to remove line 62 at first and set last_seen for some source

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Well, having it in readonly_fields breaks things so spectacularly that I've had to remove it.

Having it in date_hierarchy works fine. If last_seen is set on at least one source, the date hierarchy is generated and shown. If not, the hierarchy is hidden.

@hmpf hmpf mentioned this pull request Apr 24, 2026
8 tasks
@hmpf hmpf force-pushed the start-of-heartbeat branch from 83ca9fb to 1fa9963 Compare April 27, 2026 06:47
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 27, 2026

Test naming convention

All new test names follow the convention. 👍

@hmpf hmpf force-pushed the start-of-heartbeat branch 2 times, most recently from 93b526f to 3542fc3 Compare April 27, 2026 07:50
@hmpf hmpf force-pushed the start-of-heartbeat branch from 3542fc3 to 9e13baa Compare April 27, 2026 07:50
@sonarqubecloud
Copy link
Copy Markdown

@hmpf hmpf merged commit f5033fb into main Apr 27, 2026
17 checks passed
@hmpf hmpf deleted the start-of-heartbeat branch April 27, 2026 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

admin Django admin API v3 Ideas for API v3, backwards incompatible OK API Affects Argus' REST API data model Affects the data model and/or SQL schema frontend Affects frontend nonews No news fragment is necessary for this PR (e.g. refactoring, cleanups, workflow/development changes)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants