Skip to content

Commit ec1add6

Browse files
committed
Fixing GaugeGuard's API
1 parent 1d96c6b commit ec1add6

File tree

17 files changed

+71
-51
lines changed

17 files changed

+71
-51
lines changed

quickwit/quickwit-actors/src/mailbox.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,7 @@ fn get_actor_inboxes_count_gauge_guard() -> GaugeGuard<'static> {
395395
&[],
396396
)
397397
});
398-
let mut gauge_guard = GaugeGuard::from_gauge(gauge);
399-
gauge_guard.add(1);
400-
gauge_guard
398+
GaugeGuard::from_gauge_with_initial_value(gauge, 1)
401399
}
402400

403401
pub(crate) fn create_mailbox<A: Actor>(

quickwit/quickwit-common/src/metrics.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,13 @@ impl std::fmt::Debug for GaugeGuard<'_> {
219219
}
220220

221221
impl<'a> GaugeGuard<'a> {
222-
pub fn from_gauge(gauge: &'a IntGauge) -> Self {
223-
Self { gauge, delta: 0i64 }
222+
pub fn from_gauge_with_initial_value(gauge: &'a IntGauge, initial_value: i64) -> Self {
223+
let mut gauge = Self {
224+
gauge,
225+
delta: initial_value,
226+
};
227+
gauge.add(initial_value);
228+
gauge
224229
}
225230

226231
pub fn get(&self) -> i64 {
@@ -256,8 +261,10 @@ impl std::fmt::Debug for OwnedGaugeGuard {
256261
}
257262

258263
impl OwnedGaugeGuard {
259-
pub fn from_gauge(gauge: IntGauge) -> Self {
260-
Self { gauge, delta: 0i64 }
264+
pub fn from_gauge_with_initial_value(gauge: IntGauge, initial_value: i64) -> Self {
265+
let mut gauge = Self { gauge, delta: 0i64 };
266+
gauge.add(initial_value);
267+
gauge
261268
}
262269

263270
pub fn get(&self) -> i64 {

quickwit/quickwit-common/src/stream_utils.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,8 @@ where T: fmt::Debug
240240

241241
impl<T> InFlightValue<T> {
242242
pub fn new(value: T, value_size: ByteSize, gauge: &'static IntGauge) -> Self {
243-
let mut gauge_guard = GaugeGuard::from_gauge(gauge);
244-
gauge_guard.add(value_size.as_u64() as i64);
245-
243+
let gauge_guard =
244+
GaugeGuard::from_gauge_with_initial_value(gauge, value_size.as_u64() as i64);
246245
Self(value, gauge_guard)
247246
}
248247

quickwit/quickwit-common/src/thread_pool.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,17 @@ impl ThreadPool {
8585
{
8686
let span = tracing::Span::current();
8787
let ongoing_tasks = self.ongoing_tasks.clone();
88-
let mut pending_tasks_guard: OwnedGaugeGuard =
89-
OwnedGaugeGuard::from_gauge(self.pending_tasks.clone());
90-
pending_tasks_guard.add(1i64);
88+
let pending_tasks_guard: OwnedGaugeGuard =
89+
OwnedGaugeGuard::from_gauge_with_initial_value(self.pending_tasks.clone(), 1i64);
9190
let (tx, rx) = oneshot::channel();
9291
self.thread_pool.spawn(move || {
9392
drop(pending_tasks_guard);
9493
if tx.is_closed() {
9594
return;
9695
}
9796
let _guard = span.enter();
98-
let mut ongoing_task_guard = GaugeGuard::from_gauge(&ongoing_tasks);
99-
ongoing_task_guard.add(1i64);
97+
let _ongoing_task_guard =
98+
GaugeGuard::from_gauge_with_initial_value(&ongoing_tasks, 1i64);
10099
let result = cpu_intensive_fn();
101100
let _ = tx.send(result);
102101
});

quickwit/quickwit-indexing/src/actors/indexer.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,10 @@ impl IndexerState {
219219
let publish_lock = self.publish_lock.clone();
220220
let publish_token_opt = self.publish_token_opt.clone();
221221

222-
let mut split_builders_guard =
223-
GaugeGuard::from_gauge(&crate::metrics::INDEXER_METRICS.split_builders);
224-
split_builders_guard.add(1);
222+
let split_builders_guard = GaugeGuard::from_gauge_with_initial_value(
223+
&crate::metrics::INDEXER_METRICS.split_builders,
224+
1,
225+
);
225226

226227
let workbench = IndexingWorkbench {
227228
workbench_id,
@@ -233,10 +234,11 @@ impl IndexerState {
233234
publish_lock,
234235
publish_token_opt,
235236
last_delete_opstamp,
236-
memory_usage: GaugeGuard::from_gauge(
237+
memory_usage: GaugeGuard::from_gauge_with_initial_value(
237238
&quickwit_common::metrics::MEMORY_METRICS
238239
.in_flight
239240
.index_writer,
241+
0i64,
240242
),
241243
cooperative_indexing_period,
242244
split_builders_guard,

quickwit/quickwit-indexing/src/actors/indexing_pipeline.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ impl IndexingPipeline {
159159
let indexing_pipelines_gauge = crate::metrics::INDEXER_METRICS
160160
.indexing_pipelines
161161
.with_label_values([&params.pipeline_id.index_uid.index_id]);
162-
let mut indexing_pipelines_gauge_guard =
163-
OwnedGaugeGuard::from_gauge(indexing_pipelines_gauge);
164-
indexing_pipelines_gauge_guard.add(1);
162+
let indexing_pipelines_gauge_guard =
163+
OwnedGaugeGuard::from_gauge_with_initial_value(indexing_pipelines_gauge, 1);
165164
let params_fingerprint = params.params_fingerprint;
166165
IndexingPipeline {
167166
params,

quickwit/quickwit-indexing/src/models/processed_doc.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ impl ProcessedDocBatch {
5151
force_commit: bool,
5252
) -> Self {
5353
let delta = docs.iter().map(|doc| doc.num_bytes as i64).sum::<i64>();
54-
let mut gauge_guard = GaugeGuard::from_gauge(&MEMORY_METRICS.in_flight.indexer_mailbox);
55-
gauge_guard.add(delta);
54+
let gauge_guard = GaugeGuard::from_gauge_with_initial_value(
55+
&MEMORY_METRICS.in_flight.indexer_mailbox,
56+
delta,
57+
);
5658
Self {
5759
docs,
5860
checkpoint_delta,

quickwit/quickwit-indexing/src/models/raw_doc_batch.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ impl RawDocBatch {
3434
force_commit: bool,
3535
) -> Self {
3636
let delta = docs.iter().map(|doc| doc.len() as i64).sum::<i64>();
37-
let mut gauge_guard =
38-
GaugeGuard::from_gauge(&MEMORY_METRICS.in_flight.doc_processor_mailbox);
39-
gauge_guard.add(delta);
37+
let gauge_guard = GaugeGuard::from_gauge_with_initial_value(
38+
&MEMORY_METRICS.in_flight.doc_processor_mailbox,
39+
delta,
40+
);
4041

4142
Self {
4243
docs,
@@ -67,7 +68,10 @@ impl fmt::Debug for RawDocBatch {
6768

6869
impl Default for RawDocBatch {
6970
fn default() -> Self {
70-
let _gauge_guard = GaugeGuard::from_gauge(&MEMORY_METRICS.in_flight.doc_processor_mailbox);
71+
let _gauge_guard = GaugeGuard::from_gauge_with_initial_value(
72+
&MEMORY_METRICS.in_flight.doc_processor_mailbox,
73+
0i64,
74+
);
7175
Self {
7276
docs: Vec::new(),
7377
checkpoint_delta: SourceCheckpointDelta::default(),

quickwit/quickwit-indexing/src/source/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ impl BatchBuilder {
532532
SourceType::Pulsar => MEMORY_METRICS.in_flight.pulsar(),
533533
_ => MEMORY_METRICS.in_flight.other(),
534534
};
535-
let gauge_guard = GaugeGuard::from_gauge(gauge);
535+
let gauge_guard = GaugeGuard::from_gauge_with_initial_value(gauge, 0i64);
536536

537537
Self {
538538
docs: Vec::with_capacity(capacity),

quickwit/quickwit-ingest/src/ingest_v2/ingester.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,8 +1115,10 @@ impl IngesterService for Ingester {
11151115
_ => None,
11161116
})
11171117
.sum::<usize>();
1118-
let mut gauge_guard = GaugeGuard::from_gauge(&MEMORY_METRICS.in_flight.ingester_persist);
1119-
gauge_guard.add(request_size_bytes as i64);
1118+
let _gauge_guard = GaugeGuard::from_gauge_with_initial_value(
1119+
&MEMORY_METRICS.in_flight.ingester_persist,
1120+
request_size_bytes as i64,
1121+
);
11201122

11211123
self.persist_inner(persist_request).await
11221124
}

0 commit comments

Comments
 (0)