1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
use std::cmp::Ordering;
use ordered_float::OrderedFloat;
use strum::EnumIter;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
/// Type of vector matching score
pub type ScoreType = f32;
/// Type of point index inside a segment
pub type PointOffsetType = u32;
#[derive(Copy, Clone, PartialEq, Debug, Default, FromBytes, IntoBytes, KnownLayout, Immutable)]
#[repr(C)]
pub struct ScoredPointOffset {
pub idx: PointOffsetType,
pub score: ScoreType,
}
impl Eq for ScoredPointOffset {}
impl Ord for ScoredPointOffset {
fn cmp(&self, other: &Self) -> Ordering {
OrderedFloat(self.score).cmp(&OrderedFloat(other.score))
}
}
impl PartialOrd for ScoredPointOffset {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
#[derive(Copy, Clone, Debug)]
pub struct TelemetryDetail {
pub level: DetailsLevel,
pub histograms: bool,
pub per_collection: bool,
}
impl TelemetryDetail {
pub fn new(level: DetailsLevel, histograms: bool) -> Self {
Self {
level,
histograms,
per_collection: false,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, EnumIter)]
pub enum DetailsLevel {
/// Minimal information level
/// - app info
/// - minimal telemetry by endpoint
/// - cluster status
Level0,
/// Detailed common info level
/// - app info details
/// - system info
/// - hardware flags
/// - hardware usage per collection
/// - RAM usage
/// - cluster basic details
/// - collections basic info
Level1,
/// Detailed consensus info - peers info
/// Collections:
/// - detailed config
/// - Shards - basic config
Level2,
/// Shards:
/// - detailed config
/// - Optimizers info
Level3,
/// Segment level telemetry
Level4,
}
impl Default for TelemetryDetail {
fn default() -> Self {
TelemetryDetail {
level: DetailsLevel::Level0,
histograms: false,
per_collection: false,
}
}
}
impl From<usize> for DetailsLevel {
fn from(value: usize) -> Self {
match value {
0 => DetailsLevel::Level0,
1 => DetailsLevel::Level1,
2 => DetailsLevel::Level2,
3 => DetailsLevel::Level3,
4 => DetailsLevel::Level4,
_ => DetailsLevel::Level4,
}
}
}
/// Tweaks the filtering of deferred points.
/// Can be used in places where we sometimes must access all points, including deferred ones.
#[derive(Clone, Copy)]
pub enum DeferredBehavior {
/// Deferred points are not affected nor visible.
Exclude,
/// Deferred points are affected and visible.
IncludeAll,
}
impl DeferredBehavior {
/// Apply the behavior to a given `deferred_internal_id`.
pub fn apply(&self, deferred_internal_id: Option<PointOffsetType>) -> Option<PointOffsetType> {
match self {
// Excluding deferred points from the result, if `deferred_internal_id` is set.
DeferredBehavior::Exclude => deferred_internal_id,
// Setting `deferred_internal_id` to `None` results in no points being left out
// at deferred-point filtering.
DeferredBehavior::IncludeAll => None,
}
}
/// Returns `true` if filtering deferred points should be disabled
/// and *all* points should be included in the result.
pub fn include_all_points(&self) -> bool {
matches!(self, DeferredBehavior::IncludeAll)
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_deferred_overwrite() {
assert_eq!(DeferredBehavior::Exclude.apply(Some(32)), Some(32));
assert_eq!(DeferredBehavior::Exclude.apply(None), None);
// `IncludeAll` always returns `None` because then the filtering of deferred points is disabled.
assert_eq!(DeferredBehavior::IncludeAll.apply(Some(32)), None);
assert_eq!(DeferredBehavior::IncludeAll.apply(None), None);
}
}