Skip to content

Commit d09431a

Browse files
refactor(config): simplify configuration file
Removed unused config keys and verbose comments: - Removed 'middleware' key (not used in codebase) - Removed 'prometheus.middleware' key (only mentioned in comment) - Removed 'hooks' arrays (hooks now registered via code, not config) - Simplified all section comments - Removed inline comments from config values The config is now 83 lines shorter while keeping all functionality that's actually used by the package. All tests passing.
1 parent 4d39867 commit d09431a

File tree

1 file changed

+13
-96
lines changed

1 file changed

+13
-96
lines changed

config/queue-metrics.php

Lines changed: 13 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,8 @@
2929

3030
/*
3131
|--------------------------------------------------------------------------
32-
| 👉 BASIC CONFIGURATION
32+
| 👉 BASIC
3333
|--------------------------------------------------------------------------
34-
|
35-
| Essential settings to get started with queue metrics collection.
36-
| These are the only settings most users need to configure.
37-
|
3834
*/
3935

4036
'enabled' => env('QUEUE_METRICS_ENABLED', true),
@@ -45,145 +41,66 @@
4541
'prefix' => 'queue_metrics',
4642

4743
'ttl' => [
48-
'raw' => 3600, // 1 hour - raw job execution data
49-
'aggregated' => 604800, // 7 days - calculated metrics
50-
'baseline' => 2592000, // 30 days - baseline calculations
44+
'raw' => 3600,
45+
'aggregated' => 604800,
46+
'baseline' => 2592000,
5147
],
5248
],
5349

5450
/*
5551
|--------------------------------------------------------------------------
5652
| 🔒 SECURITY
5753
|--------------------------------------------------------------------------
58-
|
59-
| Control access to metrics endpoints.
60-
|
6154
*/
6255

6356
'allowed_ips' => env('QUEUE_METRICS_ALLOWED_IPS') ? explode(',', env('QUEUE_METRICS_ALLOWED_IPS')) : null,
6457

65-
'middleware' => [
66-
'api',
67-
AllowIps::class,
68-
],
69-
7058
/*
7159
|--------------------------------------------------------------------------
72-
| 📊 INTEGRATIONS
60+
| 📊 PROMETHEUS
7361
|--------------------------------------------------------------------------
74-
|
75-
| Optional integrations for monitoring and observability.
76-
|
7762
*/
7863

7964
'prometheus' => [
8065
'enabled' => env('QUEUE_METRICS_PROMETHEUS_ENABLED', true),
8166
'namespace' => env('QUEUE_METRICS_PROMETHEUS_NAMESPACE', 'laravel_queue'),
82-
83-
// Cache TTL for metrics export (in seconds)
84-
// Prevents multiple concurrent requests from overloading Redis with key scans
8567
'cache_ttl' => env('QUEUE_METRICS_PROMETHEUS_CACHE_TTL', 10),
86-
87-
// Middleware applied to the Prometheus endpoint
88-
// Add ThrottlePrometheus::class to enable rate limiting
89-
'middleware' => [
90-
// ThrottlePrometheus::class,
91-
],
92-
],
93-
94-
/*
95-
|--------------------------------------------------------------------------
96-
| 🔌 EXTENSIBILITY (for autoscaler & custom processing)
97-
|--------------------------------------------------------------------------
98-
|
99-
| Hooks allow you to extend the metrics processing pipeline.
100-
| Register custom hook classes to enrich or process metrics data.
101-
|
102-
| Available contexts:
103-
| - 'before_record': Before recording job metrics
104-
| - 'after_record': After recording job metrics (enrich with custom data)
105-
| - 'before_calculate': Before calculating aggregated metrics
106-
| - 'after_calculate': After calculating aggregated metrics (export to external systems)
107-
| - 'before_baseline': Before baseline calculation
108-
| - 'after_baseline': After baseline calculation (trigger autoscaler)
109-
|
110-
| Example:
111-
| 'hooks' => [
112-
| 'after_record' => [\App\Hooks\CustomMetricsEnricherHook::class],
113-
| 'after_baseline' => [\App\Hooks\AutoscalerTriggerHook::class],
114-
| ],
115-
|
116-
*/
117-
118-
'hooks' => [
119-
'before_record' => [],
120-
'after_record' => [],
121-
'before_calculate' => [],
122-
'after_calculate' => [],
123-
'before_baseline' => [],
124-
'after_baseline' => [],
12568
],
12669

12770
/*
12871
|--------------------------------------------------------------------------
129-
| ⚙️ ADVANCED CONFIGURATION
72+
| ⚙️ ADVANCED
13073
|--------------------------------------------------------------------------
131-
|
132-
| These settings rarely need changes. They're here if you need fine-grained
133-
| control over worker monitoring and baseline calculation behavior.
134-
|
13574
*/
13675

13776
'worker_heartbeat' => [
13877
'stale_threshold' => env('QUEUE_METRICS_STALE_THRESHOLD', 60),
13978
],
14079

14180
'baseline' => [
142-
// Sliding window size (recent data is weighted higher)
14381
'sliding_window_days' => env('QUEUE_METRICS_BASELINE_WINDOW_DAYS', 7),
144-
145-
// Exponential decay factor (higher = faster decay, more weight on recent data)
146-
// λ value where weight = e^(-λ * age_in_days)
14782
'decay_factor' => env('QUEUE_METRICS_BASELINE_DECAY_FACTOR', 0.1),
148-
149-
// Target sample size for 100% confidence
15083
'target_sample_size' => env('QUEUE_METRICS_BASELINE_TARGET_SAMPLES', 200),
15184

152-
// Adaptive recalculation intervals based on confidence (in minutes)
15385
'intervals' => [
154-
'no_baseline' => 1, // No baseline exists - calculate every minute
155-
'low_confidence' => 5, // Confidence < 0.5 - every 5 minutes
156-
'medium_confidence' => 10, // Confidence 0.5-0.7 - every 10 minutes
157-
'high_confidence' => 30, // Confidence 0.7-0.9 - every 30 minutes
158-
'very_high_confidence' => 60, // Confidence >= 0.9 - every 60 minutes
86+
'no_baseline' => 1,
87+
'low_confidence' => 5,
88+
'medium_confidence' => 10,
89+
'high_confidence' => 30,
90+
'very_high_confidence' => 60,
15991
],
16092

161-
// Deviation detection for triggering more frequent recalculation
16293
'deviation' => [
16394
'enabled' => env('QUEUE_METRICS_BASELINE_DEVIATION_ENABLED', true),
164-
'threshold' => env('QUEUE_METRICS_BASELINE_DEVIATION_THRESHOLD', 2.0), // Standard deviations
165-
'trigger_interval' => 5, // Recalculate every 5 minutes when deviation detected
95+
'threshold' => env('QUEUE_METRICS_BASELINE_DEVIATION_THRESHOLD', 2.0),
96+
'trigger_interval' => 5,
16697
],
16798
],
16899

169100
/*
170101
|--------------------------------------------------------------------------
171102
| 🛠️ EXTENSIBILITY
172103
|--------------------------------------------------------------------------
173-
|
174-
| Override repositories and actions to customize package behavior.
175-
| This follows Spatie's pattern for extending Laravel packages.
176-
|
177-
| Example: To use a custom repository
178-
| 'repositories' => [
179-
| JobMetricsRepository::class => \App\Repositories\CustomJobMetricsRepository::class,
180-
| ],
181-
|
182-
| Example: To use a custom action
183-
| 'actions' => [
184-
| 'record_job_start' => \App\Actions\CustomRecordJobStartAction::class,
185-
| ],
186-
|
187104
*/
188105

189106
'repositories' => [

0 commit comments

Comments
 (0)