Skip to content

Commit e8e59ec

Browse files
authored
Feat[STATS]: Report partition offsets (#922)
Signed-off-by: Anton Pryakhin <[email protected]>
1 parent b6028b2 commit e8e59ec

File tree

4 files changed

+64
-23
lines changed

4 files changed

+64
-23
lines changed

src/groups/mqb/mqbs/mqbs_filestore.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3973,10 +3973,11 @@ int FileStore::issueSyncPointInternal(SyncPointType::Enum type,
39733973
immediateFlush);
39743974

39753975
// Report cluster's partition stats
3976-
d_clusterStats_p->setPartitionOutstandingBytes(
3977-
d_config.partitionId(),
3978-
fs->d_outstandingBytesData,
3979-
fs->d_outstandingBytesJournal);
3976+
d_clusterStats_p->setPartitionBytes(d_config.partitionId(),
3977+
fs->d_outstandingBytesData,
3978+
fs->d_outstandingBytesJournal,
3979+
fs->d_dataFilePosition,
3980+
fs->d_journalFilePosition);
39803981

39813982
return rc_SUCCESS;
39823983
}
@@ -4324,10 +4325,10 @@ int FileStore::writeQueueCreationRecord(
43244325
// Create in-memory record.
43254326
DataStoreRecordHandle handle;
43264327
DataStoreRecord record(RecordType::e_QUEUE_OP,
4327-
recordOffset,
4328-
queueRecLength);
4328+
recordOffset,
4329+
queueRecLength);
43294330
DataStoreRecordKey key(recHeader.sequenceNumber(),
4330-
recHeader.primaryLeaseId());
4331+
recHeader.primaryLeaseId());
43314332

43324333
insertDataStoreRecord(&handle, key, record);
43334334

@@ -5207,10 +5208,12 @@ int FileStore::open(const QueueKeyInfoMap& queueKeyInfoMap)
52075208
BSLS_ASSERT_SAFE(d_isOpen);
52085209

52095210
// Report cluster's partition stats
5210-
d_clusterStats_p->setPartitionOutstandingBytes(
5211-
d_config.partitionId(),
5212-
d_fileSets[0].get()->d_outstandingBytesData,
5213-
d_fileSets[0].get()->d_outstandingBytesJournal);
5211+
const FileSet* fs = d_fileSets[0].get();
5212+
d_clusterStats_p->setPartitionBytes(d_config.partitionId(),
5213+
fs->d_outstandingBytesData,
5214+
fs->d_outstandingBytesJournal,
5215+
fs->d_dataFilePosition,
5216+
fs->d_journalFilePosition);
52145217

52155218
return rc_SUCCESS;
52165219
}

src/groups/mqb/mqbstat/mqbstat_clusterstats.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ struct ClusterStatsIndex {
9191
,
9292
e_PARTITION_JOURNAL_BYTES
9393
// Value: Outstanding bytes in the journal file of the partition.
94+
,
95+
e_PARTITION_DATA_OFFSET_BYTES
96+
// Value: Offset bytes in the data file of the partition.
97+
,
98+
e_PARTITION_JOURNAL_OFFSET_BYTES
99+
// Value: Offset bytes in the journal file of the partition.
94100
};
95101
};
96102

@@ -196,6 +202,12 @@ bsls::Types::Int64 ClusterStats::getValue(const bmqst::StatContext& context,
196202
return value == bsl::numeric_limits<bsls::Types::Int64>::min() ? 0
197203
: value;
198204
}
205+
case Stat::e_PARTITION_DATA_OFFSET: {
206+
return STAT_SINGLE(value, e_PARTITION_DATA_OFFSET_BYTES);
207+
}
208+
case Stat::e_PARTITION_JOURNAL_OFFSET: {
209+
return STAT_SINGLE(value, e_PARTITION_JOURNAL_OFFSET_BYTES);
210+
}
199211
case Stat::e_PARTITION_DATA_UTILIZATION_MAX: {
200212
const bsls::Types::Int64 value = STAT_RANGE(rangeMax,
201213
e_PARTITION_DATA_BYTES);
@@ -395,9 +407,11 @@ ClusterStats& ClusterStats::setNodeRoleForPartition(int partitionId,
395407
}
396408

397409
ClusterStats&
398-
ClusterStats::setPartitionOutstandingBytes(int partitionId,
399-
bsls::Types::Int64 dataBytes,
400-
bsls::Types::Int64 journalBytes)
410+
ClusterStats::setPartitionBytes(int partitionId,
411+
bsls::Types::Int64 outstandingDataBytes,
412+
bsls::Types::Int64 outstandingJournalBytes,
413+
bsls::Types::Int64 offsetDataBytes,
414+
bsls::Types::Int64 offsetJournalBytes)
401415
{
402416
// PRECONDITIONS
403417
BSLS_ASSERT_SAFE(partitionId >= 0 &&
@@ -408,10 +422,16 @@ ClusterStats::setPartitionOutstandingBytes(int partitionId,
408422

409423
d_partitionsStatContexts[partitionId]->reportValue(
410424
ClusterStatsIndex::e_PARTITION_DATA_BYTES,
411-
dataBytes);
425+
outstandingDataBytes);
412426
d_partitionsStatContexts[partitionId]->reportValue(
413427
ClusterStatsIndex::e_PARTITION_JOURNAL_BYTES,
414-
journalBytes);
428+
outstandingJournalBytes);
429+
d_partitionsStatContexts[partitionId]->setValue(
430+
ClusterStatsIndex::e_PARTITION_DATA_OFFSET_BYTES,
431+
offsetDataBytes);
432+
d_partitionsStatContexts[partitionId]->setValue(
433+
ClusterStatsIndex::e_PARTITION_JOURNAL_OFFSET_BYTES,
434+
offsetJournalBytes);
415435
return *this;
416436
}
417437

@@ -571,7 +591,9 @@ ClusterStatsUtil::initializeStatContextCluster(int historySize,
571591
.value("partition_status")
572592
.value("partition.rollover_time", bmqst::StatValue::e_DISCRETE)
573593
.value("partition.data_bytes", bmqst::StatValue::e_DISCRETE)
574-
.value("partition.journal_bytes", bmqst::StatValue::e_DISCRETE);
594+
.value("partition.journal_bytes", bmqst::StatValue::e_DISCRETE)
595+
.value("partition.data_offset_bytes")
596+
.value("partition.journal_offset_bytes");
575597

576598
// NOTE: For the clusters, the stat context will have two levels of
577599
// children, first level is per cluster, and second level is per

src/groups/mqb/mqbstat/mqbstat_clusterstats.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ class ClusterStats {
106106
/// Maximum observed outstanding bytes in the journal file of the
107107
/// partition.
108108
e_PARTITION_JOURNAL_CONTENT,
109+
/// Latest observed offset bytes in the data file of the partition.
110+
e_PARTITION_DATA_OFFSET,
111+
/// Latest observed offset bytes in the journal file of the
112+
/// partition.
113+
e_PARTITION_JOURNAL_OFFSET,
109114
/// Maximum observed utilization of the data file of the partition.
110115
e_PARTITION_DATA_UTILIZATION_MAX,
111116
/// Maximum observed utilization of the journal file of the
@@ -258,11 +263,13 @@ class ClusterStats {
258263

259264
/// Set the partition outstanding bytes of the specified data and
260265
/// journal files for the specified `partitionId` to the corresponding
261-
/// specified `dataBytes` and `journalBytes` values.
262-
ClusterStats&
263-
setPartitionOutstandingBytes(int partitionId,
264-
bsls::Types::Int64 dataBytes,
265-
bsls::Types::Int64 journalBytes);
266+
/// specified `outstandingDataBytes`, `outstandingJournalBytes`,
267+
/// `offsetDataBytes` and `offsetJournalBytes` values.
268+
ClusterStats& setPartitionBytes(int partitionId,
269+
bsls::Types::Int64 outstandingDataBytes,
270+
bsls::Types::Int64 outstandingJournalBytes,
271+
bsls::Types::Int64 offsetDataBytes,
272+
bsls::Types::Int64 offsetJournalBytes);
266273

267274
/// Return a pointer to the statcontext.
268275
bmqst::StatContext* statContext();

src/plugins/bmqprometheus/bmqprometheus_prometheusstatconsumer.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,11 +736,14 @@ void PrometheusStatConsumer::captureClusterPartitionsStats()
736736
// Generate the metric name from the partition name (e.g.,
737737
// 'cluster_partition1_rollover_time')
738738
const bsl::string prefix = "cluster_" + partitionIt->name() + "_";
739-
const bsl::string rollover_time = prefix + "rollover_time";
739+
const bsl::string rollover_time = prefix + "rollover_time";
740+
const bsl::string journal_offset_bytes = prefix +
741+
"journal_offset_bytes";
740742
const bsl::string journal_outstanding_bytes =
741743
prefix + "journal_outstanding_bytes";
742744
const bsl::string journal_utilization = prefix +
743745
"journal_utilization_max";
746+
const bsl::string data_offset_bytes = prefix + "data_offset_bytes";
744747
const bsl::string data_outstanding_bytes =
745748
prefix + "data_outstanding_bytes";
746749
const bsl::string data_utilization = prefix +
@@ -750,13 +753,19 @@ void PrometheusStatConsumer::captureClusterPartitionsStats()
750753
{rollover_time.c_str(),
751754
mqbstat::ClusterStats::Stat::e_PARTITION_ROLLOVER_TIME,
752755
false},
756+
{journal_offset_bytes.c_str(),
757+
mqbstat::ClusterStats::Stat::e_PARTITION_JOURNAL_OFFSET,
758+
false},
753759
{journal_outstanding_bytes.c_str(),
754760
mqbstat::ClusterStats::Stat::e_PARTITION_JOURNAL_CONTENT,
755761
false},
756762
{journal_utilization.c_str(),
757763
mqbstat::ClusterStats::Stat::
758764
e_PARTITION_JOURNAL_UTILIZATION_MAX,
759765
false},
766+
{data_offset_bytes.c_str(),
767+
mqbstat::ClusterStats::Stat::e_PARTITION_DATA_OFFSET,
768+
false},
760769
{data_outstanding_bytes.c_str(),
761770
mqbstat::ClusterStats::Stat::e_PARTITION_DATA_CONTENT,
762771
false},

0 commit comments

Comments
 (0)