Skip to content

Commit

Permalink
add metric for search split affinity (#4998)
Browse files Browse the repository at this point in the history
* add metric for search split affinity
  • Loading branch information
trinity-1686a committed Jun 3, 2024
1 parent 8b011cb commit fc7638b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
11 changes: 10 additions & 1 deletion quickwit/quickwit-search/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@

use once_cell::sync::Lazy;
use quickwit_common::metrics::{
exponential_buckets, new_counter, new_histogram, Histogram, IntCounter,
exponential_buckets, new_counter, new_counter_vec, new_histogram, Histogram, IntCounter,
IntCounterVec,
};

pub struct SearchMetrics {
pub leaf_searches_splits_total: IntCounter,
pub leaf_search_split_duration_secs: Histogram,
pub job_assigned_total: IntCounterVec<1>,
}

impl Default for SearchMetrics {
Expand All @@ -45,6 +47,13 @@ impl Default for SearchMetrics {
"search",
exponential_buckets(0.005, 2.0, 10).unwrap(),
),
job_assigned_total: new_counter_vec(
"job_assigned_total",
"Number of job assigned to searchers, per affinity rank.",
"search",
&[],
["affinity"],
),
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion quickwit/quickwit-search/src/search_job_placer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use quickwit_common::pubsub::EventSubscriber;
use quickwit_common::rendezvous_hasher::{node_affinity, sort_by_rendez_vous_hash};
use quickwit_proto::search::{ReportSplit, ReportSplitsRequest};

use crate::{SearchJob, SearchServiceClient, SearcherPool};
use crate::{SearchJob, SearchServiceClient, SearcherPool, SEARCH_METRICS};

/// Job.
/// The unit in which distributed search is performed.
Expand Down Expand Up @@ -185,6 +185,16 @@ impl SearchJobPlacer {
} else {
0
};
let metric_node_idx = match chosen_node_idx {
0 => "0",
1 => "1",
_ => "> 1",
};
SEARCH_METRICS
.job_assigned_total
.with_label_values([metric_node_idx])
.inc();

let chosen_node = &mut candidate_nodes[chosen_node_idx];
chosen_node.load += job.cost();

Expand Down

0 comments on commit fc7638b

Please sign in to comment.