11package com .linkedin .venice .controller .stats ;
22
3+ import static com .linkedin .venice .controller .VeniceController .CONTROLLER_SERVICE_METRIC_ENTITIES ;
34import static com .linkedin .venice .stats .dimensions .VeniceMetricsDimensions .STORE_REPUSH_TRIGGER_SOURCE ;
45import static com .linkedin .venice .stats .dimensions .VeniceMetricsDimensions .VENICE_CLUSTER_NAME ;
56import static com .linkedin .venice .stats .dimensions .VeniceMetricsDimensions .VENICE_RESPONSE_STATUS_CODE_CATEGORY ;
67import static com .linkedin .venice .stats .dimensions .VeniceMetricsDimensions .VENICE_STORE_NAME ;
78import static org .mockito .Mockito .doReturn ;
9+ import static org .testng .Assert .fail ;
810
911import com .linkedin .venice .controller .AbstractTestVeniceParentHelixAdmin ;
1012import com .linkedin .venice .stats .VeniceMetricsConfig ;
1113import com .linkedin .venice .stats .VeniceMetricsRepository ;
1214import com .linkedin .venice .stats .dimensions .StoreRepushTriggerSource ;
1315import com .linkedin .venice .stats .dimensions .VeniceResponseStatusCategory ;
14- import com .linkedin .venice .stats . metrics . MetricEntity ;
16+ import com .linkedin .venice .utils . DataProviderUtils ;
1517import com .linkedin .venice .utils .OpenTelemetryDataPointTestUtils ;
1618import io .opentelemetry .api .common .Attributes ;
1719import io .opentelemetry .sdk .testing .exporter .InMemoryMetricReader ;
18- import java .util .Arrays ;
19- import java .util .Collection ;
2020import org .testng .annotations .BeforeMethod ;
2121import 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