@@ -50,13 +50,26 @@ public class CompactionExecutorsMetrics implements MetricsProducer {
50
50
private MeterRegistry registry = null ;
51
51
52
52
// public so it can be closed by outside callers
53
- public static class CeMetrics implements AutoCloseable {
54
- private AtomicInteger queued ;
55
- private AtomicInteger running ;
53
+ public class CeMetrics implements AutoCloseable {
54
+ private final AtomicInteger queued ;
55
+ private final AtomicInteger running ;
56
56
57
57
private IntSupplier runningSupplier ;
58
58
private IntSupplier queuedSupplier ;
59
59
60
+ private CeMetrics (CompactionExecutorId ceid ) {
61
+ if (registry != null ) {
62
+ this .queued = registry .gauge (METRICS_MAJC_QUEUED , Tags .of ("id" , ceid .canonical ()),
63
+ new AtomicInteger (0 ));
64
+ this .running = registry .gauge (METRICS_MAJC_RUNNING , Tags .of ("id" , ceid .canonical ()),
65
+ new AtomicInteger (0 ));
66
+ } else {
67
+ // these vars have no effect on metrics in this case - just avoids NPEs
68
+ this .queued = new AtomicInteger (0 );
69
+ this .running = new AtomicInteger (0 );
70
+ }
71
+ }
72
+
60
73
@ Override
61
74
public void close () {
62
75
runningSupplier = () -> 0 ;
@@ -66,9 +79,22 @@ public void close() {
66
79
}
67
80
}
68
81
69
- private static class ExMetrics {
70
- AtomicInteger queued ;
71
- AtomicInteger running ;
82
+ private class ExMetrics {
83
+ private final AtomicInteger queued ;
84
+ private final AtomicInteger running ;
85
+
86
+ private ExMetrics (CompactionExecutorId ceid ) {
87
+ if (registry != null ) {
88
+ this .queued = registry .gauge (METRICS_MAJC_QUEUED , Tags .of ("id" , ceid .canonical ()),
89
+ new AtomicInteger (0 ));
90
+ this .running = registry .gauge (METRICS_MAJC_RUNNING , Tags .of ("id" , ceid .canonical ()),
91
+ new AtomicInteger (0 ));
92
+ } else {
93
+ // these vars have no effect on metrics in this case - just avoids NPEs
94
+ this .queued = new AtomicInteger (0 );
95
+ this .running = new AtomicInteger (0 );
96
+ }
97
+ }
72
98
}
73
99
74
100
public CompactionExecutorsMetrics () {
@@ -89,16 +115,7 @@ public synchronized CeMetrics addExecutor(CompactionExecutorId ceid, IntSupplier
89
115
90
116
synchronized (ceMetricsMap ) {
91
117
92
- CeMetrics cem = ceMetricsMap .computeIfAbsent (ceid , id -> {
93
- CeMetrics m = new CeMetrics ();
94
- if (registry != null ) {
95
- m .queued = registry .gauge (METRICS_MAJC_QUEUED , Tags .of ("id" , ceid .canonical ()),
96
- new AtomicInteger (0 ));
97
- m .running = registry .gauge (METRICS_MAJC_RUNNING , Tags .of ("id" , ceid .canonical ()),
98
- new AtomicInteger (0 ));
99
- }
100
- return m ;
101
- });
118
+ CeMetrics cem = ceMetricsMap .computeIfAbsent (ceid , id -> new CeMetrics (ceid ));
102
119
103
120
cem .runningSupplier = runningSupplier ;
104
121
cem .queuedSupplier = queuedSupplier ;
@@ -120,16 +137,7 @@ public void update() {
120
137
externalMetricsSupplier .get ().forEach (ecm -> {
121
138
seenIds .add (ecm .ceid );
122
139
123
- ExMetrics exm = exCeMetricsMap .computeIfAbsent (ecm .ceid , id -> {
124
- ExMetrics m = new ExMetrics ();
125
- if (registry != null ) {
126
- m .queued = registry .gauge (METRICS_MAJC_QUEUED , Tags .of ("id" , ecm .ceid .canonical ()),
127
- new AtomicInteger (0 ));
128
- m .running = registry .gauge (METRICS_MAJC_RUNNING , Tags .of ("id" , ecm .ceid .canonical ()),
129
- new AtomicInteger (0 ));
130
- }
131
- return m ;
132
- });
140
+ ExMetrics exm = exCeMetricsMap .computeIfAbsent (ecm .ceid , id -> new ExMetrics (ecm .ceid ));
133
141
134
142
exm .queued .set (ecm .queued );
135
143
exm .running .set (ecm .running );
0 commit comments