@@ -209,15 +209,22 @@ private void applyConfig(Object config_, AppSecModuleConfigurer.Reconfiguration
209209 config .dirtyStatus .markAllDirty ();
210210 }
211211
212+ boolean success = false ;
212213 try {
213214 // ddwaf_init/update
214- initializeNewWafCtx (reconf , config , curCtxAndAddresses );
215+ success = initializeNewWafCtx (reconf , config , curCtxAndAddresses );
215216 } catch (Exception e ) {
216217 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+ }
217224 }
218225 }
219226
220- private void initializeNewWafCtx (
227+ private boolean initializeNewWafCtx (
221228 AppSecModuleConfigurer .Reconfiguration reconf ,
222229 CurrentAppSecConfig config ,
223230 CtxAndAddresses prevContextAndAddresses )
@@ -267,13 +274,11 @@ private void initializeNewWafCtx(
267274 }
268275 } catch (InvalidRuleSetException irse ) {
269276 initReport = irse .ruleSetInfo ;
270- sendWafMetrics (prevContextAndAddresses , false );
271277 throw new AppSecModuleActivationException ("Error creating WAF rules" , irse );
272278 } catch (RuntimeException | AbstractPowerwafException e ) {
273279 if (newPwafCtx != null ) {
274280 newPwafCtx .close ();
275281 }
276- sendWafMetrics (prevContextAndAddresses , false );
277282 throw new AppSecModuleActivationException ("Error creating WAF rules" , e );
278283 } finally {
279284 if (initReport != null ) {
@@ -283,25 +288,15 @@ private void initializeNewWafCtx(
283288
284289 if (!this .ctxAndAddresses .compareAndSet (prevContextAndAddresses , newContextAndAddresses )) {
285290 newPwafCtx .close ();
286- sendWafMetrics (prevContextAndAddresses , false );
287291 throw new AppSecModuleActivationException ("Concurrent update of WAF configuration" );
288292 }
289293
290- sendWafMetrics (prevContextAndAddresses , true );
291-
292294 if (prevContextAndAddresses != null ) {
293295 prevContextAndAddresses .ctx .close ();
294296 }
295297
296298 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 ;
305300 }
306301
307302 private Map <String , ActionInfo > calculateEffectiveActions (
0 commit comments