Skip to content

Commit 29263be

Browse files
committed
fix: publish the stats correctly
Signed-off-by: Rustin170506 <[email protected]>
1 parent 530a45d commit 29263be

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

console-subscriber/src/aggregator/mod.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ pub struct Aggregator {
4949
/// buffer is approaching capacity.
5050
shared: Arc<Shared>,
5151

52+
/// Currently active RPCs streaming state events.
53+
state_watchers: ShrinkVec<Watch<proto::instrument::State>>,
54+
5255
/// Currently active RPCs streaming task events.
5356
watchers: ShrinkVec<Watch<proto::instrument::Update>>,
5457

@@ -148,6 +151,7 @@ impl Aggregator {
148151
events,
149152
watchers: Default::default(),
150153
details_watchers: Default::default(),
154+
state_watchers: Default::default(),
151155
all_metadata: Default::default(),
152156
new_metadata: Default::default(),
153157
tasks: IdData::default(),
@@ -195,11 +199,8 @@ impl Aggregator {
195199
self.add_task_detail_subscription(watch_request);
196200
},
197201
Some(Command::WatchState(subscription)) => {
198-
let state = proto::instrument::State {
199-
temporality: self.temporality.into(),
200-
};
201-
subscription.update(&state);
202-
},
202+
self.add_state_subscription(subscription);
203+
}
203204
Some(Command::Pause) => {
204205
self.temporality = proto::instrument::Temporality::Paused;
205206
}
@@ -214,7 +215,6 @@ impl Aggregator {
214215

215216
false
216217
}
217-
218218
};
219219

220220
// drain and aggregate buffered events.
@@ -252,6 +252,10 @@ impl Aggregator {
252252
"event channel drain loop",
253253
);
254254

255+
if !self.state_watchers.is_empty() {
256+
self.publish_state();
257+
}
258+
255259
// flush data to clients, if there are any currently subscribed
256260
// watchers and we should send a new update.
257261
if !self.watchers.is_empty() && should_send {
@@ -396,6 +400,20 @@ impl Aggregator {
396400
// If the task is not found, drop `stream_sender` which will result in a not found error
397401
}
398402

403+
/// Add a state subscription to the watchers.
404+
fn add_state_subscription(&mut self, subscription: Watch<proto::instrument::State>) {
405+
self.state_watchers.push(subscription);
406+
}
407+
408+
/// Publish the current state to all active state watchers.
409+
fn publish_state(&mut self) {
410+
let state = proto::instrument::State {
411+
temporality: self.temporality.into(),
412+
};
413+
self.state_watchers
414+
.retain_and_shrink(|watch| watch.update(&state));
415+
}
416+
399417
/// Publish the current state to all active watchers.
400418
///
401419
/// This drops any watchers which have closed the RPC, or whose update

tokio-console/src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@ async fn main() -> color_eyre::Result<()> {
9595
if input::is_space(&input) {
9696
if state.is_paused() {
9797
conn.resume().await;
98-
state.resume();
9998
} else {
10099
conn.pause().await;
101-
state.pause();
102100
}
103101
}
104102

tokio-console/src/state/mod.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -233,16 +233,6 @@ impl State {
233233
*self.current_task_details.borrow_mut() = None;
234234
}
235235

236-
// temporality methods
237-
238-
pub(crate) fn pause(&mut self) {
239-
self.temporality = proto::instrument::Temporality::Paused;
240-
}
241-
242-
pub(crate) fn resume(&mut self) {
243-
self.temporality = proto::instrument::Temporality::Live;
244-
}
245-
246236
pub(crate) fn is_paused(&self) -> bool {
247237
matches!(self.temporality, proto::instrument::Temporality::Paused)
248238
}

0 commit comments

Comments
 (0)