Plugin System & Extensibility
Relevant source files
The following files were used as context for generating this wiki page:
The Plugin System & Extensibility module in FLEXT DB Oracle provides a flexible framework for extending the core Oracle database operations library. It allows developers to register custom functionality, track database operations, and record observability metrics through a standardized interface. This architecture follows the Open/Closed principle, enabling the addition of new features like performance monitoring, security auditing, and data validation without modifying the core codebase. Sources: src/README.md:46-51, tests/README.md:95-99
Core Architecture
The extensibility framework is primarily implemented as a service mixin, FlextDbOracleServicePlugin, which is integrated into the FlextDbOracleServices facade. This mixin provides the necessary logic for managing a local service registry of plugins and tracking system health. Sources: src/flext_db_oracle/services/plugin.py:19-24
The diagram above illustrates the class hierarchy where the plugin service acts as a specialized mixin for the main service facade. Sources: src/flext_db_oracle/services/plugin.py:19-24, tests/unit/test_api.py:38-42
Plugin Management
Plugins are managed within a local registry (self._plugins). The system supports registration, unregistration, and retrieval of plugin payloads, which are typically defined as JSON-compatible structures. Sources: src/flext_db_oracle/services/plugin.py:46-60
Key Management Functions
| Function | Purpose | Data Type |
|---|---|---|
register_plugin | Adds a new plugin to the local registry. | p.Result[bool] |
unregister_plugin | Removes a plugin by name. | p.Result[bool] |
fetch_plugin | Retrieves a specific plugin payload. | p.Result[t.JsonPayload] |
list_plugins | Returns a map of all registered plugin names. | p.Result[m.ConfigMap] |
Sources: src/flext_db_oracle/services/plugin.py:46-60, src/flext_db_oracle/services/plugin.py:79-84, src/flext_db_oracle/services/plugin.py:113-120
Registration Workflow
The registration process ensures that all plugins have a valid name before being committed to the internal state. Sources: src/flext_db_oracle/services/plugin.py:79-84
Observability & Metrics
Extensibility extends beyond functional plugins to include a robust metrics and operation tracking system. This allows plugins or core services to record telemetry data. Sources: src/flext_db_oracle/services/plugin.py:27-44
Metrics Recording
The record_metric function allows for the storage of float values associated with a metric name, with optional metadata tags. These tags are normalized before storage to ensure consistency. Sources: src/flext_db_oracle/services/plugin.py:62-77
def record_metric(
self,
name: str,
value: float,
tags: m.ConfigMap | t.JsonMapping | None = None,
) -> p.Result[bool]:
"""Record metric in the local service metrics registry."""
if not name:
return r[bool].fail("Metric name is required")
# ... normalization and storage logic ...
self._metrics[name] = metric_payload
return r[bool].ok(True)
Sources: src/flext_db_oracle/services/plugin.py:62-77
Operation Tracking
Operation tracking provides a way to monitor the execution time and success rate of database commands. It captures the operation type, duration, and associated metadata into an OperationRecord. Sources: src/flext_db_oracle/services/plugin.py:86-111
| Field | Description |
|---|---|
operation_type | The category of the operation (e.g., SELECT, INSERT). |
duration | The time taken to execute the operation. |
success | Boolean indicating if the operation completed without error. |
metadata_info | Additional context such as table names or query hashes. |
Sources: src/flext_db_oracle/services/plugin.py:97-105
Integration with FLEXT Core
The plugin system is tightly integrated with FLEXT Core patterns, utilizing Railway-Oriented Programming (ROP) for error handling and standard domain models for health reporting. Sources: src/README.md:65-70, src/flext_db_oracle/services/plugin.py:27-31
- Railway-Oriented Programming: Every plugin operation returns a
p.Resultobject, ensuring that failures (like missing plugins) are handled gracefully without exceptions. Sources: src/flext_db_oracle/services/plugin.py:46-51 - Health Status: The
fetch_metricsfunction aggregates connection status, metrics, and timestamps into am.DbOracle.HealthStatusmodel. Sources: src/flext_db_oracle/services/plugin.py:27-40
This sequence demonstrates how the application layer interacts with the service to manage extensions and retrieve observability data. Sources: src/flext_db_oracle/services/plugin.py:27-40, tests/unit/test_api.py:228-245
Conclusion
The Plugin System & Extensibility module provides a centralized mechanism for managing enhancements to FLEXT DB Oracle. By leveraging mixins and a structured registry, it maintains a clean separation of concerns while offering comprehensive observability and extension points for enterprise database operations. Sources: src/README.md:121-125, src/flext_db_oracle/services/plugin.py:11-16