Skip to content

Alarm client status tracking - #4036

Open
LordIdra wants to merge 8 commits into
ControlSystemStudio:masterfrom
LordIdra:alarm-client-status-tracking
Open

LordIdra wants to merge 8 commits into
ControlSystemStudio:masterfrom
LordIdra:alarm-client-status-tracking

Conversation

@LordIdra

@LordIdra LordIdra commented Nov 24, 2026 •

Copy link
Copy Markdown

Now that I am familiar with all the alarm logic, I have done a refactor which I have wanted to look into for a while; introduce a state tracking system for AlarmClient. Half-and-half technical and UX change which aims to lower architectural complexity, improve performance, move tracking logic out of the UI, reduce potential for bugs, and display the client/server state to the user more clearly.

part of #3995

Closes #4022

Previous behaviour

The alarm server / Kafka state tracking prior to this PR works as follows:

  • Alarmserver connection status is tracked by a heartbeat sent to the root node in Kafka at a predefined interval
  • Kafka connection status is not tracked, nor is it differentiated from the alarm server connection status
    • This means you can have situations like a config loading in front of you with a 'no alarmserver connection' label which is quite confusing
  • When the alarm tree is launched, it waits a configurable predefined duration before rendering the UI
    • This was to avoid overloading the CPU with loads of updates and slowing down initial loading considerably
  • When a component is added/removed, a 'Loading...' label appears
    • Including if you add/remove the component yourself which is a bit confusing
    • It can also appear next to the 'no alarmserver connection' label which is even more confusing
    • I think this is a remnant of a hack implemented when the alarm configuration was meant to be static and not modified from Phoebus but not 100% sure

Changes

I have resolved these issues by consolidating the logic and using some new Kafka features to track the state of the Kafka connection, how much of the config we have loaded, and the state of the alarm server connection, and displaying this clearly to the user.

Why this is an improvement:

  • The alarm tree UI element is immediately loaded as soon as we have caught up with Kafka - the manual timeout no longer needs to be defined and config loading is faster
  • The status labels for the alarm tree and table are consolidated into one label which clearly shows to the user what's going on (this has also simplified the status label logic)
  • The slightly ad-hoc tracking logic is replaced with a cleaner and more useful state machine which is managed in exactly one method (rather than scattered across files)
  • The initial alarm tree loading logic has been simplified and moved into one location (state update)
  • Overall it has allowed me to clean up some code in AlarmTreeView and (I think) make it simpler

Have only touched AlarmTreeConfigView as far as was needed to get it to keep working (as usual with these PRs, as otherwise it requires me to write a lot of duplicate code). Once the alarm config work is mostly done I will revisit it and clean it up, refactor it, or remove it depending on what we agree.

Importantly, the state machine logic does not affect the polling logic, it runs alongside it. Kafka will be continually polled regardless of the state.

snazzy state machine diagram

image

Testing

Test setups:

  • locally hosted Kafka with 1 partition
  • locally hosted Kafka with 1000 partitions
  • locally hosted Kafka with 1000 partitions and 2 brokers

(also tested config loads for our own development setup)

Test cases (tried the below on every setup for the alarm tree):

  • Just played around to see what happened when I took random actions in different scenarios as a user would
  • Repeatedly tested that alarm tree loads correctly once initial updates have come in with different variations on previous states (e.g. stop and restart kafka while loading)
  • Tested random scenarios from below on the alarm table and area panel
  • Tested all edges of the state machine
    • CONNECTING -> LOADING - start kafka, open alarm tree, label changes to Loading
    • CONNECTING -> NO_INITIAL_KAFKA_CONNECTION - don't start kafka, open alarm tree, label changes to No Kafka connection
    • NO_INITIAL_KAFKA_CONNECTION -> LOADING - don't start kafka, open alarm tree, wait for status to be no kafka connection, start kafka, label changes to Loading
    • LOADING -> NO_INITIAL_KAFKA_CONNECTION - start kafka, open alarm tree, label changes to no kafka connection (and then continues loading if you start kafka again)
    • LOADING -> CONNECTED - start kafka, label changes to connected
    • CONNECTED -> NO_ALARMSERVER_CONNECTION - start kafka, don't start alarm server, wait for status to be connected, label changes to No alarmserver connection (since we do not receive a heartbeat)
    • CONNECTED -> NO_KAFKA_CONNECTION - start kafka, wait for status to be connected, stop kafka, label changes to NO_KAFKA_CONNECTION
    • NO_ALARMSERVER_CONNECTION -> CONNECTED - start kafka, don't start alarm server, wait for status to be connected, wait for status to change to No alarmserver connection, start alarmserver, label changes to connected
    • NO_KAFKA_CONNECTION -> CONNECTED - start kafka, wait for status to change to connected, stop kafka, wait for status to change to no kafka connection, start kafka, label changes to connected
    • NO_ALARMSERVER_CONNECTION -> NO_KAFKA_CONNECTION - start kafka but not alarmserver, open alarm tree, wait until label changes to NO_ALARMSERVER_CONNECTION, shut down Kafka, label changes to No kafka connection

Also tested random cases with alarm table + area panel

Related future work

  • Optimise config loading code (most of the time is spent on our own logic, not polling, and I have discovered from profiles that in configs with long paths, a large proportion of the time is spent on a single regex - amongst other potential optimisations)
  • Add a state for CONFIG_DOES_NOT_EXIST and/or allow configs to be auto-detected from Kafka's topic list
  • Update AlarmConfigMonitor to use the new state tracking

@LordIdra LordIdra mentioned this pull request Nov 24, 2026
34 tasks
@georgweiss

Copy link
Copy Markdown
Collaborator

@LordIdra, I like the separation between Kafka and alarm service connection. Good job. However, to better communicate connection errors I would maybe suggest using separate messages in the UI. This would hopefully eliminate the ambiguity between "alarm server" and "kafka", or at least clarify they are not the same.

Personally I would prefer icons (paired with tooltips) to indicate status, I could ask my colleague to create such. But this could be added later.

@LordIdra

Copy link
Copy Markdown
Author

@LordIdra, I like the separation between Kafka and alarm service connection. Good job. However, to better communicate connection errors I would maybe suggest using separate messages in the UI. This would hopefully eliminate the ambiguity between "alarm server" and "kafka", or at least clarify they are not the same.

Personally I would prefer icons (paired with tooltips) to indicate status, I could ask my colleague to create such. But this could be added later.

Thanks!

Please could you clarify on using separate messages in the UI? Currently, when Kafka connection is lost the message is 'No Kafka connection' and when alarm server connection is lost the message is 'No alarm server connection'. (Though, now that you mention it, they use the same background color so may be easily confused).

Yes, I agree the icons + tooltips would be an improvement. It would also be good to display in the tooltip the implication of 'no alarm server connection' (i.e. you can still configure alarms but their status will not update) as obviously operators may not have an appreciation for the difference between Kafka and alarm server. Just let me know on the icons

@georgweiss

Copy link
Copy Markdown
Collaborator

Maybe I should not try to be clever late in the afternoon...
A separation does not make sense as Alarm Server status cannot be determined if Kafka connection is down.

For the time being I think this is ok.

@LordIdra

LordIdra commented Dec 2, 2026

Copy link
Copy Markdown
Author

pushed some very minor fixes to issues found by LLM

@sonarqubecloud

sonarqubecloud Bot commented Dec 2, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
16.3% Duplication on New Code (required ≤ 3%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

This branch has not been deployed

No deployments
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.

AlarmClient status tracking improvements

2 participants