|
29 | 29 |
|
30 | 30 | /* |
31 | 31 | |-------------------------------------------------------------------------- |
32 | | - | 👉 BASIC CONFIGURATION |
| 32 | + | 👉 BASIC |
33 | 33 | |-------------------------------------------------------------------------- |
34 | | - | |
35 | | - | Essential settings to get started with queue metrics collection. |
36 | | - | These are the only settings most users need to configure. |
37 | | - | |
38 | 34 | */ |
39 | 35 |
|
40 | 36 | 'enabled' => env('QUEUE_METRICS_ENABLED', true), |
|
45 | 41 | 'prefix' => 'queue_metrics', |
46 | 42 |
|
47 | 43 | '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, |
51 | 47 | ], |
52 | 48 | ], |
53 | 49 |
|
54 | 50 | /* |
55 | 51 | |-------------------------------------------------------------------------- |
56 | 52 | | 🔒 SECURITY |
57 | 53 | |-------------------------------------------------------------------------- |
58 | | - | |
59 | | - | Control access to metrics endpoints. |
60 | | - | |
61 | 54 | */ |
62 | 55 |
|
63 | 56 | 'allowed_ips' => env('QUEUE_METRICS_ALLOWED_IPS') ? explode(',', env('QUEUE_METRICS_ALLOWED_IPS')) : null, |
64 | 57 |
|
65 | | - 'middleware' => [ |
66 | | - 'api', |
67 | | - AllowIps::class, |
68 | | - ], |
69 | | - |
70 | 58 | /* |
71 | 59 | |-------------------------------------------------------------------------- |
72 | | - | 📊 INTEGRATIONS |
| 60 | + | 📊 PROMETHEUS |
73 | 61 | |-------------------------------------------------------------------------- |
74 | | - | |
75 | | - | Optional integrations for monitoring and observability. |
76 | | - | |
77 | 62 | */ |
78 | 63 |
|
79 | 64 | 'prometheus' => [ |
80 | 65 | 'enabled' => env('QUEUE_METRICS_PROMETHEUS_ENABLED', true), |
81 | 66 | '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 |
85 | 67 | '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' => [], |
125 | 68 | ], |
126 | 69 |
|
127 | 70 | /* |
128 | 71 | |-------------------------------------------------------------------------- |
129 | | - | ⚙️ ADVANCED CONFIGURATION |
| 72 | + | ⚙️ ADVANCED |
130 | 73 | |-------------------------------------------------------------------------- |
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 | | - | |
135 | 74 | */ |
136 | 75 |
|
137 | 76 | 'worker_heartbeat' => [ |
138 | 77 | 'stale_threshold' => env('QUEUE_METRICS_STALE_THRESHOLD', 60), |
139 | 78 | ], |
140 | 79 |
|
141 | 80 | 'baseline' => [ |
142 | | - // Sliding window size (recent data is weighted higher) |
143 | 81 | '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) |
147 | 82 | 'decay_factor' => env('QUEUE_METRICS_BASELINE_DECAY_FACTOR', 0.1), |
148 | | - |
149 | | - // Target sample size for 100% confidence |
150 | 83 | 'target_sample_size' => env('QUEUE_METRICS_BASELINE_TARGET_SAMPLES', 200), |
151 | 84 |
|
152 | | - // Adaptive recalculation intervals based on confidence (in minutes) |
153 | 85 | '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, |
159 | 91 | ], |
160 | 92 |
|
161 | | - // Deviation detection for triggering more frequent recalculation |
162 | 93 | 'deviation' => [ |
163 | 94 | '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, |
166 | 97 | ], |
167 | 98 | ], |
168 | 99 |
|
169 | 100 | /* |
170 | 101 | |-------------------------------------------------------------------------- |
171 | 102 | | 🛠️ EXTENSIBILITY |
172 | 103 | |-------------------------------------------------------------------------- |
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 | | - | |
187 | 104 | */ |
188 | 105 |
|
189 | 106 | 'repositories' => [ |
|
0 commit comments