-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.rs
76 lines (65 loc) · 2 KB
/
metadata.rs
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
use crate::identity;
use indexmap::IndexMap;
/// Metadata describing an endpoint.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Metadata {
/// An endpoint's relative weight.
///
/// A weight of 0 means that the endpoint should never be preferred over a
/// non 0-weighted endpoint.
///
/// The default weight, corresponding to 1.0, is 10,000. This enables us to
/// specify weights as small as 0.0001 and as large as 400,000+.
///
/// A float is not used so that this type can implement `Eq`.
weight: u32,
/// Arbitrary endpoint labels. Primarily used for telemetry.
labels: IndexMap<String, String>,
/// A hint from the controller about what protocol (HTTP1, HTTP2, etc) the
/// destination understands.
protocol_hint: ProtocolHint,
/// How to verify TLS for the endpoint.
identity: Option<identity::Name>,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ProtocolHint {
/// We don't what the destination understands, so forward messages in the
/// protocol we received them in.
Unknown,
/// The destination can receive HTTP2 messages.
Http2,
}
// === impl Metadata ===
impl Metadata {
pub fn empty() -> Self {
Self {
labels: IndexMap::default(),
protocol_hint: ProtocolHint::Unknown,
identity: None,
weight: 10_000,
}
}
pub fn new(
labels: IndexMap<String, String>,
protocol_hint: ProtocolHint,
identity: Option<identity::Name>,
weight: u32,
) -> Self {
Self {
labels,
protocol_hint,
identity,
weight,
}
}
/// Returns the endpoint's labels from the destination service, if it has them.
pub fn labels(&self) -> &IndexMap<String, String> {
&self.labels
}
pub fn protocol_hint(&self) -> ProtocolHint {
self.protocol_hint
}
pub fn identity(&self) -> Option<&identity::Name> {
self.identity.as_ref()
}
}