-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathHostLevelIngestionStats.java
More file actions
862 lines (718 loc) · 32.5 KB
/
HostLevelIngestionStats.java
File metadata and controls
862 lines (718 loc) · 32.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
package com.linkedin.davinci.stats;
import static com.linkedin.davinci.stats.IngestionStats.BATCH_PROCESSING_REQUEST;
import static com.linkedin.davinci.stats.IngestionStats.BATCH_PROCESSING_REQUEST_ERROR;
import static com.linkedin.davinci.stats.IngestionStats.BATCH_PROCESSING_REQUEST_LATENCY;
import static com.linkedin.davinci.stats.IngestionStats.BATCH_PROCESSING_REQUEST_RECORDS;
import static com.linkedin.davinci.stats.IngestionStats.BATCH_PROCESSING_REQUEST_SIZE;
import static com.linkedin.venice.offsets.OffsetRecord.ACTIVE_KEY_COUNT_NOT_TRACKED;
import com.linkedin.davinci.config.VeniceServerConfig;
import com.linkedin.davinci.kafka.consumer.PartitionConsumptionState;
import com.linkedin.davinci.kafka.consumer.StoreIngestionTask;
import com.linkedin.venice.stats.AbstractVeniceStats;
import com.linkedin.venice.stats.LongAdderRateGauge;
import com.linkedin.venice.utils.RegionUtils;
import com.linkedin.venice.utils.Time;
import io.tehuti.metrics.Measurable;
import io.tehuti.metrics.MetricsRepository;
import io.tehuti.metrics.Sensor;
import io.tehuti.metrics.stats.AsyncGauge;
import io.tehuti.metrics.stats.Count;
import io.tehuti.metrics.stats.Max;
import io.tehuti.metrics.stats.OccurrenceRate;
import io.tehuti.metrics.stats.Rate;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.ToLongFunction;
/**
* This class contains stats for stats on the storage node host level.
* Stats inside this class can either:
* (1) Total only: The stat indicate total number of all the stores on this host.
* (2) Per store only: The stat is registered for each store on this host.
* (3) Per store and total: The stat is registered for each store on this host and the total number for this host.
*/
public class HostLevelIngestionStats extends AbstractVeniceStats {
public static final String ASSEMBLED_RECORD_SIZE_RATIO = "assembled_record_size_ratio";
public static final String ASSEMBLED_RECORD_SIZE_IN_BYTES = "assembled_record_size_in_bytes";
public static final String ASSEMBLED_RMD_SIZE_IN_BYTES = "assembled_rmd_size_in_bytes";
// The aggregated bytes ingested rate for the entire host
private final LongAdderRateGauge totalBytesConsumedRate;
// The aggregated records ingested rate for the entire host
private final LongAdderRateGauge totalRecordsConsumedRate;
// The aggregated blob transfer sent byte rate for the entire host
private final LongAdderRateGauge totalBlobTransferBytesSentRate;
// The aggregated blob transfer received byte rate for the entire host
private final LongAdderRateGauge totalBlobTransferBytesReceivedRate;
/*
* Bytes read from Kafka by store ingestion task as a total. This metric includes bytes read for all store versions
* allocated in a storage node reported with its uncompressed data size.
*/
private final LongAdderRateGauge totalBytesReadFromKafkaAsUncompressedSizeRate;
/** To measure 'put' latency of consumer records blocking queue */
private final Sensor consumerRecordsQueuePutLatencySensor;
private final Sensor keySizeSensor;
private final Sensor valueSizeSensor;
private final Sensor assembledRecordSizeSensor;
private final Sensor assembledRecordSizeRatioSensor;
private final Sensor assembledRmdSizeSensor;
private final Sensor unexpectedMessageSensor;
private final Sensor inconsistentStoreMetadataSensor;
private final Sensor ingestionFailureSensor;
private final Sensor resubscriptionFailureSensor;
private final Sensor viewProducerLatencySensor;
private final Sensor viewProducerAckLatencySensor;
/**
* Sensors for emitting if/when we detect DCR violations (such as a backwards timestamp or receding offset vector)
*/
private final LongAdderRateGauge totalTimestampRegressionDCRErrorRate;
private final LongAdderRateGauge totalOffsetRegressionDCRErrorRate;
/**
* A gauge reporting the total the percentage of hybrid quota used.
*/
private double hybridQuotaUsageGauge;
// Measure the avg/max time we need to spend on waiting for the leader producer
private final Sensor leaderProducerSynchronizeLatencySensor;
// Measure the avg/max latency for data lookup and deserialization
private final Sensor leaderWriteComputeLookUpLatencySensor;
// Measure the avg/max latency for the actual write computation
private final Sensor leaderWriteComputeUpdateLatencySensor;
// Measure the latency in processing consumer actions
private final Sensor processConsumerActionLatencySensor;
// Measure the latency in checking long running task states, like leader promotion, TopicSwitch
private final Sensor checkLongRunningTasksLatencySensor;
// Measure the latency in putting data into storage engine
private final Sensor storageEnginePutLatencySensor;
// Measure the latency in deleting data from storage engine
private final Sensor storageEngineDeleteLatencySensor;
/**
* Measure the number of times a record was found in {@link PartitionConsumptionState#transientRecordMap} during UPDATE
* message processing.
*/
private final Sensor writeComputeCacheHitCount;
/**
* Measure the total number of transient record cache lookups during UPDATE message processing.
*/
private final Sensor writeComputeLookupCount;
private final LongAdderRateGauge totalLeaderBytesConsumedRate;
private final LongAdderRateGauge totalLeaderRecordsConsumedRate;
private final LongAdderRateGauge totalFollowerBytesConsumedRate;
private final LongAdderRateGauge totalFollowerRecordsConsumedRate;
private final LongAdderRateGauge totalLeaderBytesProducedRate;
private final LongAdderRateGauge totalLeaderRecordsProducedRate;
private final List<Sensor> totalHybridBytesConsumedByRegionId;
private final List<Sensor> totalHybridRecordsConsumedByRegionId;
private final Sensor checksumVerificationFailureSensor;
/**
* Measure the number of times replication metadata was found in {@link PartitionConsumptionState#transientRecordMap}
*/
private final Sensor leaderIngestionReplicationMetadataCacheHitCount;
/**
* Measure the total number of transient record cache lookups for replication metadata
*/
private final Sensor leaderIngestionReplicationMetadataLookupCount;
/**
* Measure the avg/max latency for value bytes lookup
*/
private final Sensor leaderIngestionValueBytesLookUpLatencySensor;
/**
* Measure the number of times value bytes were found in {@link PartitionConsumptionState#transientRecordMap}
*/
private final Sensor leaderIngestionValueBytesCacheHitCount;
/**
* Measure the total number of transient record cache lookups for value bytes
*/
private final Sensor leaderIngestionValueBytesLookupCount;
/**
* Measure the avg/max latency for replication metadata data lookup
*/
private final Sensor leaderIngestionReplicationMetadataLookUpLatencySensor;
private final Sensor leaderIngestionActiveActivePutLatencySensor;
private final Sensor leaderIngestionActiveActiveUpdateLatencySensor;
private final Sensor leaderIngestionActiveActiveDeleteLatencySensor;
/**
* Measure the count of ignored updates due to conflict resolution
*/
private final LongAdderRateGauge totalUpdateIgnoredDCRRate;
/**
* Measure the count of tombstones created
*/
private final LongAdderRateGauge totalTombstoneCreationDCRRate;
private final LongAdderRateGauge totalActiveKeyCountInvalidationRate;
private final Sensor leaderProduceLatencySensor;
private final Sensor leaderCompressLatencySensor;
private final LongAdderRateGauge batchProcessingRequestSensor;
private final Sensor batchProcessingRequestSizeSensor;
private final LongAdderRateGauge batchProcessingRequestRecordsSensor;
private final Sensor batchProcessingRequestLatencySensor;
private final LongAdderRateGauge batchProcessingRequestErrorSensor;
private final Sensor leaderStepdownStampEmitSuccessSensor;
private final Sensor leaderStepdownStampEmitFailureSensor;
/**
* @param totalStats the total stats singleton instance, or null if we are constructing the total stats
*/
public HostLevelIngestionStats(
MetricsRepository metricsRepository,
VeniceServerConfig serverConfig,
String storeName,
HostLevelIngestionStats totalStats,
Map<String, StoreIngestionTask> ingestionTaskMap,
Time time) {
super(metricsRepository, storeName);
// Stats which are total only:
this.totalBytesConsumedRate =
registerOnlyTotalRate("bytes_consumed", totalStats, () -> totalStats.totalBytesConsumedRate, time);
this.totalRecordsConsumedRate =
registerOnlyTotalRate("records_consumed", totalStats, () -> totalStats.totalRecordsConsumedRate, time);
this.totalBlobTransferBytesSentRate = registerOnlyTotalRate(
"blob_transfer_bytes_sent",
totalStats,
() -> totalStats.totalBlobTransferBytesSentRate,
time);
this.totalBlobTransferBytesReceivedRate = registerOnlyTotalRate(
"blob_transfer_bytes_received",
totalStats,
() -> totalStats.totalBlobTransferBytesReceivedRate,
time);
this.totalBytesReadFromKafkaAsUncompressedSizeRate = registerOnlyTotalRate(
"bytes_read_from_kafka_as_uncompressed_size",
totalStats,
() -> totalStats.totalBytesReadFromKafkaAsUncompressedSizeRate,
time);
this.totalLeaderBytesConsumedRate =
registerOnlyTotalRate("leader_bytes_consumed", totalStats, () -> totalStats.totalLeaderBytesConsumedRate, time);
this.totalLeaderRecordsConsumedRate = registerOnlyTotalRate(
"leader_records_consumed",
totalStats,
() -> totalStats.totalLeaderRecordsConsumedRate,
time);
this.totalFollowerBytesConsumedRate = registerOnlyTotalRate(
"follower_bytes_consumed",
totalStats,
() -> totalStats.totalFollowerBytesConsumedRate,
time);
this.totalFollowerRecordsConsumedRate = registerOnlyTotalRate(
"follower_records_consumed",
totalStats,
() -> totalStats.totalFollowerRecordsConsumedRate,
time);
this.totalLeaderBytesProducedRate =
registerOnlyTotalRate("leader_bytes_produced", totalStats, () -> totalStats.totalLeaderBytesProducedRate, time);
this.totalLeaderRecordsProducedRate = registerOnlyTotalRate(
"leader_records_produced",
totalStats,
() -> totalStats.totalLeaderRecordsProducedRate,
time);
this.totalUpdateIgnoredDCRRate =
registerOnlyTotalRate("update_ignored_dcr", totalStats, () -> totalStats.totalUpdateIgnoredDCRRate, time);
this.totalTombstoneCreationDCRRate = registerOnlyTotalRate(
"tombstone_creation_dcr",
totalStats,
() -> totalStats.totalTombstoneCreationDCRRate,
time);
boolean activeKeyCountEnabled = serverConfig.isAnyActiveKeyCountTrackingEnabled();
this.totalActiveKeyCountInvalidationRate = activeKeyCountEnabled
? registerOnlyTotalRate(
"active_key_count_invalidation",
totalStats,
() -> totalStats.totalActiveKeyCountInvalidationRate,
time)
: null;
this.totalTimestampRegressionDCRErrorRate = registerOnlyTotalRate(
"timestamp_regression_dcr_error",
totalStats,
() -> totalStats.totalTimestampRegressionDCRErrorRate,
time);
this.totalOffsetRegressionDCRErrorRate = registerOnlyTotalRate(
"offset_regression_dcr_error",
totalStats,
() -> totalStats.totalOffsetRegressionDCRErrorRate,
time);
Int2ObjectMap<String> kafkaClusterIdToAliasMap = serverConfig.getKafkaClusterIdToAliasMap();
int listSize = kafkaClusterIdToAliasMap.isEmpty() ? 0 : Collections.max(kafkaClusterIdToAliasMap.keySet()) + 1;
Sensor[] tmpTotalHybridBytesConsumedByRegionId = new Sensor[listSize];
Sensor[] tmpTotalHybridRecordsConsumedByRegionId = new Sensor[listSize];
for (Int2ObjectMap.Entry<String> entry: serverConfig.getKafkaClusterIdToAliasMap().int2ObjectEntrySet()) {
String regionNamePrefix =
RegionUtils.getRegionSpecificMetricPrefix(serverConfig.getRegionName(), entry.getValue());
tmpTotalHybridBytesConsumedByRegionId[entry.getIntKey()] =
registerSensor(regionNamePrefix + "_rt_bytes_consumed", new Rate());
tmpTotalHybridRecordsConsumedByRegionId[entry.getIntKey()] =
registerSensor(regionNamePrefix + "_rt_records_consumed", new Rate());
}
this.totalHybridBytesConsumedByRegionId =
Collections.unmodifiableList(Arrays.asList(tmpTotalHybridBytesConsumedByRegionId));
this.totalHybridRecordsConsumedByRegionId =
Collections.unmodifiableList(Arrays.asList(tmpTotalHybridRecordsConsumedByRegionId));
// Register an aggregate metric for disk_usage_in_bytes metric
final boolean isTotalStats = isTotalStats();
registerSensor(
new AsyncGauge(
measurable(
ingestionTaskMap,
storeName,
t -> t.getStorageEngine().getStats().getCachedStoreSizeInBytes(),
t -> t.getStorageEngine().getStats().getStoreSizeInBytes()),
"disk_usage_in_bytes"));
// Register an aggregate metric for rmd_disk_usage_in_bytes metric
registerSensor(
new AsyncGauge(
measurable(
ingestionTaskMap,
storeName,
t -> t.getStorageEngine().getStats().getCachedRMDSizeInBytes(),
t -> t.getStorageEngine().getStats().getRMDSizeInBytes()),
"rmd_disk_usage_in_bytes"));
// Register a metric that records the size of ingestion tasks count
if (isTotalStats) {
registerSensor(new AsyncGauge((ignored, ignored2) -> ingestionTaskMap.size(), "ingestion_task_count"));
}
registerActiveKeyCountGauge(activeKeyCountEnabled, isTotalStats, ingestionTaskMap, storeName);
// Stats which are per-store only:
String keySizeSensorName = "record_key_size_in_bytes";
this.keySizeSensor = registerSensor(keySizeSensorName, avgAndMax());
String valueSizeSensorName = "record_value_size_in_bytes";
this.valueSizeSensor = registerSensor(valueSizeSensorName, avgAndMax());
this.assembledRecordSizeSensor = registerPerStoreAndTotalSensor(
ASSEMBLED_RECORD_SIZE_IN_BYTES,
totalStats,
() -> totalStats.assembledRecordSizeSensor,
new Max());
this.assembledRecordSizeRatioSensor = registerPerStoreAndTotalSensor(
ASSEMBLED_RECORD_SIZE_RATIO,
totalStats,
() -> totalStats.assembledRecordSizeRatioSensor,
new Max());
this.assembledRmdSizeSensor = registerPerStoreAndTotalSensor(
ASSEMBLED_RMD_SIZE_IN_BYTES,
totalStats,
() -> totalStats.assembledRmdSizeSensor,
new Max());
String viewTimerSensorName = "total_view_writer_latency";
this.viewProducerLatencySensor = registerPerStoreAndTotalSensor(
viewTimerSensorName,
totalStats,
() -> totalStats.viewProducerLatencySensor,
avgAndMax());
this.viewProducerAckLatencySensor = registerPerStoreAndTotalSensor(
"total_view_writer_ack_latency",
totalStats,
() -> totalStats.viewProducerAckLatencySensor,
avgAndMax());
registerSensor(new AsyncGauge((ignored, ignored2) -> hybridQuotaUsageGauge, "storage_quota_used"));
// Stats which are both per-store and total:
this.consumerRecordsQueuePutLatencySensor = registerPerStoreAndTotalSensor(
"consumer_records_queue_put_latency",
totalStats,
() -> totalStats.consumerRecordsQueuePutLatencySensor,
avgAndMax());
this.unexpectedMessageSensor = registerPerStoreAndTotalSensor(
"unexpected_message",
totalStats,
() -> totalStats.unexpectedMessageSensor,
new Rate());
this.inconsistentStoreMetadataSensor = registerPerStoreAndTotalSensor(
"inconsistent_store_metadata",
totalStats,
() -> totalStats.inconsistentStoreMetadataSensor,
new Count());
this.ingestionFailureSensor = registerPerStoreAndTotalSensor(
"ingestion_failure",
totalStats,
() -> totalStats.ingestionFailureSensor,
new Count());
this.resubscriptionFailureSensor = registerPerStoreAndTotalSensor(
"resubscription_failure",
totalStats,
() -> totalStats.resubscriptionFailureSensor,
new Count());
this.leaderStepdownStampEmitSuccessSensor = registerPerStoreAndTotalSensor(
"leader_stepdown_stamp_emit_success",
totalStats,
() -> totalStats.leaderStepdownStampEmitSuccessSensor,
new Count());
this.leaderStepdownStampEmitFailureSensor = registerPerStoreAndTotalSensor(
"leader_stepdown_stamp_emit_failure",
totalStats,
() -> totalStats.leaderStepdownStampEmitFailureSensor,
new Count());
this.leaderProducerSynchronizeLatencySensor = registerPerStoreAndTotalSensor(
"leader_producer_synchronize_latency",
totalStats,
() -> totalStats.leaderProducerSynchronizeLatencySensor,
avgAndMax());
this.leaderWriteComputeLookUpLatencySensor = registerPerStoreAndTotalSensor(
"leader_write_compute_lookup_latency",
totalStats,
() -> totalStats.leaderWriteComputeLookUpLatencySensor,
avgAndMax());
this.leaderWriteComputeUpdateLatencySensor = registerPerStoreAndTotalSensor(
"leader_write_compute_update_latency",
totalStats,
() -> totalStats.leaderWriteComputeUpdateLatencySensor,
avgAndMax());
this.processConsumerActionLatencySensor = registerPerStoreAndTotalSensor(
"process_consumer_actions_latency",
totalStats,
() -> totalStats.processConsumerActionLatencySensor,
avgAndMax());
this.checkLongRunningTasksLatencySensor = registerPerStoreAndTotalSensor(
"check_long_running_task_latency",
totalStats,
() -> totalStats.checkLongRunningTasksLatencySensor,
avgAndMax());
String storageEnginePutLatencySensorName = "storage_engine_put_latency",
storageEngineDeleteLatencySensorName = "storage_engine_delete_latency";
this.storageEnginePutLatencySensor = registerPerStoreAndTotalSensor(
storageEnginePutLatencySensorName,
totalStats,
() -> totalStats.storageEnginePutLatencySensor,
avgAndMax());
this.storageEngineDeleteLatencySensor = registerPerStoreAndTotalSensor(
storageEngineDeleteLatencySensorName,
totalStats,
() -> totalStats.storageEngineDeleteLatencySensor,
avgAndMax());
this.writeComputeCacheHitCount = registerPerStoreAndTotalSensor(
"write_compute_cache_hit_count",
totalStats,
() -> totalStats.writeComputeCacheHitCount,
new OccurrenceRate());
this.writeComputeLookupCount = registerPerStoreAndTotalSensor(
"write_compute_lookup_count",
totalStats,
() -> totalStats.writeComputeLookupCount,
new OccurrenceRate());
this.checksumVerificationFailureSensor = registerPerStoreAndTotalSensor(
"checksum_verification_failure",
totalStats,
() -> totalStats.checksumVerificationFailureSensor,
new Count());
this.leaderIngestionValueBytesLookUpLatencySensor = registerPerStoreAndTotalSensor(
"leader_ingestion_value_bytes_lookup_latency",
totalStats,
() -> totalStats.leaderIngestionValueBytesLookUpLatencySensor,
avgAndMax());
this.leaderIngestionValueBytesCacheHitCount = registerPerStoreAndTotalSensor(
"leader_ingestion_value_bytes_cache_hit_count",
totalStats,
() -> totalStats.leaderIngestionValueBytesCacheHitCount,
new Rate());
// Using Rate (not OccurrenceRate) to align with existing cache hit sensor setup
this.leaderIngestionValueBytesLookupCount = registerPerStoreAndTotalSensor(
"leader_ingestion_value_bytes_lookup_count",
totalStats,
() -> totalStats.leaderIngestionValueBytesLookupCount,
new Rate());
this.leaderIngestionReplicationMetadataCacheHitCount = registerPerStoreAndTotalSensor(
"leader_ingestion_replication_metadata_cache_hit_count",
totalStats,
() -> totalStats.leaderIngestionReplicationMetadataCacheHitCount,
new Rate());
// Using Rate (not OccurrenceRate) to align with existing cache hit sensor setup
this.leaderIngestionReplicationMetadataLookupCount = registerPerStoreAndTotalSensor(
"leader_ingestion_replication_metadata_lookup_count",
totalStats,
() -> totalStats.leaderIngestionReplicationMetadataLookupCount,
new Rate());
this.leaderIngestionReplicationMetadataLookUpLatencySensor = registerPerStoreAndTotalSensor(
"leader_ingestion_replication_metadata_lookup_latency",
totalStats,
() -> totalStats.leaderIngestionReplicationMetadataLookUpLatencySensor,
avgAndMax());
this.leaderIngestionActiveActivePutLatencySensor = registerPerStoreAndTotalSensor(
"leader_ingestion_active_active_put_latency",
totalStats,
() -> totalStats.leaderIngestionActiveActivePutLatencySensor,
avgAndMax());
this.leaderIngestionActiveActiveUpdateLatencySensor = registerPerStoreAndTotalSensor(
"leader_ingestion_active_active_update_latency",
totalStats,
() -> totalStats.leaderIngestionActiveActiveUpdateLatencySensor,
avgAndMax());
this.leaderIngestionActiveActiveDeleteLatencySensor = registerPerStoreAndTotalSensor(
"leader_ingestion_active_active_delete_latency",
totalStats,
() -> totalStats.leaderIngestionActiveActiveDeleteLatencySensor,
avgAndMax());
this.leaderProduceLatencySensor = registerPerStoreAndTotalSensor(
"leader_produce_latency",
totalStats,
() -> totalStats.leaderProduceLatencySensor,
avgAndMax());
this.leaderCompressLatencySensor = registerPerStoreAndTotalSensor(
"leader_compress_latency",
totalStats,
() -> totalStats.leaderCompressLatencySensor,
avgAndMax());
this.batchProcessingRequestSensor = registerOnlyTotalRate(
BATCH_PROCESSING_REQUEST,
totalStats,
() -> totalStats.batchProcessingRequestSensor,
time);
this.batchProcessingRequestErrorSensor = registerOnlyTotalRate(
BATCH_PROCESSING_REQUEST_ERROR,
totalStats,
() -> totalStats.batchProcessingRequestErrorSensor,
time);
this.batchProcessingRequestRecordsSensor = registerOnlyTotalRate(
BATCH_PROCESSING_REQUEST_RECORDS,
totalStats,
() -> totalStats.batchProcessingRequestRecordsSensor,
time);
this.batchProcessingRequestSizeSensor = registerOnlyTotalSensor(
BATCH_PROCESSING_REQUEST_SIZE,
totalStats,
() -> totalStats.batchProcessingRequestSizeSensor,
avgAndMax());
this.batchProcessingRequestLatencySensor = registerOnlyTotalSensor(
BATCH_PROCESSING_REQUEST_LATENCY,
totalStats,
() -> totalStats.batchProcessingRequestLatencySensor,
avgAndMax());
}
private Measurable measurable(
Map<String, StoreIngestionTask> sitMap,
String storeName,
ToLongFunction<StoreIngestionTask> total,
ToLongFunction<StoreIngestionTask> individual) {
if (isTotalStats()) {
return (i1, i2) -> sitMap.values().stream().mapToLong(total).sum();
}
return (i1, i2) -> {
StoreIngestionTask sit = sitMap.get(storeName);
if (sit == null) {
/**
* N.B.: For the metrics we currently support, 0 is a sensible fallback in cases where the SIT is not found,
* but if new cases emerge where that would not be desirable, we could make this configurable so that
* the caller can specify some {@link StatsErrorCode} instead...
*/
return 0;
}
return individual.applyAsLong(sit);
};
}
/** Record a host-level byte consumption rate across all store versions */
public void recordTotalBytesConsumed(long bytes) {
totalBytesConsumedRate.record(bytes);
}
/** Record a host-level record consumption rate across all store versions */
public void recordTotalRecordsConsumed() {
totalRecordsConsumedRate.record();
}
/**
* Records the total number of bytes sent during blob transfer operations at the host level.
* This metric aggregates blob transfer send operations across all store versions on the host.
*
* @param bytes the number of bytes sent
*/
public void recordTotalBlobTransferBytesSend(long bytes) {
totalBlobTransferBytesSentRate.record(bytes);
}
/**
* Records the total number of bytes received during blob transfer operations at the host level.
* This metric aggregates blob transfer receive operations across all store versions on the host.
*
* @param bytes the number of bytes received
*/
public void recordTotalBlobTransferBytesReceived(long bytes) {
totalBlobTransferBytesReceivedRate.record(bytes);
}
public void recordTotalBytesReadFromKafkaAsUncompressedSize(long bytes) {
totalBytesReadFromKafkaAsUncompressedSizeRate.record(bytes);
}
public void recordStorageQuotaUsed(double quotaUsed) {
hybridQuotaUsageGauge = quotaUsed;
}
public void recordConsumerRecordsQueuePutLatency(double latency, long currentTimeMs) {
consumerRecordsQueuePutLatencySensor.record(latency, currentTimeMs);
}
public void recordViewProducerLatency(double latency) {
viewProducerLatencySensor.record(latency);
}
public void recordViewProducerAckLatency(double latency) {
viewProducerAckLatencySensor.record(latency);
}
public void recordUnexpectedMessage() {
unexpectedMessageSensor.record();
}
public void recordInconsistentStoreMetadata() {
inconsistentStoreMetadataSensor.record();
}
public void recordKeySize(long bytes, long currentTimeMs) {
keySizeSensor.record(bytes, currentTimeMs);
}
public void recordValueSize(long bytes, long currentTimeMs) {
valueSizeSensor.record(bytes, currentTimeMs);
}
public void recordAssembledRecordSize(long bytes, long currentTimeMs) {
assembledRecordSizeSensor.record(bytes, currentTimeMs);
}
public void recordAssembledRecordSizeRatio(double ratio, long currentTimeMs) {
assembledRecordSizeRatioSensor.record(ratio, currentTimeMs);
}
public void recordAssembledRmdSize(long bytes, long currentTimeMs) {
assembledRmdSizeSensor.record(bytes, currentTimeMs);
}
public void recordIngestionFailure() {
ingestionFailureSensor.record();
}
public void recordResubscriptionFailure() {
resubscriptionFailureSensor.record();
}
public void recordLeaderStepdownStampEmitSuccess() {
leaderStepdownStampEmitSuccessSensor.record();
}
public void recordLeaderStepdownStampEmitFailure() {
leaderStepdownStampEmitFailureSensor.record();
}
public void recordLeaderProducerSynchronizeLatency(double latency) {
leaderProducerSynchronizeLatencySensor.record(latency);
}
public void recordWriteComputeLookUpLatency(double latency) {
leaderWriteComputeLookUpLatencySensor.record(latency);
}
public void recordIngestionValueBytesLookUpLatency(double latency, long currentTime) {
leaderIngestionValueBytesLookUpLatencySensor.record(latency, currentTime);
}
public void recordIngestionValueBytesCacheHitCount(long currentTime) {
leaderIngestionValueBytesCacheHitCount.record(1, currentTime);
}
public void recordIngestionValueBytesLookupCount(long currentTime) {
leaderIngestionValueBytesLookupCount.record(1, currentTime);
}
public void recordIngestionReplicationMetadataLookUpLatency(double latency, long currentTimeMs) {
leaderIngestionReplicationMetadataLookUpLatencySensor.record(latency, currentTimeMs);
}
public void recordIngestionActiveActivePutLatency(double latency) {
leaderIngestionActiveActivePutLatencySensor.record(latency);
}
public void recordIngestionActiveActiveUpdateLatency(double latency) {
leaderIngestionActiveActiveUpdateLatencySensor.record(latency);
}
public void recordIngestionActiveActiveDeleteLatency(double latency) {
leaderIngestionActiveActiveDeleteLatencySensor.record(latency);
}
public void recordWriteComputeUpdateLatency(double latency) {
leaderWriteComputeUpdateLatencySensor.record(latency);
}
public void recordProcessConsumerActionLatency(double latency) {
processConsumerActionLatencySensor.record(latency);
}
public void recordCheckLongRunningTasksLatency(double latency) {
checkLongRunningTasksLatencySensor.record(latency);
}
public void recordStorageEnginePutLatency(double latency, long currentTimeMs) {
storageEnginePutLatencySensor.record(latency, currentTimeMs);
}
public void recordStorageEngineDeleteLatency(double latency, long currentTimeMs) {
storageEngineDeleteLatencySensor.record(latency, currentTimeMs);
}
public void recordWriteComputeCacheHitCount() {
writeComputeCacheHitCount.record();
}
public void recordWriteComputeLookupCount() {
writeComputeLookupCount.record();
}
public void recordIngestionReplicationMetadataCacheHitCount(long currentTimeMs) {
leaderIngestionReplicationMetadataCacheHitCount.record(1, currentTimeMs);
}
public void recordIngestionReplicationMetadataLookupCount(long currentTimeMs) {
leaderIngestionReplicationMetadataLookupCount.record(1, currentTimeMs);
}
public void recordUpdateIgnoredDCR() {
totalUpdateIgnoredDCRRate.record();
}
public void recordTombstoneCreatedDCR() {
totalTombstoneCreationDCRRate.record();
}
public void recordActiveKeyCountInvalidation() {
if (totalActiveKeyCountInvalidationRate != null) {
totalActiveKeyCountInvalidationRate.record();
}
}
/** Uses the ACTIVE_KEY_COUNT_NOT_TRACKED sentinel to distinguish untracked from empty (which {@code measurable()}'s 0-fallback would conflate). */
private void registerActiveKeyCountGauge(
boolean activeKeyCountEnabled,
boolean isTotalStats,
Map<String, StoreIngestionTask> ingestionTaskMap,
String storeName) {
if (!activeKeyCountEnabled) {
return;
}
if (isTotalStats) {
registerSensor(new AsyncGauge((ignored, ignored2) -> {
long total = 0;
boolean anyTracked = false;
for (StoreIngestionTask task: ingestionTaskMap.values()) {
long storeCount = task.getActiveKeyCount();
if (storeCount != ACTIVE_KEY_COUNT_NOT_TRACKED) {
anyTracked = true;
total += storeCount;
}
}
return anyTracked ? total : ACTIVE_KEY_COUNT_NOT_TRACKED;
}, "active_key_count"));
return;
}
registerSensor(new AsyncGauge((ignored, ignored2) -> {
StoreIngestionTask sit = ingestionTaskMap.get(storeName);
return sit == null ? ACTIVE_KEY_COUNT_NOT_TRACKED : sit.getActiveKeyCount();
}, "active_key_count"));
}
public void recordTotalLeaderBytesConsumed(long bytes) {
totalLeaderBytesConsumedRate.record(bytes);
}
public void recordTotalLeaderRecordsConsumed() {
totalLeaderRecordsConsumedRate.record();
}
public void recordTotalFollowerBytesConsumed(long bytes) {
totalFollowerBytesConsumedRate.record(bytes);
}
public void recordTotalFollowerRecordsConsumed() {
totalFollowerRecordsConsumedRate.record();
}
public void recordTotalRegionHybridBytesConsumed(int regionId, long bytes, long currentTimeMs) {
Sensor sensor = totalHybridBytesConsumedByRegionId.get(regionId);
if (sensor != null) {
sensor.record(bytes, currentTimeMs);
}
sensor = totalHybridRecordsConsumedByRegionId.get(regionId);
if (sensor != null) {
sensor.record(1, currentTimeMs);
}
}
public void recordTotalLeaderBytesProduced(long bytes) {
totalLeaderBytesProducedRate.record(bytes);
}
public void recordTotalLeaderRecordsProduced(int count) {
totalLeaderRecordsProducedRate.record(count);
}
public void recordChecksumVerificationFailure() {
checksumVerificationFailureSensor.record();
}
public void recordTimestampRegressionDCRError() {
totalTimestampRegressionDCRErrorRate.record();
}
public void recordOffsetRegressionDCRError() {
totalOffsetRegressionDCRErrorRate.record();
}
public void recordLeaderProduceLatency(double latency) {
leaderProduceLatencySensor.record(latency);
}
public void recordLeaderCompressLatency(double latency) {
leaderCompressLatencySensor.record(latency);
}
public void recordBatchProcessingRequest(int size) {
batchProcessingRequestSensor.record();
batchProcessingRequestRecordsSensor.record(size);
batchProcessingRequestSizeSensor.record(size);
}
public void recordBatchProcessingRequestError() {
batchProcessingRequestErrorSensor.record();
}
public void recordBatchProcessingRequestLatency(double latency) {
batchProcessingRequestLatencySensor.record(latency);
}
}