@@ -209,15 +209,22 @@ private void applyConfig(Object config_, AppSecModuleConfigurer.Reconfiguration
209
209
config .dirtyStatus .markAllDirty ();
210
210
}
211
211
212
+ boolean success = false ;
212
213
try {
213
214
// ddwaf_init/update
214
- initializeNewWafCtx (reconf , config , curCtxAndAddresses );
215
+ success = initializeNewWafCtx (reconf , config , curCtxAndAddresses );
215
216
} catch (Exception e ) {
216
217
throw new AppSecModuleActivationException ("Could not initialize/update waf" , e );
218
+ } finally {
219
+ if (curCtxAndAddresses == null ) {
220
+ WafMetricCollector .get ().wafInit (Powerwaf .LIB_VERSION , currentRulesVersion , success );
221
+ } else {
222
+ WafMetricCollector .get ().wafUpdates (currentRulesVersion , success );
223
+ }
217
224
}
218
225
}
219
226
220
- private void initializeNewWafCtx (
227
+ private boolean initializeNewWafCtx (
221
228
AppSecModuleConfigurer .Reconfiguration reconf ,
222
229
CurrentAppSecConfig config ,
223
230
CtxAndAddresses prevContextAndAddresses )
@@ -267,13 +274,11 @@ private void initializeNewWafCtx(
267
274
}
268
275
} catch (InvalidRuleSetException irse ) {
269
276
initReport = irse .ruleSetInfo ;
270
- sendWafMetrics (prevContextAndAddresses , false );
271
277
throw new AppSecModuleActivationException ("Error creating WAF rules" , irse );
272
278
} catch (RuntimeException | AbstractPowerwafException e ) {
273
279
if (newPwafCtx != null ) {
274
280
newPwafCtx .close ();
275
281
}
276
- sendWafMetrics (prevContextAndAddresses , false );
277
282
throw new AppSecModuleActivationException ("Error creating WAF rules" , e );
278
283
} finally {
279
284
if (initReport != null ) {
@@ -283,25 +288,15 @@ private void initializeNewWafCtx(
283
288
284
289
if (!this .ctxAndAddresses .compareAndSet (prevContextAndAddresses , newContextAndAddresses )) {
285
290
newPwafCtx .close ();
286
- sendWafMetrics (prevContextAndAddresses , false );
287
291
throw new AppSecModuleActivationException ("Concurrent update of WAF configuration" );
288
292
}
289
293
290
- sendWafMetrics (prevContextAndAddresses , true );
291
-
292
294
if (prevContextAndAddresses != null ) {
293
295
prevContextAndAddresses .ctx .close ();
294
296
}
295
297
296
298
reconf .reloadSubscriptions ();
297
- }
298
-
299
- private void sendWafMetrics (CtxAndAddresses prevContextAndAddresses , boolean success ) {
300
- if (prevContextAndAddresses == null ) {
301
- WafMetricCollector .get ().wafInit (Powerwaf .LIB_VERSION , currentRulesVersion , success );
302
- } else {
303
- WafMetricCollector .get ().wafUpdates (currentRulesVersion , success );
304
- }
299
+ return true ;
305
300
}
306
301
307
302
private Map <String , ActionInfo > calculateEffectiveActions (
0 commit comments