feat: module level singleton pattern For Pulse instantiation #20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background: If Pulse object is initialized twice it gives us a warning like this:
Overriding of current LoggerProvider is not allowed"
We want the Pulse SDK to be initialized only once per kernel, so that any notebook connected to a kernel has access to a singleton pulse object. This works as expected when a new kernel is started.
However, issues arise when the feature flag (FF) is changed and the notebook page is reloaded. In some cases, the reload starts a new kernel (which is fine), but other times it reconnects to an existing idle kernel. If that kernel was initialized before the FF change, it may not have the correct pulse object, leading to inconsistent behavior.
Since we rely on having a single, correctly-initialized pulse instance per kernel, we need to address this.
Hence, we use module level singleton pattern for Pulse class. where the global state is maintained at the module level.
Testing
Tested locally and test case updated.Pulse is instantiated before also, and when we re-instantiate it again, it skips the reinstantiation with message: Pulse instance already exists. Skipping initialization.

JIRA
https://memsql.atlassian.net/browse/MCDB-74788