1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package de.kaiserpfalzedv.services.sms77.filter;
19
20 import de.kaiserpfalzedv.services.sms77.mapper.Sms77Exception;
21 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
22 import feign.InvocationContext;
23 import feign.ResponseInterceptor;
24 import io.micrometer.core.instrument.Counter;
25 import io.micrometer.core.instrument.MeterRegistry;
26 import io.micrometer.core.instrument.Tags;
27 import jakarta.annotation.PostConstruct;
28 import jakarta.annotation.PreDestroy;
29 import jakarta.inject.Inject;
30 import jakarta.inject.Singleton;
31 import lombok.RequiredArgsConstructor;
32
33
34
35
36
37
38
39 @SuppressFBWarnings(value = {"EI_EXPOSE_REP","EI_EXPOSE_REP2"}, justification = "lombok provided @Getter are created")
40 @Singleton
41 @RequiredArgsConstructor(onConstructor = @__(@Inject))
42 public class Sms77RequestReportFilter implements ResponseInterceptor {
43 private static final String API_REQUESTS_HANDLED_SINCE_START = "sms77.sms-since-start";
44
45 private final MeterRegistry registry;
46 private Counter requestCounter;
47
48 @PostConstruct
49 public void registerMetric() {
50 this.requestCounter = this.registry.counter(API_REQUESTS_HANDLED_SINCE_START, Tags.empty());
51 }
52
53 @SuppressFBWarnings(value = "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "The field is set in the PostConstruct method of this class.")
54 @PreDestroy
55 public void unregisterMetrics() {
56 assert this.registry != null;
57
58 this.requestCounter.close();
59 }
60
61
62
63
64
65
66
67
68
69 @SuppressFBWarnings(value = "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "The field is set in the PostConstruct method of this class.")
70 @Override
71 public Object intercept(final InvocationContext invocationContext, final Chain chain) throws Exception {
72 assert this.registry != null;
73
74 this.requestCounter.increment();
75
76 return chain.next(invocationContext);
77 }
78 }