Skip to content

[monitorlib] Obtain UTMClientSessions via factory rather than direct construction#1413

Merged
mickmis merged 2 commits intointeruss:mainfrom
BenjaminPelletier:client-factory
Apr 9, 2026
Merged

[monitorlib] Obtain UTMClientSessions via factory rather than direct construction#1413
mickmis merged 2 commits intointeruss:mainfrom
BenjaminPelletier:client-factory

Conversation

@BenjaminPelletier
Copy link
Copy Markdown
Member

@BenjaminPelletier BenjaminPelletier commented Apr 8, 2026

This PR implements the concept of #1409 using a factory pattern instead of construction interception (and is an alternative to #1409). Instead of constructing UTMClientSessions directly, a UTMClientSessionFactory singleton is used to obtain the desired UTMClientSessions, and the factory reuses existing UTMClientSessions when possible (when all construction parameters are the same). This partially addresses #1407 and should also increase efficiency by reusing connections more often.

The substantive change in this PR is in infrastructure.py. All other changes should be changing from the UTMClientSession constructor to the singleton factory's get_session method.

@BenjaminPelletier BenjaminPelletier marked this pull request as ready for review April 8, 2026 02:25
return self._sessions[key]


utm_client_session_factory = UTMClientSessionFactory()
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.

nit: I would have made it a class method and just use UTMClientSessionFactory.get_session(..) instead of having that shared variable

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This assumes that it could only ever make sense to have a single UTMClientSessionFactory and that doesn't seem necessarily true. I think it is probably true with the current implementation, but patterns of access (like UTMClientSessionFactory.get_session(..)) are part of the interface rather than the implementation and should therefore generally survive changes in the implementation. Since it doesn't seem necessarily non-sensical to have, e.g., 2 factories, then the choice to have just 1 factory currently doesn't seem like it should be part of the contract/interface of the factory.

Copy link
Copy Markdown
Contributor

@mickmis mickmis left a comment

Choose a reason for hiding this comment

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

LGTM

@mickmis mickmis merged commit e59f147 into interuss:main Apr 9, 2026
22 checks passed
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.

3 participants