k8s_openapi/v1_30/api/flowcontrol/v1/
limited_priority_level_configuration.rs1#[derive(Clone, Debug, Default, PartialEq)]
7pub struct LimitedPriorityLevelConfiguration {
8 pub borrowing_limit_percent: Option<i32>,
14
15 pub lendable_percent: Option<i32>,
19
20 pub limit_response: Option<crate::api::flowcontrol::v1::LimitResponse>,
22
23 pub nominal_concurrency_shares: Option<i32>,
33}
34
35impl crate::DeepMerge for LimitedPriorityLevelConfiguration {
36 fn merge_from(&mut self, other: Self) {
37 crate::DeepMerge::merge_from(&mut self.borrowing_limit_percent, other.borrowing_limit_percent);
38 crate::DeepMerge::merge_from(&mut self.lendable_percent, other.lendable_percent);
39 crate::DeepMerge::merge_from(&mut self.limit_response, other.limit_response);
40 crate::DeepMerge::merge_from(&mut self.nominal_concurrency_shares, other.nominal_concurrency_shares);
41 }
42}
43
44impl<'de> crate::serde::Deserialize<'de> for LimitedPriorityLevelConfiguration {
45 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
46 #[allow(non_camel_case_types)]
47 enum Field {
48 Key_borrowing_limit_percent,
49 Key_lendable_percent,
50 Key_limit_response,
51 Key_nominal_concurrency_shares,
52 Other,
53 }
54
55 impl<'de> crate::serde::Deserialize<'de> for Field {
56 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
57 struct Visitor;
58
59 impl crate::serde::de::Visitor<'_> for Visitor {
60 type Value = Field;
61
62 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
63 f.write_str("field identifier")
64 }
65
66 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
67 Ok(match v {
68 "borrowingLimitPercent" => Field::Key_borrowing_limit_percent,
69 "lendablePercent" => Field::Key_lendable_percent,
70 "limitResponse" => Field::Key_limit_response,
71 "nominalConcurrencyShares" => Field::Key_nominal_concurrency_shares,
72 _ => Field::Other,
73 })
74 }
75 }
76
77 deserializer.deserialize_identifier(Visitor)
78 }
79 }
80
81 struct Visitor;
82
83 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
84 type Value = LimitedPriorityLevelConfiguration;
85
86 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
87 f.write_str("LimitedPriorityLevelConfiguration")
88 }
89
90 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
91 let mut value_borrowing_limit_percent: Option<i32> = None;
92 let mut value_lendable_percent: Option<i32> = None;
93 let mut value_limit_response: Option<crate::api::flowcontrol::v1::LimitResponse> = None;
94 let mut value_nominal_concurrency_shares: Option<i32> = None;
95
96 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
97 match key {
98 Field::Key_borrowing_limit_percent => value_borrowing_limit_percent = crate::serde::de::MapAccess::next_value(&mut map)?,
99 Field::Key_lendable_percent => value_lendable_percent = crate::serde::de::MapAccess::next_value(&mut map)?,
100 Field::Key_limit_response => value_limit_response = crate::serde::de::MapAccess::next_value(&mut map)?,
101 Field::Key_nominal_concurrency_shares => value_nominal_concurrency_shares = crate::serde::de::MapAccess::next_value(&mut map)?,
102 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
103 }
104 }
105
106 Ok(LimitedPriorityLevelConfiguration {
107 borrowing_limit_percent: value_borrowing_limit_percent,
108 lendable_percent: value_lendable_percent,
109 limit_response: value_limit_response,
110 nominal_concurrency_shares: value_nominal_concurrency_shares,
111 })
112 }
113 }
114
115 deserializer.deserialize_struct(
116 "LimitedPriorityLevelConfiguration",
117 &[
118 "borrowingLimitPercent",
119 "lendablePercent",
120 "limitResponse",
121 "nominalConcurrencyShares",
122 ],
123 Visitor,
124 )
125 }
126}
127
128impl crate::serde::Serialize for LimitedPriorityLevelConfiguration {
129 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
130 let mut state = serializer.serialize_struct(
131 "LimitedPriorityLevelConfiguration",
132 self.borrowing_limit_percent.as_ref().map_or(0, |_| 1) +
133 self.lendable_percent.as_ref().map_or(0, |_| 1) +
134 self.limit_response.as_ref().map_or(0, |_| 1) +
135 self.nominal_concurrency_shares.as_ref().map_or(0, |_| 1),
136 )?;
137 if let Some(value) = &self.borrowing_limit_percent {
138 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "borrowingLimitPercent", value)?;
139 }
140 if let Some(value) = &self.lendable_percent {
141 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "lendablePercent", value)?;
142 }
143 if let Some(value) = &self.limit_response {
144 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "limitResponse", value)?;
145 }
146 if let Some(value) = &self.nominal_concurrency_shares {
147 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nominalConcurrencyShares", value)?;
148 }
149 crate::serde::ser::SerializeStruct::end(state)
150 }
151}
152
153#[cfg(feature = "schemars")]
154impl crate::schemars::JsonSchema for LimitedPriorityLevelConfiguration {
155 fn schema_name() -> std::borrow::Cow<'static, str> {
156 "io.k8s.api.flowcontrol.v1.LimitedPriorityLevelConfiguration".into()
157 }
158
159 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
160 crate::schemars::json_schema!({
161 "description": "LimitedPriorityLevelConfiguration specifies how to handle requests that are subject to limits. It addresses two issues:\n - How are requests for this priority level limited?\n - What should be done with requests that exceed the limit?",
162 "type": "object",
163 "properties": {
164 "borrowingLimitPercent": {
165 "description": "`borrowingLimitPercent`, if present, configures a limit on how many seats this priority level can borrow from other priority levels. The limit is known as this level's BorrowingConcurrencyLimit (BorrowingCL) and is a limit on the total number of seats that this level may borrow at any one time. This field holds the ratio of that limit to the level's nominal concurrency limit. When this field is non-nil, it must hold a non-negative integer and the limit is calculated as follows.\n\nBorrowingCL(i) = round( NominalCL(i) * borrowingLimitPercent(i)/100.0 )\n\nThe value of this field can be more than 100, implying that this priority level can borrow a number of seats that is greater than its own nominal concurrency limit (NominalCL). When this field is left `nil`, the limit is effectively infinite.",
166 "type": "integer",
167 "format": "int32",
168 },
169 "lendablePercent": {
170 "description": "`lendablePercent` prescribes the fraction of the level's NominalCL that can be borrowed by other priority levels. The value of this field must be between 0 and 100, inclusive, and it defaults to 0. The number of seats that other levels can borrow from this level, known as this level's LendableConcurrencyLimit (LendableCL), is defined as follows.\n\nLendableCL(i) = round( NominalCL(i) * lendablePercent(i)/100.0 )",
171 "type": "integer",
172 "format": "int32",
173 },
174 "limitResponse": ({
175 let mut schema_obj = __gen.subschema_for::<crate::api::flowcontrol::v1::LimitResponse>();
176 schema_obj.ensure_object().insert("description".into(), "`limitResponse` indicates what to do with requests that can not be executed right now".into());
177 schema_obj
178 }),
179 "nominalConcurrencyShares": {
180 "description": "`nominalConcurrencyShares` (NCS) contributes to the computation of the NominalConcurrencyLimit (NominalCL) of this level. This is the number of execution seats available at this priority level. This is used both for requests dispatched from this priority level as well as requests dispatched from other priority levels borrowing seats from this level. The server's concurrency limit (ServerCL) is divided among the Limited priority levels in proportion to their NCS values:\n\nNominalCL(i) = ceil( ServerCL * NCS(i) / sum_ncs ) sum_ncs = sum[priority level k] NCS(k)\n\nBigger numbers mean a larger nominal concurrency limit, at the expense of every other priority level.\n\nIf not specified, this field defaults to a value of 30.\n\nSetting this field to zero supports the construction of a \"jail\" for this priority level that is used to hold some request(s)",
181 "type": "integer",
182 "format": "int32",
183 },
184 },
185 })
186 }
187}