Skip to content

Commit fe6b33b

Browse files
committed
fix ConsumerCoordinatorTest unit test
1 parent 11e8f54 commit fe6b33b

File tree

4 files changed

+16
-35
lines changed

4 files changed

+16
-35
lines changed

pinot-common/src/main/java/org/apache/pinot/common/metrics/AbstractMetrics.java

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.common.collect.ImmutableMap;
2323
import java.util.Collection;
2424
import java.util.Collections;
25+
import java.util.HashMap;
2526
import java.util.HashSet;
2627
import java.util.List;
2728
import java.util.Map;
@@ -236,13 +237,8 @@ public void addTimedValue(final String key, final T timer, final long duration,
236237
*/
237238
private void addValueToTimer(String fullTimerName, String simplifiedTimerName, final long duration,
238239
final TimeUnit timeUnit, Map<String, String> attributes) {
239-
Map<String, String> fullAttributes = ImmutableMap.<String, String>builder()
240-
.putAll(attributes)
241-
.put(MetricAttributeConstants.PINOT_METRIC_NAME, fullTimerName)
242-
.build();
243-
244240
final PinotMetricName metricName = PinotMetricUtils.makePinotMetricName(_clazz, fullTimerName,
245-
simplifiedTimerName, fullAttributes);
241+
simplifiedTimerName, new HashMap<>(attributes));
246242
PinotTimer timer =
247243
PinotMetricUtils.makePinotTimer(_metricsRegistry, metricName, TimeUnit.MILLISECONDS, TimeUnit.SECONDS);
248244
if (timer != null) {
@@ -366,10 +362,9 @@ public PinotMeter addMeteredTableValue(final String tableName, final String key,
366362
PinotMeter reusedMeter, Map<String, String> attributes) {
367363
String meterName = meter.getMeterName();
368364
final String fullMeterName = _metricPrefix + getTableName(tableName) + "." + key + "." + meterName;
369-
Map<String, String> fullAttributes = ImmutableMap.<String, String>builder()
370-
.putAll(attributes)
371-
.put(MetricAttributeConstants.TABLE_NAME, tableName)
372-
.build();
365+
Map<String, String> fullAttributes = new HashMap<>(attributes);
366+
fullAttributes.put(MetricAttributeConstants.TABLE_NAME, tableName);
367+
373368
return addValueToMeter(fullMeterName, meterName, meter.getUnit(), unitCount, reusedMeter, fullAttributes);
374369
}
375370

@@ -392,13 +387,8 @@ private PinotMeter addValueToMeter(
392387
reusedMeter.mark(unitCount);
393388
return reusedMeter;
394389
} else {
395-
Map<String, String> fullAttributes = ImmutableMap.<String, String>builder()
396-
.putAll(attributes)
397-
.put(MetricAttributeConstants.PINOT_METRIC_NAME, fullMeterName)
398-
.build();
399-
400390
final PinotMetricName metricName = PinotMetricUtils.makePinotMetricName(_clazz, fullMeterName,
401-
simplifiedMeterName, fullAttributes);
391+
simplifiedMeterName, new HashMap<>(attributes));
402392

403393
final PinotMeter newMeter =
404394
PinotMetricUtils.makePinotMeter(_metricsRegistry, metricName, unit, TimeUnit.SECONDS);
@@ -688,12 +678,8 @@ public void addCallbackGauge(final String metricName,
688678
String simplifiedMetricName,
689679
Map<String, String> attributes,
690680
final Callable<Long> valueCallback) {
691-
Map<String, String> fullAttributes = ImmutableMap.<String, String>builder()
692-
.putAll(attributes)
693-
.put(MetricAttributeConstants.PINOT_METRIC_NAME, metricName)
694-
.build();
695681
PinotMetricName pinotMetricName = PinotMetricUtils.makePinotMetricName(_clazz, _metricPrefix + metricName,
696-
simplifiedMetricName, fullAttributes);
682+
simplifiedMetricName, new HashMap<>(attributes));
697683

698684
PinotMetricUtils
699685
.makeGauge(_metricsRegistry, pinotMetricName,
@@ -737,10 +723,8 @@ public void setOrUpdateTableGauge(final String tableName, final String key, fina
737723
Map<String, String> attributes, final Supplier<Long> valueSupplier) {
738724
String fullGaugeName = composeTableGaugeName(tableName, key, gauge);
739725

740-
Map<String, String> fullAttributes = ImmutableMap.<String, String>builder()
741-
.putAll(attributes)
742-
.put(MetricAttributeConstants.TABLE_NAME, tableName)
743-
.build();
726+
Map<String, String> fullAttributes = new HashMap<>(attributes);
727+
fullAttributes.put(MetricAttributeConstants.TABLE_NAME, tableName);
744728

745729
setOrUpdateGauge(fullGaugeName, gauge.getGaugeName(), fullAttributes, valueSupplier::get);
746730
}
@@ -820,13 +804,8 @@ public void setOrUpdateGlobalGauge(final String metricName, final LongSupplier v
820804

821805
public void setOrUpdateGauge(final String metricName, final String simplifiedMetricName,
822806
Map<String, String> attributes, final LongSupplier valueSupplier) {
823-
Map<String, String> fullAttributes = ImmutableMap.<String, String>builder()
824-
.putAll(attributes)
825-
.put(MetricAttributeConstants.PINOT_METRIC_NAME, metricName)
826-
.build();
827-
828807
PinotMetricName pinotMetricName = PinotMetricUtils.makePinotMetricName(_clazz, _metricPrefix + metricName,
829-
simplifiedMetricName, fullAttributes);
808+
simplifiedMetricName, new HashMap<>(attributes));
830809

831810
PinotGauge<Long> pinotGauge = PinotMetricUtils.makeGauge(_metricsRegistry, pinotMetricName,
832811
PinotMetricUtils.makePinotGauge(pinotMetricName, avoid -> valueSupplier.getAsLong()));

pinot-core/src/test/java/org/apache/pinot/core/data/manager/realtime/ConsumerCoordinatorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public FakeRealtimeTableDataManager(Semaphore segmentBuildSemaphore,
4646
boolean useIdealStateToCalculatePreviousSegment) {
4747
super(segmentBuildSemaphore);
4848
super._recentlyDeletedSegments = CacheBuilder.newBuilder().build();
49+
super._tableNameWithType = "testTable";
4950
StreamIngestionConfig streamIngestionConfig = new StreamIngestionConfig(List.of(new HashMap<>()));
5051
streamIngestionConfig.setEnforceConsumptionInOrder(true);
5152
if (useIdealStateToCalculatePreviousSegment) {
@@ -147,7 +148,6 @@ public void testFirstConsumer()
147148
FakeConsumerCoordinator consumerCoordinator = new FakeConsumerCoordinator(true, realtimeTableDataManager);
148149
realtimeTableDataManager.setConsumerCoordinator(consumerCoordinator);
149150
ReentrantLock lock = (ReentrantLock) consumerCoordinator.getLock();
150-
RealtimeSegmentDataManager mockedRealtimeSegmentDataManager = getMockedRealtimeSegmentDataManager();
151151
Map<String, String> serverSegmentStatusMap = new HashMap<>() {{
152152
put("server_1", "ONLINE");
153153
put("server_3", "ONLINE");

pinot-plugins/pinot-metrics/pinot-open-telemetry/src/main/java/org/apache/pinot/plugin/metrics/opentelemetry/OpenTelemetryMetricName.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
*/
1919
package org.apache.pinot.plugin.metrics.opentelemetry;
2020

21-
import com.google.common.collect.ImmutableMap;
21+
import java.util.HashMap;
2222
import java.util.Map;
23+
import org.apache.pinot.common.metrics.MetricAttributeConstants;
2324
import org.apache.pinot.spi.metrics.PinotMetricName;
2425

2526

@@ -35,7 +36,8 @@ public class OpenTelemetryMetricName implements PinotMetricName {
3536
public OpenTelemetryMetricName(String fullMetricName, String simplifiedMetricName, Map<String, String> attributes) {
3637
_fullMetricName = fullMetricName;
3738
_simplifiedMetricName = simplifiedMetricName;
38-
_attributes = ImmutableMap.copyOf(attributes);
39+
_attributes = new HashMap<>(attributes);
40+
_attributes.put(MetricAttributeConstants.PINOT_METRIC_NAME, fullMetricName);
3941
}
4042

4143
public OpenTelemetryMetricName(PinotMetricName pinotMetricName) {

pinot-plugins/pinot-metrics/pinot-open-telemetry/src/main/java/org/apache/pinot/plugin/metrics/opentelemetry/OpenTelemetryUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static Attributes toOpenTelemetryAttributes(Map<String, String> attribute
5252
AttributesBuilder attributesBuilder = Attributes.builder();
5353
if (attributes != null) {
5454
for (Map.Entry<String, String> entry : attributes.entrySet()) {
55-
attributesBuilder.put(entry.getKey(), entry.getValue());
55+
attributesBuilder.put(entry.getKey(), entry.getValue() == null ? "-" : entry.getValue());
5656
}
5757
}
5858
return attributesBuilder.build();

0 commit comments

Comments
 (0)