@@ -38,6 +38,11 @@ private static class FactoryBuilder {
3838
3939 @ FunctionalInterface
4040 interface Modifier {
41+ /**
42+ * @param keyPropertyList Map of MBean ObjectName key properties and their values.
43+ * @param labels The current map of labels to be provided to the collector constructor.
44+ * @return true to continue building the collector, false to abort.
45+ */
4146 boolean modify (final Map <String , String > keyPropertyList , final Map <String , String > labels );
4247 }
4348
@@ -63,9 +68,8 @@ FactoryBuilder withModifier(final Modifier modifier) {
6368 FactoryBuilder withLabelMaker (final LabelMaker labelMaker ) {
6469 return this .withModifier ((keyPropertyList , labels ) -> {
6570 labels .putAll (labelMaker .apply (keyPropertyList ));
66-
6771 return true ;
68- });
72+ });
6973 }
7074
7175 FactoryBuilder withHelp (final String help ) {
@@ -85,17 +89,15 @@ Factory build() {
8589
8690 final Map <String , String > keyPropertyList = mBean .name .getKeyPropertyList ();
8791
92+ final String name = String .format ("cassandra_%s" , metricFamilyName );
8893 final Map <String , String > rawLabels = new HashMap <>();
89- {
90- for (final Modifier modifier : modifiers ) {
91- if (!modifier .modify (keyPropertyList , rawLabels )) {
92- return null ;
93- }
94+
95+ for (final Modifier modifier : modifiers ) {
96+ if (!modifier .modify (keyPropertyList , rawLabels )) {
97+ return null ;
9498 }
9599 }
96100
97- final String name = String .format ("cassandra_%s" , metricFamilyName );
98-
99101 return collectorConstructor .groupCollectorForMBean (name , help , new Labels (rawLabels ), mBean );
100102 };
101103 }
@@ -173,7 +175,7 @@ private Factory clientRequestMetricFactory(final FactoryBuilder.CollectorConstru
173175
174176 return new FactoryBuilder (collectorConstructor , objectNamePattern , metricFamilyName )
175177 .withHelp (help )
176- .withLabelMaker ( keyPropertyList -> {
178+ .withModifier (( keyPropertyList , labels ) -> {
177179 final String scope = keyPropertyList .get ("scope" );
178180
179181 final Pattern scopePattern = Pattern .compile ("(?<operation>.*?)(-(?<consistency>.*))?" );
@@ -182,22 +184,20 @@ private Factory clientRequestMetricFactory(final FactoryBuilder.CollectorConstru
182184 if (!matcher .matches ())
183185 throw new IllegalStateException ();
184186
185- final ImmutableMap .Builder <String , String > labelsBuilder = ImmutableMap .builder ();
186-
187187 final String operation = matcher .group ("operation" ).toLowerCase ();
188188 final String consistency = matcher .group ("consistency" );
189189
190- labelsBuilder .put ("operation" , operation );
190+ labels .put ("operation" , operation );
191191
192192 if (consistency == null && (operation .equals ("read" ) || operation .equals ("write" ))) {
193193 // read/write without a consistency level is a total -- exclude
194- return null ;
194+ return false ;
195195
196196 } else if (consistency != null ) {
197- labelsBuilder .put ("consistency" , consistency );
197+ labels .put ("consistency" , consistency );
198198 }
199199
200- return labelsBuilder . build () ;
200+ return true ;
201201 })
202202 .build ();
203203 }
0 commit comments