Skip to content

Commit 8c0615f

Browse files
committed
Merge remote-tracking branch 'origin/migrate-quickwit-metrics-to-metrics-rs' into migrate-quickwit-metrics-to-metrics-rs
# Conflicts: # quickwit/quickwit-lambda-client/src/invoker.rs
2 parents 13d8843 + aca9f7f commit 8c0615f

75 files changed

Lines changed: 1020 additions & 1304 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

quickwit/quickwit-actors/src/mailbox.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ use std::any::Any;
1616
use std::convert::Infallible;
1717
use std::fmt;
1818
use std::sync::atomic::{AtomicUsize, Ordering};
19-
use std::sync::{Arc, LazyLock, Weak};
19+
use std::sync::{Arc, Weak};
2020
use std::time::Instant;
2121

22-
use quickwit_metrics::{Counter, Gauge, GaugeGuard, gauge};
22+
use quickwit_metrics::{Counter, GaugeGuard, LazyGauge, lazy_gauge};
2323
use tokio::sync::oneshot;
2424

2525
use crate::channel_with_priority::{Receiver, Sender, TrySendError};
@@ -205,7 +205,7 @@ impl<A: Actor> Mailbox<A> {
205205
let now = Instant::now();
206206
self.inner.tx.send_low_priority(envelope).await?;
207207
let elapsed = now.elapsed();
208-
backpressure_micros_counter.increment(elapsed.as_micros() as u64);
208+
backpressure_micros_counter.inc_by(elapsed.as_micros() as u64);
209209
} else {
210210
self.inner.tx.send_low_priority(envelope).await?;
211211
}
@@ -311,13 +311,11 @@ struct InboxInner<A: Actor> {
311311
_inboxes_count_gauge_guard: GaugeGuard,
312312
}
313313

314-
static INBOX_GAUGE: LazyLock<Gauge> = LazyLock::new(|| {
315-
gauge!(
314+
static INBOX_GAUGE: LazyGauge = lazy_gauge!(
316315
name: "inboxes_count",
317316
description: "overall count of actors",
318317
subsystem: "actor",
319-
)
320-
});
318+
);
321319

322320
pub struct Inbox<A: Actor> {
323321
inner: Arc<InboxInner<A>>,

quickwit/quickwit-cli/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ pub mod busy_detector {
387387
.unwrap_or_default();
388388
let now = now.as_micros() as u64;
389389
let delta = now - time.load(Ordering::Relaxed);
390-
THREAD_UNPARK_DURATION_MICROSECONDS.record(delta as f64);
390+
THREAD_UNPARK_DURATION_MICROSECONDS.observe(delta as f64);
391391
if delta > ALLOWED_DELAY_MICROS {
392392
emit_debug(delta, now);
393393
}

quickwit/quickwit-cli/src/metrics.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,15 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use std::sync::LazyLock;
16-
1715
use quickwit_common::metrics::exponential_buckets;
18-
use quickwit_metrics::{Counter, Histogram, counter, histogram, labels};
16+
use quickwit_metrics::{LazyCounter, LazyHistogram, counter, labels, lazy_counter, lazy_histogram};
1917
use quickwit_serve::BuildInfo;
2018

21-
static BUILD_INFO: LazyLock<Counter> = LazyLock::new(|| {
22-
counter!(
19+
static BUILD_INFO: LazyCounter = lazy_counter!(
2320
name: "build_info",
2421
description: "Quickwit's build info",
2522
subsystem: "",
26-
)
27-
});
23+
);
2824
pub fn register_build_info_metric(build_info: &BuildInfo) {
2925
let commit_tags = build_info.commit_tags.join(",");
3026
let labels = labels!(
@@ -34,14 +30,12 @@ pub fn register_build_info_metric(build_info: &BuildInfo) {
3430
"commit_tags" => commit_tags,
3531
"target" => build_info.build_target,
3632
);
37-
counter!(parent: BUILD_INFO, labels: [labels]).increment(1);
33+
counter!(parent: BUILD_INFO, labels: [labels]).inc();
3834
}
3935

40-
pub(crate) static THREAD_UNPARK_DURATION_MICROSECONDS: LazyLock<Histogram> = LazyLock::new(|| {
41-
histogram!(
36+
pub(crate) static THREAD_UNPARK_DURATION_MICROSECONDS: LazyHistogram = lazy_histogram!(
4237
name: "thread_unpark_duration_microseconds",
4338
description: "Duration for which a thread of the main tokio runtime is unparked.",
4439
subsystem: "cli",
4540
buckets: exponential_buckets(5.0, 5.0, 5).unwrap(),
46-
)
47-
});
41+
);

quickwit/quickwit-cluster/src/grpc_gossip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ async fn perform_grpc_gossip_rounds<ClusterServiceClientFactory, Fut>(
108108
warn!("failed to fetch cluster state from node `{node_id}`");
109109
continue;
110110
};
111-
GRPC_GOSSIP_ROUNDS_TOTAL.increment(1);
111+
GRPC_GOSSIP_ROUNDS_TOTAL.inc();
112112

113113
let mut chitchat_guard = chitchat.lock().await;
114114

quickwit/quickwit-cluster/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@ impl Socket for CountingUdpSocket {
8484
async fn send(&mut self, to: SocketAddr, msg: ChitchatMessage) -> anyhow::Result<()> {
8585
let msg_len = msg.serialized_len() as u64;
8686
self.socket.send(to, msg).await?;
87-
GOSSIP_SENT_MESSAGES_TOTAL.increment(1);
88-
GOSSIP_SENT_BYTES_TOTAL.increment(msg_len);
87+
GOSSIP_SENT_MESSAGES_TOTAL.inc();
88+
GOSSIP_SENT_BYTES_TOTAL.inc_by(msg_len);
8989
Ok(())
9090
}
9191

9292
async fn recv(&mut self) -> anyhow::Result<(SocketAddr, ChitchatMessage)> {
9393
let (socket_addr, msg) = self.socket.recv().await?;
94-
GOSSIP_RECV_MESSAGES_TOTAL.increment(1);
94+
GOSSIP_RECV_MESSAGES_TOTAL.inc();
9595
let msg_len = msg.serialized_len() as u64;
96-
GOSSIP_RECV_BYTES_TOTAL.increment(msg_len);
96+
GOSSIP_RECV_BYTES_TOTAL.inc_by(msg_len);
9797
Ok((socket_addr, msg))
9898
}
9999
}

quickwit/quickwit-cluster/src/metrics.rs

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,110 +14,86 @@
1414

1515
use std::collections::HashSet;
1616
use std::net::SocketAddr;
17-
use std::sync::{LazyLock, Weak};
17+
use std::sync::Weak;
1818
use std::time::Duration;
1919

2020
use chitchat::{Chitchat, ChitchatId};
21-
use quickwit_metrics::{Counter, Gauge, counter, gauge};
21+
use quickwit_metrics::{LazyCounter, LazyGauge, lazy_counter, lazy_gauge};
2222
use tokio::sync::Mutex;
2323

2424
use crate::member::NodeStateExt;
2525

26-
pub(crate) static LIVE_NODES: LazyLock<Gauge> = LazyLock::new(|| {
27-
gauge!(
26+
pub(crate) static LIVE_NODES: LazyGauge = lazy_gauge!(
2827
name: "live_nodes",
2928
description: "The number of live nodes observed locally.",
3029
subsystem: "cluster",
31-
)
32-
});
30+
);
3331

34-
pub(crate) static READY_NODES: LazyLock<Gauge> = LazyLock::new(|| {
35-
gauge!(
32+
pub(crate) static READY_NODES: LazyGauge = lazy_gauge!(
3633
name: "ready_nodes",
3734
description: "The number of ready nodes observed locally.",
3835
subsystem: "cluster",
39-
)
40-
});
36+
);
4137

42-
pub(crate) static ZOMBIE_NODES: LazyLock<Gauge> = LazyLock::new(|| {
43-
gauge!(
38+
pub(crate) static ZOMBIE_NODES: LazyGauge = lazy_gauge!(
4439
name: "zombie_nodes",
4540
description: "The number of zombie nodes observed locally.",
4641
subsystem: "cluster",
47-
)
48-
});
42+
);
4943

50-
pub(crate) static DEAD_NODES: LazyLock<Gauge> = LazyLock::new(|| {
51-
gauge!(
44+
pub(crate) static DEAD_NODES: LazyGauge = lazy_gauge!(
5245
name: "dead_nodes",
5346
description: "The number of dead nodes observed locally.",
5447
subsystem: "cluster",
55-
)
56-
});
48+
);
5749

58-
pub(crate) static CLUSTER_STATE_SIZE_BYTES: LazyLock<Gauge> = LazyLock::new(|| {
59-
gauge!(
50+
pub(crate) static CLUSTER_STATE_SIZE_BYTES: LazyGauge = lazy_gauge!(
6051
name: "cluster_state_size_bytes",
6152
description: "The size of the cluster state in bytes.",
6253
subsystem: "cluster",
63-
)
64-
});
54+
);
6555

66-
pub(crate) static NODE_STATE_KEYS: LazyLock<Gauge> = LazyLock::new(|| {
67-
gauge!(
56+
pub(crate) static NODE_STATE_KEYS: LazyGauge = lazy_gauge!(
6857
name: "node_state_keys",
6958
description: "The number of keys in the node state.",
7059
subsystem: "cluster",
71-
)
72-
});
60+
);
7361

74-
pub(crate) static NODE_STATE_SIZE_BYTES: LazyLock<Gauge> = LazyLock::new(|| {
75-
gauge!(
62+
pub(crate) static NODE_STATE_SIZE_BYTES: LazyGauge = lazy_gauge!(
7663
name: "node_state_size_bytes",
7764
description: "The size of the node state in bytes.",
7865
subsystem: "cluster",
79-
)
80-
});
66+
);
8167

82-
pub(crate) static GOSSIP_RECV_MESSAGES_TOTAL: LazyLock<Counter> = LazyLock::new(|| {
83-
counter!(
68+
pub(crate) static GOSSIP_RECV_MESSAGES_TOTAL: LazyCounter = lazy_counter!(
8469
name: "gossip_recv_messages_total",
8570
description: "Total number of gossip messages received.",
8671
subsystem: "cluster",
87-
)
88-
});
72+
);
8973

90-
pub(crate) static GOSSIP_RECV_BYTES_TOTAL: LazyLock<Counter> = LazyLock::new(|| {
91-
counter!(
74+
pub(crate) static GOSSIP_RECV_BYTES_TOTAL: LazyCounter = lazy_counter!(
9275
name: "gossip_recv_bytes_total",
9376
description: "Total amount of gossip data received in bytes.",
9477
subsystem: "cluster",
95-
)
96-
});
78+
);
9779

98-
pub(crate) static GOSSIP_SENT_MESSAGES_TOTAL: LazyLock<Counter> = LazyLock::new(|| {
99-
counter!(
80+
pub(crate) static GOSSIP_SENT_MESSAGES_TOTAL: LazyCounter = lazy_counter!(
10081
name: "gossip_sent_messages_total",
10182
description: "Total number of gossip messages sent.",
10283
subsystem: "cluster",
103-
)
104-
});
84+
);
10585

106-
pub(crate) static GOSSIP_SENT_BYTES_TOTAL: LazyLock<Counter> = LazyLock::new(|| {
107-
counter!(
86+
pub(crate) static GOSSIP_SENT_BYTES_TOTAL: LazyCounter = lazy_counter!(
10887
name: "gossip_sent_bytes_total",
10988
description: "Total amount of gossip data sent in bytes.",
11089
subsystem: "cluster",
111-
)
112-
});
90+
);
11391

114-
pub(crate) static GRPC_GOSSIP_ROUNDS_TOTAL: LazyLock<Counter> = LazyLock::new(|| {
115-
counter!(
92+
pub(crate) static GRPC_GOSSIP_ROUNDS_TOTAL: LazyCounter = lazy_counter!(
11693
name: "grpc_gossip_rounds_total",
11794
description: "Total number of gRPC gossip rounds performed with peer nodes.",
11895
subsystem: "cluster",
119-
)
120-
});
96+
);
12197

12298
pub(crate) fn spawn_metrics_task(
12399
weak_chitchat: Weak<Mutex<Chitchat>>,

quickwit/quickwit-common/src/io.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use std::future::Future;
2525
use std::io;
2626
use std::io::IoSlice;
2727
use std::pin::Pin;
28-
use std::sync::LazyLock;
2928
use std::task::{Context, Poll};
3029
use std::time::Duration;
3130

@@ -34,7 +33,7 @@ use async_speed_limit::clock::StandardClock;
3433
use async_speed_limit::limiter::Consume;
3534
use bytesize::ByteSize;
3635
use pin_project::pin_project;
37-
use quickwit_metrics::{Counter, counter};
36+
use quickwit_metrics::{Counter, LazyCounter, counter, lazy_counter};
3837
use tokio::io::AsyncWrite;
3938

4039
use crate::{KillSwitch, Progress, ProtectedZoneGuard};
@@ -47,13 +46,11 @@ fn truncate_bytes(bytes: &[u8]) -> &[u8] {
4746
&bytes[..num_bytes]
4847
}
4948

50-
static WRITE_BYTES: LazyLock<Counter> = LazyLock::new(|| {
51-
counter!(
49+
static WRITE_BYTES: LazyCounter = lazy_counter!(
5250
name: "write_bytes",
5351
description: "Number of bytes written by a given component in [indexer, merger, deleter, split_downloader_{merge,delete}]",
5452
subsystem: "",
55-
)
56-
});
53+
);
5754

5855
/// Parameter used in `async_speed_limit`.
5956
///
@@ -155,7 +152,7 @@ impl IoControls {
155152
if let Some(throughput_limiter) = &self.throughput_limiter_opt {
156153
throughput_limiter.blocking_consume(num_bytes);
157154
}
158-
self.bytes_counter.increment(num_bytes as u64);
155+
self.bytes_counter.inc_by(num_bytes as u64);
159156
Ok(())
160157
}
161158
}
@@ -208,7 +205,7 @@ impl<A: IoControlsAccess, W: AsyncWrite> ControlledWrite<A, W> {
208205
let len = *obj.as_ref().unwrap_or(&0);
209206
if len > 0 {
210207
let waiter = this.io_controls_access.apply(|io_controls| {
211-
io_controls.bytes_counter.increment(len as u64);
208+
io_controls.bytes_counter.inc_by(len as u64);
212209
io_controls
213210
.throughput_limiter_opt
214211
.as_ref()

0 commit comments

Comments
 (0)