feat: Use supervisor when running tedge-agent/tedge-mapper#4244
Conversation
1937e68 to
b3cf23b
Compare
b3cf23b to
e865a13
Compare
Robot Results
|
|
@reubenmiller To me it seems to be a behaviour/feature change, not a refactoring (which ideally shouldn't change behaviour) |
yeah you're write, I just couldn't find a better label, so maybe we're missing something. Update: I've created a new "theme:runtime" label |
Bravo555
left a comment
There was a problem hiding this comment.
I see there are some unit tests in the tedge_supervisor crate, to make sure its API works as expected, but I'd also like to see system tests to make sure that tedge-mapper and tedge-agent actually use the supervisor correctly and exhibit the new behaviour we expect, because if I understand correctly, currently we don't seem to be checking that.
Bravo555
left a comment
There was a problem hiding this comment.
All the changes seem correct, nothing to complain about, but I do believe some system tests would be necessary here.
And just some thoughts about specs: having scenarios and requirements in spec.mds would be really, really nice if there was some neat way to reference the specs in any test (unit or system test) and then you could find backlinks to that requirement so you could easily see from the spec document itself the tests that cover its requirements.
|
|
||
| - SIGUSR1 mapper restart for standalone processes — this signal is meaningful only when the agent and mapper share a process, where it allows restarting the mapper without restarting the agent. A standalone mapper has nothing to coordinate with. | ||
| - Changing the `build()` factory contract — standalone and `tedge run all` paths continue to share the same factory | ||
| - Replacing systemd restart semantics — the supervisor's crash recovery complements systemd, it does not replace it |
There was a problem hiding this comment.
thought: Yeah, I was curious about that - I see in the last section that when we run tedge-mapper/tedge-agent using the supervisor and as a systemd unit, the service can restart up to supervisor × systemd times, because systemd doesn't know about restarting the supervisor does, but it's ok because supervisor restarting is faster and loses less state.
Though now there's probably no reason to, we could always make them both aware of each other. The supervisor could check INVOCATION_ID, which is set by systemd when running as a unit and disable restarts if we wish to add that type of configuration, and similarly we could also potentially support systemctl reload command since we now handle SIGHUP to reload log levels. But that's outside the scope of this PR and for future consideration.
| [[package]] | ||
| name = "quinn-udp" | ||
| version = "0.5.12" | ||
| version = "0.5.14" |
Added in 39aa1f1 |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
Move the supervisor implementation from crates/core/tedge/src/supervisor.rs to crates/common/tedge_supervisor/src/lib.rs so it can be reused by tedge-agent and tedge-mapper as standalone processes. Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Extract the supervisor into its own tedge_supervisor crate and add support for running tedge-agent and tedge-mapper as standalone supervised processes, in addition to the existing multi-unit mode. Signed-off-by: James Rhodes <jarhodes314@gmail.com>
af36fa5 to
71c80e0
Compare
Bravo555
left a comment
There was a problem hiding this comment.
I see we also changed the crash of standalone components (i.e. only mapper or only agent) to not recover using supervisor but proceed to crash and be restarted by the init system; that is fine.
Tests were added, so approving.
rina23q
left a comment
There was a problem hiding this comment.
Approved, the system tests are convincing.
albinsuresh
left a comment
There was a problem hiding this comment.
Solid work. Well documented with extensive test coverage as well.
I just noticed one bug: The mapper mapper component is getting restarted by the systemctl kill --signal=SIGUSR1 tedge-mapper-c8y command, despite the specs hinting otherwise.
| A supervised component that requires a restart (after a self-update, or an update | ||
| of its own configuration) SHALL cause the supervisor to drain every component and | ||
| exit the process with a non-zero code, since only re-executing the binary makes | ||
| such an update effective. |
There was a problem hiding this comment.
I'm assuming we were forced to handle action = "restart-agent" this way due to the current contract of the await-agent-restart. For a self-update, this makes sense as the entire tedge binary is updated. But for a config_update that only affects the tedge-agent, this isn't ideal. We might have to rethink this in future where an agent restart can be handled as just the actor restart without affecting all other mappers.
| # mapper fails fast on the lock, so this does not block. | ||
| Execute Command tedge-mapper c8y exp_exit_code=!0 | ||
|
|
||
| A config update restarting the agent restarts the whole process |
There was a problem hiding this comment.
We'll have to rethink the config_update workflow itself to not expect a service restart but only a reload once the single process mode becomes the norm and tedge.toml updates are also handled by it.
| Service Log Should Not Contain tedge-agent EntityStoreServer: recv date_from=${after} | ||
| [Teardown] Remove Log Override | ||
|
|
||
|
|
There was a problem hiding this comment.
How about an additional test that validates that SIGUSR1 signal has no effect in the standalone mode?
|
|
||
| - **WHEN** a standalone process is started with `--log-level`, `--debug`, or `RUST_LOG` | ||
| - **AND** the process receives SIGHUP | ||
| - **THEN** the signal is logged as ignored and log levels remain unchanged |
There was a problem hiding this comment.
I understand why the current impl gives precedence to the cli overrides over the value defined in the system.toml. But from a user's pov, it feels counterintuitive. Shouldn't a runtime update get precedence over settings that the process was started with? Since a runtime action implies explicit user intent to override the existing settings, irrespective of what was specified on startup? Otherwise there's no way to override the values passed in the cli, right?
Proposed changes
Use the supervisor for running a single-process tedge-agent/tedge-mapper. This means we get log reloading on SIGHUP.
For these processes, the supervisor doesn't attempt to restart the process on failure unlike in tedge run all, as we assume there is an init system in place to restart the process, and an internal restart will mask issues where the process is in a crash loop. We don't do anything on SIGUSR1 for these processes, unlike
tedge run allwhere we restart the mappers.When reviewing, you probably want to look at the second commit onwards. The first commit is merely renaming a file (to separate out the supervisor into its own crate), but github doesn't show it as that.
Types of changes
Paste Link to the issue
Checklist
just prepare-devonce)just formatas mentioned in CODING_GUIDELINESjust checkas mentioned in CODING_GUIDELINESFurther comments