Skip to content

Commit 44360ac

Browse files
add api endpoint to get some control-plan internal info (#4339)
1 parent 9a6685f commit 44360ac

File tree

9 files changed

+415
-2
lines changed

9 files changed

+415
-2
lines changed

quickwit/quickwit-control-plane/src/control_plane.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ use quickwit_config::SourceConfig;
3232
use quickwit_ingest::{IngesterPool, LocalShardsUpdate};
3333
use quickwit_metastore::IndexMetadata;
3434
use quickwit_proto::control_plane::{
35-
ControlPlaneError, ControlPlaneResult, GetOrCreateOpenShardsRequest,
36-
GetOrCreateOpenShardsResponse,
35+
ControlPlaneError, ControlPlaneResult, GetDebugStateRequest, GetDebugStateResponse,
36+
GetOrCreateOpenShardsRequest, GetOrCreateOpenShardsResponse, PhysicalIndexingPlanEntry,
37+
ShardTableEntry,
3738
};
3839
use quickwit_proto::indexing::ShardPositionsUpdate;
3940
use quickwit_proto::metastore::{
@@ -179,6 +180,37 @@ impl ControlPlane {
179180
.schedule_indexing_plan_if_needed(&self.model);
180181
Ok(())
181182
}
183+
184+
fn debug_state(&self) -> GetDebugStateResponse {
185+
let shard_table = self
186+
.model
187+
.all_shards_with_source()
188+
.map(|(source, shards)| ShardTableEntry {
189+
source_id: source.to_string(),
190+
shards: shards
191+
.map(|shard_entry| shard_entry.shard.clone())
192+
.collect(),
193+
})
194+
.collect();
195+
let physical_index_plan = self
196+
.indexing_scheduler
197+
.observable_state()
198+
.last_applied_physical_plan
199+
.map(|plan| {
200+
plan.indexing_tasks_per_indexer()
201+
.iter()
202+
.map(|(node_id, tasks)| PhysicalIndexingPlanEntry {
203+
node_id: node_id.clone(),
204+
tasks: tasks.clone(),
205+
})
206+
.collect()
207+
})
208+
.unwrap_or_default();
209+
GetDebugStateResponse {
210+
shard_table,
211+
physical_index_plan,
212+
}
213+
}
182214
}
183215

184216
#[async_trait]
@@ -528,6 +560,19 @@ impl Handler<LocalShardsUpdate> for ControlPlane {
528560
}
529561
}
530562

563+
#[async_trait]
564+
impl Handler<GetDebugStateRequest> for ControlPlane {
565+
type Reply = ControlPlaneResult<GetDebugStateResponse>;
566+
567+
async fn handle(
568+
&mut self,
569+
_: GetDebugStateRequest,
570+
_ctx: &ActorContext<Self>,
571+
) -> Result<Self::Reply, ActorExitStatus> {
572+
Ok(Ok(self.debug_state()))
573+
}
574+
}
575+
531576
#[derive(Clone)]
532577
pub struct ControlPlaneEventSubscriber(WeakMailbox<ControlPlane>);
533578

quickwit/quickwit-control-plane/src/model/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ impl ControlPlaneModel {
248248
self.shard_table.all_shards()
249249
}
250250

251+
pub(crate) fn all_shards_with_source(
252+
&self,
253+
) -> impl Iterator<Item = (&SourceUid, impl Iterator<Item = &ShardEntry>)> + '_ {
254+
self.shard_table.all_shards_with_source()
255+
}
256+
251257
pub fn list_shards_for_node(
252258
&self,
253259
ingester: &NodeId,

quickwit/quickwit-control-plane/src/model/shard_table.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ impl ShardTable {
284284
.flat_map(|table_entry| table_entry.shard_entries.values())
285285
}
286286

287+
pub(crate) fn all_shards_with_source(
288+
&self,
289+
) -> impl Iterator<Item = (&SourceUid, impl Iterator<Item = &ShardEntry>)> + '_ {
290+
self.table_entries
291+
.iter()
292+
.map(|(source, shard_table)| (source, shard_table.shard_entries.values()))
293+
}
294+
287295
pub(crate) fn all_shards_mut(&mut self) -> impl Iterator<Item = &mut ShardEntry> + '_ {
288296
self.table_entries
289297
.values_mut()

quickwit/quickwit-proto/protos/quickwit/control_plane.proto

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ syntax = "proto3";
2121

2222
package quickwit.control_plane;
2323

24+
import "quickwit/indexing.proto";
2425
import "quickwit/ingest.proto";
2526
import "quickwit/metastore.proto";
2627

@@ -59,6 +60,9 @@ service ControlPlaneService {
5960
// Returns the list of open shards for one or several sources. If the control plane is not able to find any
6061
// for a source, it will pick a pair of leader-follower ingesters and will open a new shard.
6162
rpc GetOrCreateOpenShards(GetOrCreateOpenShardsRequest) returns (GetOrCreateOpenShardsResponse);
63+
64+
// Return some innerstate of the control plane meant to assist debugging.
65+
rpc GetDebugState(GetDebugStateRequest) returns (GetDebugStateResponse);
6266
}
6367

6468
// Shard API
@@ -103,3 +107,21 @@ message GetOrCreateOpenShardsFailure {
103107
string source_id = 3;
104108
GetOrCreateOpenShardsFailureReason reason = 4;
105109
}
110+
111+
message GetDebugStateRequest {
112+
}
113+
114+
message GetDebugStateResponse {
115+
repeated ShardTableEntry shard_table = 1;
116+
repeated PhysicalIndexingPlanEntry physical_index_plan = 2;
117+
}
118+
119+
message ShardTableEntry {
120+
string source_id = 1;
121+
repeated quickwit.ingest.Shard shards = 2;
122+
}
123+
124+
message PhysicalIndexingPlanEntry {
125+
string node_id = 1;
126+
repeated quickwit.indexing.IndexingTask tasks = 2;
127+
}

0 commit comments

Comments
 (0)