11
11
import org .springframework .context .annotation .Bean ;
12
12
import org .springframework .context .annotation .Configuration ;
13
13
14
+ /**
15
+ * MetricConfiguration sets up custom metrics and configuration for the application's meter
16
+ * registry using Micrometer.
17
+ *
18
+ * It applies common tags to all metrics, configures percentile distribution statistics,
19
+ * and manages Prometheus meter registry configuration. This class also provides a
20
+ * {@link TimedAspect} bean to support @Timed annotations for methods.
21
+ */
14
22
@ Configuration
15
23
public class MetricConfiguration {
16
24
@@ -23,11 +31,23 @@ public class MetricConfiguration {
23
31
@ Value ("${info.app.zone}" )
24
32
private String appZone ;
25
33
34
+ /**
35
+ * Creates a {@link TimedAspect} bean for timing method executions using the @Timed annotation.
36
+ *
37
+ * @param registry the {@link MeterRegistry} to register the aspect with.
38
+ * @return a {@link TimedAspect} configured to record method execution times.
39
+ */
26
40
@ Bean
27
41
public TimedAspect timedAspect (MeterRegistry registry ) {
28
42
return new TimedAspect (registry );
29
43
}
30
44
45
+ /**
46
+ * Adds common tags like version, app name, and zone to all metrics registered with the
47
+ * {@link MeterRegistry}.
48
+ *
49
+ * @return a {@link MeterRegistryCustomizer} to configure common tags and filters for metrics.
50
+ */
31
51
@ Bean
32
52
public MeterRegistryCustomizer <MeterRegistry > metricsCommonTags () {
33
53
return registry -> registry .config ()
@@ -40,15 +60,31 @@ public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
40
60
.meterFilter (distribution ());
41
61
}
42
62
63
+ /**
64
+ * Configures the {@link PrometheusMeterRegistry} for use with Prometheus metrics.
65
+ *
66
+ * @return a {@link MeterRegistryCustomizer} for Prometheus meter registry configuration.
67
+ */
43
68
@ Bean
44
69
public MeterRegistryCustomizer <PrometheusMeterRegistry > prometheusConfiguration () {
45
70
return MeterRegistry ::config ;
46
71
}
47
72
73
+ /**
74
+ * Creates a meter filter that ignores the "type" tag in all registered metrics.
75
+ *
76
+ * @return a {@link MeterFilter} that ignores the "type" tag.
77
+ */
48
78
public MeterFilter ignoreTag () {
49
79
return MeterFilter .ignoreTags ("type" );
50
80
}
51
81
82
+ /**
83
+ * Configures a meter filter to enable percentile histograms and track percentiles (0.5, 0.95,
84
+ * 0.99) for distribution statistics.
85
+ *
86
+ * @return a {@link MeterFilter} that configures percentile statistics and enables histograms.
87
+ */
52
88
public MeterFilter distribution () {
53
89
return new MeterFilter () {
54
90
0 commit comments