Skip to content

Commit 607f0d8

Browse files
committed
fix missing metrics
1 parent 1ba13ec commit 607f0d8

4 files changed

Lines changed: 68 additions & 24 deletions

File tree

internal/venice-test-common/src/main/java/com/linkedin/venice/utils/OpenTelemetryDataPointTestUtils.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ public static LongPointData getLongPointDataFromSum(
2222
String metricName,
2323
String prefix,
2424
Attributes expectedAttributes) {
25-
return metricsData.stream()
25+
MetricData data = metricsData.stream()
2626
.filter(metricData -> metricData.getName().equals(DEFAULT_METRIC_PREFIX + prefix + "." + metricName))
2727
.findFirst()
28-
.orElse(null)
29-
.getLongSumData()
28+
.orElse(null);
29+
assertNotNull(data, "MetricData should not be null");
30+
31+
return data.getLongSumData()
3032
.getPoints()
3133
.stream()
3234
.filter(p -> p.getAttributes().equals(expectedAttributes))

services/venice-controller/src/main/java/com/linkedin/venice/controller/stats/ControllerMetricEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public enum ControllerMetricEntity implements ModuleMetricEntityInterface {
4545
STORE_COMPACTION_TRIGGERED_COUNT(
4646
"store.compaction.triggered_count", MetricType.COUNTER, MetricUnit.NUMBER,
4747
"Count of log compaction repush triggered for a store after it becomes eligible",
48-
setOf(VENICE_STORE_NAME, VENICE_CLUSTER_NAME)
48+
setOf(VENICE_STORE_NAME, VENICE_RESPONSE_STATUS_CODE_CATEGORY, VENICE_CLUSTER_NAME)
4949
);
5050

5151
private final MetricEntity metricEntity;

services/venice-controller/src/main/java/com/linkedin/venice/controller/stats/LogCompactionStats.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class LogCompactionStats extends AbstractVeniceStats {
2929
private final MetricEntityStateGeneric repushCallCountMetric;
3030
private final MetricEntityStateGeneric compactionEligibleMetric;
3131
private final MetricEntityStateGeneric storeNominatedForCompactionCountMetric;
32+
private final MetricEntityStateGeneric storeCompactionTriggeredCountMetric;
3233

3334
public LogCompactionStats(MetricsRepository metricsRepository, String clusterName) {
3435
super(metricsRepository, "LogCompactionStats");
@@ -73,6 +74,14 @@ public LogCompactionStats(MetricsRepository metricsRepository, String clusterNam
7374
ControllerTehutiMetricNameEnum.STORE_NOMINATED_FOR_COMPACTION_COUNT,
7475
Collections.singletonList(new OccurrenceRate()),
7576
baseDimensionsMap);
77+
78+
storeCompactionTriggeredCountMetric = MetricEntityStateGeneric.create(
79+
ControllerMetricEntity.STORE_COMPACTION_TRIGGERED_COUNT.getMetricEntity(),
80+
otelRepository,
81+
this::registerSensor,
82+
ControllerTehutiMetricNameEnum.REPUSH_CALL_COUNT,
83+
Collections.singletonList(new OccurrenceRate()),
84+
baseDimensionsMap);
7685
}
7786

7887
public void recordRepushStoreCall(
@@ -85,6 +94,13 @@ public void recordRepushStoreCall(
8594
.put(VeniceMetricsDimensions.STORE_REPUSH_TRIGGER_SOURCE, triggerSource.getDimensionValue())
8695
.put(VeniceMetricsDimensions.VENICE_RESPONSE_STATUS_CODE_CATEGORY, executionStatus.getDimensionValue())
8796
.build());
97+
if (triggerSource == StoreRepushTriggerSource.SCHEDULED_FOR_LOG_COMPACTION) {
98+
storeCompactionTriggeredCountMetric.record(
99+
1,
100+
getDimensionsBuilder().put(VeniceMetricsDimensions.VENICE_STORE_NAME, storeName)
101+
.put(VeniceMetricsDimensions.VENICE_RESPONSE_STATUS_CODE_CATEGORY, executionStatus.getDimensionValue())
102+
.build());
103+
}
88104
}
89105

90106
public void setCompactionEligible(String storeName) {
@@ -118,7 +134,9 @@ enum ControllerTehutiMetricNameEnum implements TehutiMetricNameEnum {
118134
/** for {@link ControllerMetricEntity#STORE_COMPACTION_ELIGIBLE_STATE} */
119135
COMPACTION_ELIGIBLE_STATE,
120136
/** for {@link ControllerMetricEntity#STORE_COMPACTION_NOMINATED_COUNT} */
121-
STORE_NOMINATED_FOR_COMPACTION_COUNT;
137+
STORE_NOMINATED_FOR_COMPACTION_COUNT,
138+
/** for {@link ControllerMetricEntity#STORE_COMPACTION_TRIGGERED_COUNT} */
139+
STORE_COMPACTION_TRIGGERED_COUNT;
122140

123141
private final String metricName;
124142

services/venice-controller/src/test/java/com/linkedin/venice/controller/stats/LogCompactionStatsTest.java

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
package com.linkedin.venice.controller.stats;
22

3+
import static com.linkedin.venice.controller.VeniceController.CONTROLLER_SERVICE_METRIC_ENTITIES;
34
import static com.linkedin.venice.stats.dimensions.VeniceMetricsDimensions.STORE_REPUSH_TRIGGER_SOURCE;
45
import static com.linkedin.venice.stats.dimensions.VeniceMetricsDimensions.VENICE_CLUSTER_NAME;
56
import static com.linkedin.venice.stats.dimensions.VeniceMetricsDimensions.VENICE_RESPONSE_STATUS_CODE_CATEGORY;
67
import static com.linkedin.venice.stats.dimensions.VeniceMetricsDimensions.VENICE_STORE_NAME;
78
import static org.mockito.Mockito.doReturn;
9+
import static org.testng.Assert.fail;
810

911
import com.linkedin.venice.controller.AbstractTestVeniceParentHelixAdmin;
1012
import com.linkedin.venice.stats.VeniceMetricsConfig;
1113
import com.linkedin.venice.stats.VeniceMetricsRepository;
1214
import com.linkedin.venice.stats.dimensions.StoreRepushTriggerSource;
1315
import com.linkedin.venice.stats.dimensions.VeniceResponseStatusCategory;
14-
import com.linkedin.venice.stats.metrics.MetricEntity;
16+
import com.linkedin.venice.utils.DataProviderUtils;
1517
import com.linkedin.venice.utils.OpenTelemetryDataPointTestUtils;
1618
import io.opentelemetry.api.common.Attributes;
1719
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
18-
import java.util.Arrays;
19-
import java.util.Collection;
2020
import org.testng.annotations.BeforeMethod;
2121
import org.testng.annotations.Test;
2222

@@ -31,48 +31,72 @@ public class LogCompactionStatsTest extends AbstractTestVeniceParentHelixAdmin {
3131

3232
@BeforeMethod
3333
public void setUp() throws Exception {
34-
// add all the metrics that are used in the test
35-
Collection<MetricEntity> metricEntities =
36-
Arrays.asList(ControllerMetricEntity.STORE_REPUSH_CALL_COUNT.getMetricEntity());
37-
3834
// setup metric reader to validate metric emission
3935
this.inMemoryMetricReader = InMemoryMetricReader.create();
4036
VeniceMetricsRepository metricsRepository = new VeniceMetricsRepository(
4137
new VeniceMetricsConfig.Builder().setMetricPrefix(TEST_METRIC_PREFIX)
42-
.setMetricEntities(metricEntities)
38+
.setMetricEntities(CONTROLLER_SERVICE_METRIC_ENTITIES)
4339
.setEmitOtelMetrics(true)
4440
.setOtelAdditionalMetricsReader(inMemoryMetricReader)
4541
.build());
4642

4743
setupInternalMocks();
48-
doReturn(true).when(getConfig()).isLogCompactionEnabled(); // enable log compaction to initialise LogCompactionStats
49-
// in VeniceParentHelixAdmin
44+
// enable log compaction to initialise LogCompactionStats in VeniceParentHelixAdmin
45+
doReturn(true).when(getConfig()).isLogCompactionEnabled();
5046

5147
this.logCompactionStats = new LogCompactionStats(metricsRepository, clusterName);
5248
}
5349

54-
@Test
55-
public void testEmitRepushStoreCallCountManualSuccessMetric() throws Exception {
56-
Attributes expectedAttributes = Attributes.builder()
50+
@Test(dataProvider = "True-and-False", dataProviderClass = DataProviderUtils.class)
51+
public void testEmitRepushStoreCallCountManualSuccessMetric(boolean isManualTrigger) {
52+
StoreRepushTriggerSource triggerSource =
53+
isManualTrigger ? StoreRepushTriggerSource.MANUAL : StoreRepushTriggerSource.SCHEDULED_FOR_LOG_COMPACTION;
54+
Attributes expectedAttributesForRepushCount = Attributes.builder()
5755
.put(VENICE_CLUSTER_NAME.getDimensionNameInDefaultFormat(), TEST_CLUSTER_NAME)
5856
.put(VENICE_STORE_NAME.getDimensionNameInDefaultFormat(), TEST_STORE_NAME)
59-
.put(
60-
STORE_REPUSH_TRIGGER_SOURCE.getDimensionNameInDefaultFormat(),
61-
StoreRepushTriggerSource.MANUAL.getDimensionValue())
57+
.put(STORE_REPUSH_TRIGGER_SOURCE.getDimensionNameInDefaultFormat(), triggerSource.getDimensionValue())
6258
.put(
6359
VENICE_RESPONSE_STATUS_CODE_CATEGORY.getDimensionNameInDefaultFormat(),
6460
VeniceResponseStatusCategory.SUCCESS.getDimensionValue())
6561
.build();
6662

6763
// Record metric
68-
this.logCompactionStats
69-
.recordRepushStoreCall(TEST_STORE_NAME, StoreRepushTriggerSource.MANUAL, VeniceResponseStatusCategory.SUCCESS);
64+
this.logCompactionStats.recordRepushStoreCall(TEST_STORE_NAME, triggerSource, VeniceResponseStatusCategory.SUCCESS);
7065

7166
// test validation
7267
validateLongPointFromDataFromSum(
7368
ControllerMetricEntity.STORE_REPUSH_CALL_COUNT.getMetricName(),
7469
1,
75-
expectedAttributes);
70+
expectedAttributesForRepushCount);
71+
72+
Attributes expectedAttributesForCompactionTriggered = Attributes.builder()
73+
.put(VENICE_CLUSTER_NAME.getDimensionNameInDefaultFormat(), TEST_CLUSTER_NAME)
74+
.put(VENICE_STORE_NAME.getDimensionNameInDefaultFormat(), TEST_STORE_NAME)
75+
.put(
76+
VENICE_RESPONSE_STATUS_CODE_CATEGORY.getDimensionNameInDefaultFormat(),
77+
VeniceResponseStatusCategory.SUCCESS.getDimensionValue())
78+
.build();
79+
80+
if (isManualTrigger) {
81+
try {
82+
validateLongPointFromDataFromSum(
83+
ControllerMetricEntity.STORE_COMPACTION_TRIGGERED_COUNT.getMetricName(),
84+
1,
85+
expectedAttributesForCompactionTriggered);
86+
fail("Compaction triggered metric should NOT be emitted for manual trigger");
87+
} catch (AssertionError e) {
88+
// For manual trigger, the compaction triggered metric should NOT be emitted
89+
if (!e.getMessage().contains("MetricData should not be null")) {
90+
throw e;
91+
}
92+
}
93+
} else {
94+
// For scheduled trigger, the compaction triggered metric should also be emitted
95+
validateLongPointFromDataFromSum(
96+
ControllerMetricEntity.STORE_COMPACTION_TRIGGERED_COUNT.getMetricName(),
97+
1,
98+
expectedAttributesForCompactionTriggered);
99+
}
76100
}
77101

78102
@Test

0 commit comments

Comments
 (0)