You've already forked wp-prometheus
feat: Add option to disable early mode (v0.4.2)
All checks were successful
Create Release Package / build-release (push) Successful in 56s
All checks were successful
Create Release Package / build-release (push) Successful in 56s
- Add wp_prometheus_disable_early_mode option in admin settings - Support WP_PROMETHEUS_DISABLE_EARLY_MODE environment variable - Add Early Mode section in Metrics tab with status indicator - Allow users to enable wp_prometheus_collect_metrics hook Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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',
|
||||
@@ -420,6 +426,66 @@ class Settings {
|
||||
<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>
|
||||
|
||||
<hr style="margin: 30px 0;">
|
||||
|
||||
<?php $this->render_early_mode_section(); ?>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render early mode section.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function render_early_mode_section(): 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;
|
||||
?>
|
||||
<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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user