Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request juju#18757 from SimonRichardson/application-config…
…-watcher juju#18757 Adds the application config watchers. There are currently two watchers: 1. Application config watcher as notify watcher 2. Application config hash watcher as a strings watcher To drive these watchers, we need to know when the config has changed. Unfortunately, there are two tables to watch (config and settings), which would require a bit of additional complexity, and to drive the second watcher we would need to compute the hash for every change. Instead, we can invert that model and store the hash when the config has changed. Thus, we only need to watch when the config hash has changed, and that then can drive the watcher correctly. For the notify watcher, we watch the application_config_hash table, for the strings watcher we also watch the same table, but get the hash instead of the UUID for the table and only send one event back. This coalescing ensures that we only send the event once and that the event has the correct sha256 for the config, which is a requirement for the uniter. ---- This pull request introduces several changes to the `domain/application/service` and `domain/application/state` packages to add functionality for managing and watching application configuration hashes. The most important changes include adding methods for retrieving and watching application configuration hashes, updating the state management to handle these hashes, and adding corresponding tests. ### Application Service Enhancements: * Added `InitialWatchStatementApplicationConfigHash` method to `AtomicApplicationState` and `ApplicationState` interfaces to return the initial namespace query for the application config hash watcher. [[1]](diffhunk://#diff-40e92dad177289bb0953c58a7bf643aa27252c1125bdda8628c3b1029996c639R133-R136) [[2]](diffhunk://#diff-40e92dad177289bb0953c58a7bf643aa27252c1125bdda8628c3b1029996c639R297-R302) * Implemented `WatchApplicationConfig` and `WatchApplicationConfigHash` methods in `WatchableService` to watch for changes to the application's config and config hash, respectively. ### State Management Enhancements: * Added `GetApplicationConfigHash` method to retrieve the SHA256 hash of the application config for a specified application ID. * Implemented `InitialWatchStatementApplicationConfigHash` method to return the initial namespace query for the application config hash watcher. * Added `insertApplicationConfigHash` method to insert the application config hash into the database. ### Testing Enhancements: * Added mock methods for `GetApplicationConfigHash` and `InitialWatchStatementApplicationConfigHash` to the mock state in `package_mock_test.go`. [[1]](diffhunk://#diff-b3512b9d5695360184408eef139ff1a37434dff010b323eb51922a0d038f0f0fR298-R336) [[2]](diffhunk://#diff-b3512b9d5695360184408eef139ff1a37434dff010b323eb51922a0d038f0f0fR1868-R1906) * Added tests for `GetApplicationConfigHash` and scenarios where the application is not found in `application_test.go`. ### Miscellaneous: * Updated `CreateApplication` and `SetApplicationConfigAndSettings` methods to handle the insertion and updating of application config hashes. [[1]](diffhunk://#diff-994df01f80f2f62fa018f73b1f15b583e059dd830bda4c524f4824df8764bb08R142-R146) [[2]](diffhunk://#diff-994df01f80f2f62fa018f73b1f15b583e059dd830bda4c524f4824df8764bb08R2521-R2532) * Added utility functions `hashConfigAndSettings` and `encodeConfigValue` to generate SHA256 hashes for application configurations. ## QA Tests pass. ## Links **Jira card:** [JUJU-7414](https://warthogs.atlassian.net/browse/JUJU-7414) [JUJU-7414]: https://warthogs.atlassian.net/browse/JUJU-7414?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
- Loading branch information