You've already forked wp-prometheus
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 192da4588a | |||
| cf1797d4bf | |||
| 19d75ab7b2 | |||
| fa63857f5f |
19
CHANGELOG.md
19
CHANGELOG.md
@@ -5,6 +5,25 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [0.4.3] - 2026-02-02
|
||||
|
||||
### Added
|
||||
|
||||
- Sub-tabs navigation within Metrics tab (Endpoint, Selection, Runtime, Advanced)
|
||||
- Option to disable early mode in admin settings (Metrics → Advanced)
|
||||
- Support for `WP_PROMETHEUS_DISABLE_EARLY_MODE` environment variable
|
||||
- Early mode status display in settings
|
||||
|
||||
### Fixed
|
||||
|
||||
- Early mode setting now saves correctly (moved into form with proper settings group)
|
||||
|
||||
### Changed
|
||||
|
||||
- Reorganized Metrics tab into logical sub-sections for better usability
|
||||
- Early mode can now be disabled for users who need the `wp_prometheus_collect_metrics` hook
|
||||
- Updated translations with sub-tab and early mode strings (English and German)
|
||||
|
||||
## [0.4.1] - 2026-02-02
|
||||
|
||||
### Fixed
|
||||
|
||||
58
CLAUDE.md
58
CLAUDE.md
@@ -291,6 +291,64 @@ add_action( 'wp_prometheus_collect_metrics', function( $collector ) {
|
||||
|
||||
## Session History
|
||||
|
||||
### 2026-02-02 - Sub-tabs & Early Mode Fix (v0.4.3)
|
||||
|
||||
- Split Metrics tab into sub-tabs for better organization:
|
||||
- **Endpoint**: Authentication token configuration
|
||||
- **Selection**: Enable/disable individual metrics
|
||||
- **Runtime**: Reset runtime metrics data
|
||||
- **Advanced**: Early mode toggle and status
|
||||
- Fixed early mode setting not being saved (was outside form element)
|
||||
- Added CSS styling for horizontal sub-tab navigation
|
||||
- **Key Learning**: WordPress Settings API form structure
|
||||
- Settings must be inside `<form action="options.php">` with `settings_fields()` call
|
||||
- Each sub-tab needs its own form wrapper for proper saving
|
||||
- Sub-tabs use URL query parameter (`subtab`) within the main tab
|
||||
|
||||
### 2026-02-02 - Early Mode Toggle (v0.4.2)
|
||||
|
||||
- Added option to disable early mode for users who need extensibility
|
||||
- Implementation:
|
||||
- Added `wp_prometheus_disable_early_mode` WordPress option
|
||||
- Added `WP_PROMETHEUS_DISABLE_EARLY_MODE` environment variable support
|
||||
- Option check in `wp_prometheus_early_metrics_check()` before early interception
|
||||
- Environment variable accepts `1`, `true`, `yes`, `on` (case-insensitive)
|
||||
- Admin UI in Metrics tab:
|
||||
- "Early Mode" section with description of functionality
|
||||
- Checkbox to disable early metrics interception
|
||||
- Environment override notice when env var is set
|
||||
- Current status indicator showing early mode state
|
||||
- **Key Learning**: Balancing compatibility vs extensibility
|
||||
- Early mode fixes memory issues but disables `wp_prometheus_collect_metrics` hook
|
||||
- Users with custom metrics need the hook, so early mode must be optional
|
||||
- Default remains enabled (safe) with explicit opt-out for advanced users
|
||||
|
||||
### 2026-02-02 - Plugin Compatibility Fix (v0.4.1)
|
||||
|
||||
- Fixed memory exhaustion (1GB limit) when wp-fedistream (Twig-based) plugin is active
|
||||
- Root cause: Infinite recursion through WordPress hook system when content filters trigger Twig rendering
|
||||
- Solution: Early metrics endpoint interception before full WordPress initialization
|
||||
- Implementation changes:
|
||||
- Added `wp_prometheus_early_metrics_check()` in bootstrap file (wp-prometheus.php)
|
||||
- Checks REQUEST_URI for `/metrics` pattern before `plugins_loaded` fires
|
||||
- Defines `WP_PROMETHEUS_EARLY_METRICS` constant to signal early mode
|
||||
- Removes content filters (`the_content`, `the_excerpt`, `get_the_excerpt`, `the_title`)
|
||||
- Collector skips `wp_prometheus_collect_metrics` action in early mode
|
||||
- Changed MetricsEndpoint from `template_redirect` to `parse_request` hook
|
||||
- **Key Learning**: WordPress plugin loading order and hook timing
|
||||
- Plugins load alphabetically, so wp-fedistream ('f') loads before wp-prometheus ('p')
|
||||
- `template_redirect` fires too late - after themes and Twig initialize
|
||||
- `parse_request` fires earlier but still after plugin files load
|
||||
- Earliest interception point: top-level code in plugin bootstrap file
|
||||
- **Key Learning**: Content filter recursion in WordPress
|
||||
- `get_the_excerpt()` internally triggers `apply_filters('the_content', ...)`
|
||||
- This creates unexpected recursion vectors when Twig templates process content
|
||||
- Solution: Remove all content-related filters before metrics collection
|
||||
- **Key Learning**: Isolating metrics collection from WordPress template system
|
||||
- Use `remove_all_filters()` to clear problematic filter chains
|
||||
- Skip extensibility hooks (`do_action`) when in isolated early mode
|
||||
- Exit immediately after output to prevent further WordPress processing
|
||||
|
||||
### 2026-02-02 - Persistent Storage (v0.4.0)
|
||||
|
||||
- Added persistent storage support for metrics:
|
||||
|
||||
@@ -9,6 +9,61 @@
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
/* Sub-tabs navigation */
|
||||
.wp-prometheus-subtabs {
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
.wp-prometheus-subtab-nav {
|
||||
display: flex;
|
||||
margin: 0 0 20px 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
border-bottom: 1px solid #c3c4c7;
|
||||
}
|
||||
|
||||
.wp-prometheus-subtab-item {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.wp-prometheus-subtab-item a {
|
||||
display: block;
|
||||
padding: 8px 16px;
|
||||
text-decoration: none;
|
||||
color: #50575e;
|
||||
border: 1px solid transparent;
|
||||
border-bottom: none;
|
||||
margin-bottom: -1px;
|
||||
background: transparent;
|
||||
font-size: 13px;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.wp-prometheus-subtab-item a:hover {
|
||||
color: #2271b1;
|
||||
background: #f6f7f7;
|
||||
}
|
||||
|
||||
.wp-prometheus-subtab-item.active a {
|
||||
color: #1d2327;
|
||||
background: #fff;
|
||||
border-color: #c3c4c7;
|
||||
border-bottom-color: #fff;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.wp-prometheus-subtab-content {
|
||||
background: #fff;
|
||||
border: 1px solid #c3c4c7;
|
||||
border-top: none;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.wp-prometheus-subtab-content h3:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
/* License status box */
|
||||
.wp-prometheus-license-status {
|
||||
margin: 15px 0;
|
||||
|
||||
Binary file not shown.
@@ -3,7 +3,7 @@
|
||||
# This file is distributed under the GPL v2 or later.
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: WP Prometheus 0.4.0\n"
|
||||
"Project-Id-Version: WP Prometheus 0.4.2\n"
|
||||
"Report-Msgid-Bugs-To: https://src.bundespruefstelle.ch/magdev/wp-prometheus/issues\n"
|
||||
"POT-Creation-Date: 2026-02-02T00:00:00+00:00\n"
|
||||
"PO-Revision-Date: 2026-02-02T00:00:00+00:00\n"
|
||||
@@ -879,3 +879,71 @@ msgstr "APCu funktioniert. Speicher: %s belegt."
|
||||
#: src/Metrics/StorageFactory.php
|
||||
msgid "APCu fetch operation returned unexpected value."
|
||||
msgstr "APCu-Abrufoperation hat unerwarteten Wert zurueckgegeben."
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Early Mode"
|
||||
msgstr "Fruehzeitiger Modus"
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Early mode intercepts /metrics requests before full WordPress initialization. This prevents memory exhaustion issues caused by some plugins (e.g., Twig-based themes/plugins) but disables the wp_prometheus_collect_metrics hook for custom metrics."
|
||||
msgstr "Der fruehzeitige Modus faengt /metrics-Anfragen vor der vollstaendigen WordPress-Initialisierung ab. Dies verhindert Speichererschoepfungsprobleme, die durch einige Plugins verursacht werden (z.B. Twig-basierte Themes/Plugins), deaktiviert jedoch den wp_prometheus_collect_metrics-Hook fuer benutzerdefinierte Metriken."
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Early mode is configured via WP_PROMETHEUS_DISABLE_EARLY_MODE environment variable. Admin settings will be ignored."
|
||||
msgstr "Der fruehzeitige Modus ist ueber die Umgebungsvariable WP_PROMETHEUS_DISABLE_EARLY_MODE konfiguriert. Admin-Einstellungen werden ignoriert."
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Disable Early Mode"
|
||||
msgstr "Fruehzeitigen Modus deaktivieren"
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Disable early metrics interception"
|
||||
msgstr "Fruehzeitige Metriken-Abfangung deaktivieren"
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "When disabled, metrics are collected through normal WordPress template loading. This enables the wp_prometheus_collect_metrics hook for custom metrics but may cause issues with some plugins."
|
||||
msgstr "Wenn deaktiviert, werden Metriken ueber das normale WordPress-Template-Laden erfasst. Dies aktiviert den wp_prometheus_collect_metrics-Hook fuer benutzerdefinierte Metriken, kann jedoch Probleme mit einigen Plugins verursachen."
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Early mode is active (this request was served via early interception)"
|
||||
msgstr "Fruehzeitiger Modus ist aktiv (diese Anfrage wurde ueber fruehzeitige Abfangung verarbeitet)"
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Early mode is disabled"
|
||||
msgstr "Fruehzeitiger Modus ist deaktiviert"
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Early mode is enabled (active for /metrics requests)"
|
||||
msgstr "Fruehzeitiger Modus ist aktiviert (aktiv fuer /metrics-Anfragen)"
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Clear all accumulated runtime metric data (HTTP requests, database queries). This is useful for testing or starting fresh."
|
||||
msgstr "Alle gesammelten Laufzeit-Metrikdaten loeschen (HTTP-Anfragen, Datenbank-Abfragen). Dies ist nuetzlich zum Testen oder fuer einen Neuanfang."
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Endpoint"
|
||||
msgstr "Endpunkt"
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Selection"
|
||||
msgstr "Auswahl"
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Runtime"
|
||||
msgstr "Laufzeit"
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Advanced"
|
||||
msgstr "Erweitert"
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Runtime Metrics Management"
|
||||
msgstr "Laufzeit-Metriken Verwaltung"
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Runtime metrics track HTTP requests and database queries across requests. Use this section to manage accumulated data."
|
||||
msgstr "Laufzeit-Metriken erfassen HTTP-Anfragen und Datenbank-Abfragen ueber mehrere Anfragen hinweg. Verwenden Sie diesen Bereich zur Verwaltung der gesammelten Daten."
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Reset Data"
|
||||
msgstr "Daten zuruecksetzen"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# This file is distributed under the GPL v2 or later.
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: WP Prometheus 0.4.0\n"
|
||||
"Project-Id-Version: WP Prometheus 0.4.2\n"
|
||||
"Report-Msgid-Bugs-To: https://src.bundespruefstelle.ch/magdev/wp-prometheus/issues\n"
|
||||
"POT-Creation-Date: 2026-02-02T00:00:00+00:00\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
@@ -876,3 +876,71 @@ msgstr ""
|
||||
#: src/Metrics/StorageFactory.php
|
||||
msgid "APCu fetch operation returned unexpected value."
|
||||
msgstr ""
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Early Mode"
|
||||
msgstr ""
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Early mode intercepts /metrics requests before full WordPress initialization. This prevents memory exhaustion issues caused by some plugins (e.g., Twig-based themes/plugins) but disables the wp_prometheus_collect_metrics hook for custom metrics."
|
||||
msgstr ""
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Early mode is configured via WP_PROMETHEUS_DISABLE_EARLY_MODE environment variable. Admin settings will be ignored."
|
||||
msgstr ""
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Disable Early Mode"
|
||||
msgstr ""
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Disable early metrics interception"
|
||||
msgstr ""
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "When disabled, metrics are collected through normal WordPress template loading. This enables the wp_prometheus_collect_metrics hook for custom metrics but may cause issues with some plugins."
|
||||
msgstr ""
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Early mode is active (this request was served via early interception)"
|
||||
msgstr ""
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Early mode is disabled"
|
||||
msgstr ""
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Early mode is enabled (active for /metrics requests)"
|
||||
msgstr ""
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Clear all accumulated runtime metric data (HTTP requests, database queries). This is useful for testing or starting fresh."
|
||||
msgstr ""
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Endpoint"
|
||||
msgstr ""
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Selection"
|
||||
msgstr ""
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Runtime"
|
||||
msgstr ""
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Advanced"
|
||||
msgstr ""
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Runtime Metrics Management"
|
||||
msgstr ""
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Runtime metrics track HTTP requests and database queries across requests. Use this section to manage accumulated data."
|
||||
msgstr ""
|
||||
|
||||
#: src/Admin/Settings.php
|
||||
msgid "Reset Data"
|
||||
msgstr ""
|
||||
|
||||
@@ -118,6 +118,12 @@ class Settings {
|
||||
'sanitize_callback' => array( $this, 'sanitize_metrics' ),
|
||||
) );
|
||||
|
||||
register_setting( 'wp_prometheus_metrics_settings', 'wp_prometheus_disable_early_mode', array(
|
||||
'type' => 'boolean',
|
||||
'sanitize_callback' => 'rest_sanitize_boolean',
|
||||
'default' => false,
|
||||
) );
|
||||
|
||||
// Auth token section.
|
||||
add_settings_section(
|
||||
'wp_prometheus_auth_section',
|
||||
@@ -394,32 +400,225 @@ class Settings {
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Get metrics sub-tabs.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_metrics_subtabs(): array {
|
||||
return array(
|
||||
'endpoint' => __( 'Endpoint', 'wp-prometheus' ),
|
||||
'selection' => __( 'Selection', 'wp-prometheus' ),
|
||||
'runtime' => __( 'Runtime', 'wp-prometheus' ),
|
||||
'advanced' => __( 'Advanced', 'wp-prometheus' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current metrics sub-tab.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_current_metrics_subtab(): string {
|
||||
$subtab = isset( $_GET['subtab'] ) ? sanitize_key( $_GET['subtab'] ) : 'endpoint';
|
||||
$subtabs = $this->get_metrics_subtabs();
|
||||
return array_key_exists( $subtab, $subtabs ) ? $subtab : 'endpoint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Render metrics tab content.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function render_metrics_tab(): void {
|
||||
$subtabs = $this->get_metrics_subtabs();
|
||||
$current_subtab = $this->get_current_metrics_subtab();
|
||||
?>
|
||||
<div class="wp-prometheus-subtabs">
|
||||
<ul class="wp-prometheus-subtab-nav">
|
||||
<?php foreach ( $subtabs as $subtab_id => $subtab_name ) : ?>
|
||||
<?php
|
||||
$subtab_url = add_query_arg(
|
||||
array(
|
||||
'page' => 'wp-prometheus',
|
||||
'tab' => 'metrics',
|
||||
'subtab' => $subtab_id,
|
||||
),
|
||||
admin_url( 'options-general.php' )
|
||||
);
|
||||
$active_class = ( $current_subtab === $subtab_id ) ? ' active' : '';
|
||||
?>
|
||||
<li class="wp-prometheus-subtab-item<?php echo esc_attr( $active_class ); ?>">
|
||||
<a href="<?php echo esc_url( $subtab_url ); ?>"><?php echo esc_html( $subtab_name ); ?></a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
|
||||
<div class="wp-prometheus-subtab-content">
|
||||
<?php
|
||||
switch ( $current_subtab ) {
|
||||
case 'endpoint':
|
||||
$this->render_metrics_endpoint_subtab();
|
||||
break;
|
||||
case 'selection':
|
||||
$this->render_metrics_selection_subtab();
|
||||
break;
|
||||
case 'runtime':
|
||||
$this->render_metrics_runtime_subtab();
|
||||
break;
|
||||
case 'advanced':
|
||||
$this->render_metrics_advanced_subtab();
|
||||
break;
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render metrics endpoint sub-tab.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function render_metrics_endpoint_subtab(): void {
|
||||
?>
|
||||
<form method="post" action="options.php">
|
||||
<?php
|
||||
settings_fields( 'wp_prometheus_metrics_settings' );
|
||||
do_settings_sections( 'wp-prometheus-metrics' );
|
||||
submit_button();
|
||||
?>
|
||||
<?php settings_fields( 'wp_prometheus_metrics_settings' ); ?>
|
||||
|
||||
<h3><?php esc_html_e( 'Authentication', 'wp-prometheus' ); ?></h3>
|
||||
<p class="description"><?php esc_html_e( 'Configure authentication for the /metrics endpoint.', 'wp-prometheus' ); ?></p>
|
||||
|
||||
<table class="form-table" role="presentation">
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="wp_prometheus_auth_token"><?php esc_html_e( 'Auth Token', 'wp-prometheus' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<?php $this->render_auth_token_field(); ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php submit_button(); ?>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
<hr style="margin: 30px 0;">
|
||||
/**
|
||||
* Render metrics selection sub-tab.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function render_metrics_selection_subtab(): void {
|
||||
?>
|
||||
<form method="post" action="options.php">
|
||||
<?php settings_fields( 'wp_prometheus_metrics_settings' ); ?>
|
||||
|
||||
<h3><?php esc_html_e( 'Reset Runtime Metrics', 'wp-prometheus' ); ?></h3>
|
||||
<p class="description"><?php esc_html_e( 'Clear all accumulated runtime metric data (HTTP requests, database queries). This is useful for testing or starting fresh.', 'wp-prometheus' ); ?></p>
|
||||
<p>
|
||||
<button type="button" id="wp-prometheus-reset-runtime" class="button button-secondary">
|
||||
<?php esc_html_e( 'Reset Runtime Metrics', 'wp-prometheus' ); ?>
|
||||
</button>
|
||||
<span id="wp-prometheus-reset-spinner" class="spinner" style="float: none;"></span>
|
||||
</p>
|
||||
<div id="wp-prometheus-reset-message" style="display: none; margin-top: 10px;"></div>
|
||||
<h3><?php esc_html_e( 'Enabled Metrics', 'wp-prometheus' ); ?></h3>
|
||||
<p class="description"><?php esc_html_e( 'Select which metrics to expose on the /metrics endpoint.', 'wp-prometheus' ); ?></p>
|
||||
|
||||
<table class="form-table" role="presentation">
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Select Metrics', 'wp-prometheus' ); ?></th>
|
||||
<td>
|
||||
<?php $this->render_enabled_metrics_field(); ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php submit_button(); ?>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render metrics runtime sub-tab.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function render_metrics_runtime_subtab(): void {
|
||||
?>
|
||||
<h3><?php esc_html_e( 'Runtime Metrics Management', 'wp-prometheus' ); ?></h3>
|
||||
<p class="description"><?php esc_html_e( 'Runtime metrics track HTTP requests and database queries across requests. Use this section to manage accumulated data.', 'wp-prometheus' ); ?></p>
|
||||
|
||||
<table class="form-table" role="presentation">
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Reset Data', 'wp-prometheus' ); ?></th>
|
||||
<td>
|
||||
<p class="description" style="margin-bottom: 10px;">
|
||||
<?php esc_html_e( 'Clear all accumulated runtime metric data (HTTP requests, database queries). This is useful for testing or starting fresh.', 'wp-prometheus' ); ?>
|
||||
</p>
|
||||
<button type="button" id="wp-prometheus-reset-runtime" class="button button-secondary">
|
||||
<?php esc_html_e( 'Reset Runtime Metrics', 'wp-prometheus' ); ?>
|
||||
</button>
|
||||
<span id="wp-prometheus-reset-spinner" class="spinner" style="float: none;"></span>
|
||||
<div id="wp-prometheus-reset-message" style="display: none; margin-top: 10px;"></div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render metrics advanced sub-tab.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function render_metrics_advanced_subtab(): void {
|
||||
$disabled = get_option( 'wp_prometheus_disable_early_mode', false );
|
||||
$env_override = false !== getenv( 'WP_PROMETHEUS_DISABLE_EARLY_MODE' );
|
||||
$early_active = defined( 'WP_PROMETHEUS_EARLY_METRICS' ) && WP_PROMETHEUS_EARLY_METRICS;
|
||||
?>
|
||||
<form method="post" action="options.php">
|
||||
<?php settings_fields( 'wp_prometheus_metrics_settings' ); ?>
|
||||
|
||||
<h3><?php esc_html_e( 'Early Mode', 'wp-prometheus' ); ?></h3>
|
||||
<p class="description">
|
||||
<?php esc_html_e( 'Early mode intercepts /metrics requests before full WordPress initialization. This prevents memory exhaustion issues caused by some plugins (e.g., Twig-based themes/plugins) but disables the wp_prometheus_collect_metrics hook for custom metrics.', 'wp-prometheus' ); ?>
|
||||
</p>
|
||||
|
||||
<?php if ( $env_override ) : ?>
|
||||
<div class="notice notice-info inline" style="padding: 12px; margin: 15px 0;">
|
||||
<strong><?php esc_html_e( 'Environment Override Active', 'wp-prometheus' ); ?></strong>
|
||||
<p><?php esc_html_e( 'Early mode is configured via WP_PROMETHEUS_DISABLE_EARLY_MODE environment variable. Admin settings will be ignored.', 'wp-prometheus' ); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<table class="form-table" role="presentation">
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Disable Early Mode', 'wp-prometheus' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="wp_prometheus_disable_early_mode" value="1"
|
||||
<?php checked( $disabled ); ?>
|
||||
<?php disabled( $env_override ); ?>>
|
||||
<?php esc_html_e( 'Disable early metrics interception', 'wp-prometheus' ); ?>
|
||||
</label>
|
||||
<p class="description">
|
||||
<?php esc_html_e( 'When disabled, metrics are collected through normal WordPress template loading. This enables the wp_prometheus_collect_metrics hook for custom metrics but may cause issues with some plugins.', 'wp-prometheus' ); ?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Current Status', 'wp-prometheus' ); ?></th>
|
||||
<td>
|
||||
<?php if ( $early_active ) : ?>
|
||||
<span class="dashicons dashicons-yes-alt" style="color: green;"></span>
|
||||
<?php esc_html_e( 'Early mode is active (this request was served via early interception)', 'wp-prometheus' ); ?>
|
||||
<?php elseif ( $disabled || $env_override ) : ?>
|
||||
<span class="dashicons dashicons-dismiss" style="color: gray;"></span>
|
||||
<?php esc_html_e( 'Early mode is disabled', 'wp-prometheus' ); ?>
|
||||
<?php else : ?>
|
||||
<span class="dashicons dashicons-yes-alt" style="color: green;"></span>
|
||||
<?php esc_html_e( 'Early mode is enabled (active for /metrics requests)', 'wp-prometheus' ); ?>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php submit_button(); ?>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Plugin Name: WP Prometheus
|
||||
* Plugin URI: https://src.bundespruefstelle.ch/magdev/wp-prometheus
|
||||
* Description: Prometheus metrics endpoint for WordPress with extensible hooks for custom metrics.
|
||||
* Version: 0.4.1
|
||||
* Version: 0.4.3
|
||||
* Requires at least: 6.4
|
||||
* Requires PHP: 8.3
|
||||
* Author: Marco Graetsch
|
||||
@@ -37,6 +37,18 @@ function wp_prometheus_early_metrics_check(): void {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if early mode is disabled via environment variable.
|
||||
$env_disable = getenv( 'WP_PROMETHEUS_DISABLE_EARLY_MODE' );
|
||||
if ( false !== $env_disable && in_array( strtolower( $env_disable ), array( '1', 'true', 'yes', 'on' ), true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if early mode is disabled via option.
|
||||
// We can use get_option() here because WordPress core is already loaded.
|
||||
if ( get_option( 'wp_prometheus_disable_early_mode', false ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if autoloader exists.
|
||||
$autoloader = __DIR__ . '/vendor/autoload.php';
|
||||
if ( ! file_exists( $autoloader ) ) {
|
||||
@@ -118,7 +130,7 @@ wp_prometheus_early_metrics_check();
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
define( 'WP_PROMETHEUS_VERSION', '0.4.1' );
|
||||
define( 'WP_PROMETHEUS_VERSION', '0.4.3' );
|
||||
|
||||
/**
|
||||
* Plugin file path.
|
||||
|
||||
Reference in New Issue
Block a user