Skip to content

Split runtime from static configuration and use it for request context.#467

Open
albu-diku wants to merge 6 commits intonextfrom
add/runtime-configuration-and-assistants
Open

Split runtime from static configuration and use it for request context.#467
albu-diku wants to merge 6 commits intonextfrom
add/runtime-configuration-and-assistants

Conversation

@albu-diku
Copy link
Contributor

@albu-diku albu-diku commented Feb 20, 2026

The purpose of this change is twofold: first, firm up the notion of a runtime configuration as distinct from the static configuration loaded on disk and second, with this separation enforced, to prepare for further uses of the runtime side.

Note that the need to do this originated with the needs of templates - consider that a user may need a specific locale to be reflected in the ui for example. An observation was made that we already attach runtime properties to configuration (see mig_server_id, the logger) and must be additional work in various places to sidestep those additions.

Opt to do this by making an object which internally keeps a reference
to an underlying configuration object, proxies attribute access to and can thus be used as a substitute in any call stack of logic. Name this RuntimeConfiguration.

Use the split to add a the notion of a context. This idea was independently arrived at by myself and others on the team. With the support in hand, rework email sending to be context aware - that is, one can simply make use of send_email as before. Internally it will check whether sending was previously done (by consulting the context) and skip any construction steps if so.

As a result of this small change, we become able to centrally intercept email sending without threading arguments through multiple levels of the call stack of logic code purely to override email sending and we can do useful general enforcement.

Add a means for tests to check the the number of emails sent and whether an email was sent to a particular recipient. By default, enforce disallowing unexpected outgoing emails. This has the effect of nudging test writers to account for emails as a covered side effect of the logic being exercised. For cases where the email send is not relevant t, there is an escape hatch.

@albu-diku
Copy link
Contributor Author

@rasmunk this is what came of our discussion of the concept the other day :)

@albu-diku albu-diku changed the title Add/runtime configuration and assistants Split runtime from static configuration and use the former for assistants. Feb 20, 2026
@albu-diku albu-diku force-pushed the add/runtime-configuration-and-assistants branch 2 times, most recently from 20a5865 to 7b0193b Compare February 20, 2026 15:51
@albu-diku albu-diku force-pushed the add/runtime-configuration-and-assistants branch 3 times, most recently from d668a66 to 497886e Compare March 4, 2026 15:23
@albu-diku albu-diku changed the title Split runtime from static configuration and use the former for assistants. Split runtime from static configuration and use it for request context. Mar 5, 2026


def send_email(
configuration,
Copy link
Contributor

@rasmunk rasmunk Mar 5, 2026

Choose a reason for hiding this comment

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

One note, I think in general when then underlying receiving implementation starts to utilise the RuntimeConfiguration specific functions such as context_get that the caller should be aware that it is no expecting a standard configuration anyone. So I would think that we would call it runtime_configuration here instead. Especially since the get_configuration_object in the PR allows for the raw instance to be returned instead at this point which could cause a mixup if one was not aware that a different configuration type was expected here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah - that raw argument is not one I'd expect anybody to use normally, and given your mentioning it I'm almost tempted to give it a leading undersco.re It was purely done so that - necessity of the way this is put together currently - the test support code can still grab a raw configuration and wrap it itself.

As for the the naming, yeah I thought abut that too. My instinct was to do that but I chose not to with the feeling it introduces too much inconsistency wrt the rest of the tree at present. See how that argument sits with you - one thing we could to to make this clear is add an assert here to make clear it must be a runtime configuration, and perhaps that threads the needle a little more?

Copy link
Contributor

Choose a reason for hiding this comment

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

A leading underscore on raw and a subsequent instance assertion on the configuration being passed as a transition state is also fine by me . Then when we get the complete split between runtime and static configuration it is reasonable to expect that aconfiguration argument would be a runtime instance in all migrid-sync's functions, since we would call the static one directly when needed.

@albu-diku albu-diku marked this pull request as ready for review March 9, 2026 10:58
This change paves the way adding further runtime specific data to
configuration objects. An instance of a configuration already contains
such data, such as the mig_server_id property when in use by daemons
and a reference to the logger. With needs arising for further runtime
data, make a clear separation between runtime attributes and the
static configuration data clear.

Opt to do this by making an object which internally keeps a reference
to an underlying configuration object, proxies attribute access to it
and can then be used as a drop-in substitute in ay call stack of logic.
Name this RuntimeConfiguration.

Stop short of moving existing runtime properties as of this commit.
…ite.

Use the runtime configuration concept to expose the sending of email to
logic codepaths. This avoids adding an argument at multiple levels of the
call stack of logic code purely to override email sending.

As a result, we are able to centrally intercept email sending. Do this,
and as a consequence sprinkle a bunch of additional assertions into calls
that happen to send email but this side-effect was completely uncovered.

Add a means for tests to check the the number of emails sent and whether
an email was sent to a particular recipient. For cases where the email
sent is not relevant to what is being tested, there is an escape hatch.
@albu-diku albu-diku force-pushed the add/runtime-configuration-and-assistants branch from 5fc0d43 to 58f2dd8 Compare March 11, 2026 14:09
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.

2 participants