You've already forked wp-prometheus
feat: Split Metrics tab into sub-tabs and fix early mode storage (v0.4.3)
Some checks failed
Create Release Package / build-release (push) Failing after 52s
Some checks failed
Create Release Package / build-release (push) Failing after 52s
- Add sub-tabs: Endpoint, Selection, Runtime, Advanced - Fix early mode checkbox not saving (was outside form element) - Add CSS styling for horizontal sub-tab navigation - Update translations with new sub-tab strings Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -400,95 +400,228 @@ 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();
|
||||
?>
|
||||
<form method="post" action="options.php">
|
||||
<?php
|
||||
settings_fields( 'wp_prometheus_metrics_settings' );
|
||||
do_settings_sections( 'wp-prometheus-metrics' );
|
||||
submit_button();
|
||||
?>
|
||||
</form>
|
||||
<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>
|
||||
|
||||
<hr style="margin: 30px 0;">
|
||||
|
||||
<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>
|
||||
|
||||
<hr style="margin: 30px 0;">
|
||||
|
||||
<?php $this->render_early_mode_section(); ?>
|
||||
<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 early mode section.
|
||||
* Render metrics endpoint sub-tab.
|
||||
*
|
||||
* @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;
|
||||
private function render_metrics_endpoint_subtab(): void {
|
||||
?>
|
||||
<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>
|
||||
<form method="post" action="options.php">
|
||||
<?php settings_fields( 'wp_prometheus_metrics_settings' ); ?>
|
||||
|
||||
<?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; ?>
|
||||
<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
|
||||
}
|
||||
|
||||
/**
|
||||
* 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( '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( 'Disable Early Mode', 'wp-prometheus' ); ?></th>
|
||||
<th scope="row"><?php esc_html_e( 'Reset Data', '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 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>
|
||||
</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; ?>
|
||||
<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
|
||||
}
|
||||
|
||||
/**
|
||||
* Render storage tab content.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user