feat: Add persistent storage support for Redis and APCu (v0.4.0)
All checks were successful
Create Release Package / build-release (push) Successful in 56s

- Add StorageFactory class for storage adapter selection with fallback
- Support Redis storage for shared metrics across instances
- Support APCu storage for high-performance single-server deployments
- Add Storage tab in admin settings with configuration UI
- Add connection testing for Redis and APCu adapters
- Support environment variables for Docker/containerized deployments
- Update Collector to use StorageFactory instead of hardcoded InMemory
- Add all translations (English and German)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-02 16:15:53 +01:00
parent bad977bef0
commit 898af5e9d2
11 changed files with 1693 additions and 13 deletions

View File

@@ -234,7 +234,8 @@ wp-prometheus/
│ ├── Metrics/
│ │ ├── Collector.php # Prometheus metrics collector
│ │ ├── CustomMetricBuilder.php # Custom metric CRUD
│ │ ── RuntimeCollector.php # Runtime metrics collector
│ │ ── RuntimeCollector.php # Runtime metrics collector
│ │ └── StorageFactory.php # Storage adapter factory
│ ├── Installer.php # Activation/Deactivation
│ ├── Plugin.php # Main plugin class
│ └── index.php
@@ -290,6 +291,34 @@ add_action( 'wp_prometheus_collect_metrics', function( $collector ) {
## Session History
### 2026-02-02 - Persistent Storage (v0.4.0)
- Added persistent storage support for metrics:
- `StorageFactory.php` - Factory class for storage adapter instantiation
- Redis storage adapter for shared metrics across multiple instances
- APCu storage adapter for single-server high-performance caching
- Automatic fallback to In-Memory if configured adapter fails
- Added new "Storage" tab in admin settings:
- Storage adapter selection (In-Memory, Redis, APCu)
- Redis configuration (host, port, password, database, key prefix)
- APCu configuration (key prefix)
- Connection test button with detailed error messages
- Added environment variable support for Docker deployments:
- `WP_PROMETHEUS_STORAGE_ADAPTER` - Adapter selection
- `WP_PROMETHEUS_REDIS_HOST`, `_PORT`, `_PASSWORD`, `_DATABASE`, `_PREFIX`
- `WP_PROMETHEUS_APCU_PREFIX`
- Environment variables take precedence over admin settings
- Updated `Collector.php` to use `StorageFactory::get_adapter()`
- Updated Help tab with storage backends documentation
- Updated translation files with all new strings
- **Key Learning**: promphp/prometheus_client_php storage adapters
- Redis adapter requires options array with host, port, password, timeout
- APCu adapter just needs a prefix string
- Use `Redis::setPrefix()` before instantiation for custom key prefixes
- **Key Learning**: Docker environment variable configuration
- Use `getenv()` with explicit false check (`false !== getenv()`)
- Environment variables should override WordPress options for containerized deployments
### 2026-02-02 - Custom Metrics & Dashboards (v0.3.0)
- Added Custom Metric Builder with full admin UI: