feat!: introduce storage abstraction layer - #40
Merged
Conversation
Core services no longer depend on the Elasticsearch bridge. New ActivityLogStorageInterface, CurrentDataTrackerStorageInterface and StorageInitializerInterface in Locastic\Loggastic\Storage decouple the processor, providers, message handlers and console commands from the backend; the default Elasticsearch implementations live in Bridge\Elasticsearch\Storage and are wired via interface aliases. Also moves ElasticNormalizationContextTrait to Serializer\Traits\NormalizationContextTrait, replaces ActivityLogProviderInterface::getActivityLogsByIndexAndId() with ElasticsearchActivityLogStorage::findByIndexAndObjectId(), and removes the broken ActivityLogProvider::getCurrentDataTrackerByClassAndId() and the unused IndexNotFoundException.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Loggastic is hard-wired to Elasticsearch: the data processor, both data providers, the populate handler and the console commands all inject
ElasticsearchServiceInterface,ElasticsearchContextFactoryInterfaceorElasticsearchIndexFactoryInterfacedirectly. There is no way to store activity logs in another backend without forking, and #32 (bridge interfaces) only made the existing Elasticsearch services decoratable. #38 prepared the modern bundle layout so this abstraction could land on top of it.Changes
Locastic\Loggastic\Storagenamespace with three storage-agnostic interfaces:ActivityLogStorageInterface(write/read activity logs),CurrentDataTrackerStorageInterface(save/update/bulk-save/find trackers) andStorageInitializerInterface(create or recreate the underlying storage per loggable class, idempotentinitialize*methods return whether the storage was created)Bridge\Elasticsearch\Storage(ElasticsearchActivityLogStorage,ElasticsearchCurrentDataTrackerStorage,ElasticsearchStorageInitializer), aliased to the interfaces, so existing apps need no configuration changes. Custom backends implement the three interfaces and override the aliases (documented in the README)ActivityLogProcessor,ActivityLogProvider,CurrentDataTrackerProvider,PopulateCurrentDataTrackersHandlerand both console commands now depend on the storage interfaces; their constructor signatures changedActivityLogProviderInterface::getActivityLogsByIndexAndId()(from Add limit and offset to ActivityLogProvider #24) moved toElasticsearchActivityLogStorage::findByIndexAndObjectId(): an index-name-based read is inherently Elasticsearch-specific and does not belong on the storage-agnostic providerElasticNormalizationContextTraitmoved toSerializer\Traits\NormalizationContextTrait; it only forces the\DateTime::ATOMdate format and was the lastBridge\Elasticsearchreference in the logger and update handlerActivityLogProvider::getCurrentDataTrackerByClassAndId(): it declared an?arrayreturn type while the denormalizer returns aCurrentDataTrackerobject, so any call that found a tracker threw aTypeError(CurrentDataTrackerProviderInterfaceprovides the working equivalent)IndexNotFoundException;CreateLoggableIndexesCommandno longer catches the Elasticsearch client exception itself, the "already exists" handling lives in the initializerVerification
locastic:activity-logs:create-loggable-indexesexercised twice end-to-end through the test kernel: first run creates all indexes, second run prints "Index already exists, skipping." for each and exits 0composer validate --strictpasses