k8s_openapi/v1_30/api/flowcontrol/v1beta3/
limited_priority_level_configuration.rs

1// Generated from definition io.k8s.api.flowcontrol.v1beta3.LimitedPriorityLevelConfiguration
2
3/// LimitedPriorityLevelConfiguration specifies how to handle requests that are subject to limits. It addresses two issues:
4///   - How are requests for this priority level limited?
5///   - What should be done with requests that exceed the limit?
6#[derive(Clone, Debug, Default, PartialEq)]
7pub struct LimitedPriorityLevelConfiguration {
8    /// `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.
9    ///
10    /// BorrowingCL(i) = round( NominalCL(i) * borrowingLimitPercent(i)/100.0 )
11    ///
12    /// The 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.
13    pub borrowing_limit_percent: Option<i32>,
14
15    /// `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.
16    ///
17    /// LendableCL(i) = round( NominalCL(i) * lendablePercent(i)/100.0 )
18    pub lendable_percent: Option<i32>,
19
20    /// `limitResponse` indicates what to do with requests that can not be executed right now
21    pub limit_response: Option<crate::api::flowcontrol::v1beta3::LimitResponse>,
22
23    /// `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:
24    ///
25    /// NominalCL(i)  = ceil( ServerCL * NCS(i) / sum_ncs ) sum_ncs = sum\[priority level k\] NCS(k)
26    ///
27    /// Bigger numbers mean a larger nominal concurrency limit, at the expense of every other priority level. This field has a default value of 30.
28    pub nominal_concurrency_shares: Option<i32>,
29}
30
31impl crate::DeepMerge for LimitedPriorityLevelConfiguration {
32    fn merge_from(&mut self, other: Self) {
33        crate::DeepMerge::merge_from(&mut self.borrowing_limit_percent, other.borrowing_limit_percent);
34        crate::DeepMerge::merge_from(&mut self.lendable_percent, other.lendable_percent);
35        crate::DeepMerge::merge_from(&mut self.limit_response, other.limit_response);
36        crate::DeepMerge::merge_from(&mut self.nominal_concurrency_shares, other.nominal_concurrency_shares);
37    }
38}
39
40impl<'de> crate::serde::Deserialize<'de> for LimitedPriorityLevelConfiguration {
41    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
42        #[allow(non_camel_case_types)]
43        enum Field {
44            Key_borrowing_limit_percent,
45            Key_lendable_percent,
46            Key_limit_response,
47            Key_nominal_concurrency_shares,
48            Other,
49        }
50
51        impl<'de> crate::serde::Deserialize<'de> for Field {
52            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
53                struct Visitor;
54
55                impl crate::serde::de::Visitor<'_> for Visitor {
56                    type Value = Field;
57
58                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
59                        f.write_str("field identifier")
60                    }
61
62                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
63                        Ok(match v {
64                            "borrowingLimitPercent" => Field::Key_borrowing_limit_percent,
65                            "lendablePercent" => Field::Key_lendable_percent,
66                            "limitResponse" => Field::Key_limit_response,
67                            "nominalConcurrencyShares" => Field::Key_nominal_concurrency_shares,
68                            _ => Field::Other,
69                        })
70                    }
71                }
72
73                deserializer.deserialize_identifier(Visitor)
74            }
75        }
76
77        struct Visitor;
78
79        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
80            type Value = LimitedPriorityLevelConfiguration;
81
82            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
83                f.write_str("LimitedPriorityLevelConfiguration")
84            }
85
86            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
87                let mut value_borrowing_limit_percent: Option<i32> = None;
88                let mut value_lendable_percent: Option<i32> = None;
89                let mut value_limit_response: Option<crate::api::flowcontrol::v1beta3::LimitResponse> = None;
90                let mut value_nominal_concurrency_shares: Option<i32> = None;
91
92                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
93                    match key {
94                        Field::Key_borrowing_limit_percent => value_borrowing_limit_percent = crate::serde::de::MapAccess::next_value(&mut map)?,
95                        Field::Key_lendable_percent => value_lendable_percent = crate::serde::de::MapAccess::next_value(&mut map)?,
96                        Field::Key_limit_response => value_limit_response = crate::serde::de::MapAccess::next_value(&mut map)?,
97                        Field::Key_nominal_concurrency_shares => value_nominal_concurrency_shares = crate::serde::de::MapAccess::next_value(&mut map)?,
98                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
99                    }
100                }
101
102                Ok(LimitedPriorityLevelConfiguration {
103                    borrowing_limit_percent: value_borrowing_limit_percent,
104                    lendable_percent: value_lendable_percent,
105                    limit_response: value_limit_response,
106                    nominal_concurrency_shares: value_nominal_concurrency_shares,
107                })
108            }
109        }
110
111        deserializer.deserialize_struct(
112            "LimitedPriorityLevelConfiguration",
113            &[
114                "borrowingLimitPercent",
115                "lendablePercent",
116                "limitResponse",
117                "nominalConcurrencyShares",
118            ],
119            Visitor,
120        )
121    }
122}
123
124impl crate::serde::Serialize for LimitedPriorityLevelConfiguration {
125    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
126        let mut state = serializer.serialize_struct(
127            "LimitedPriorityLevelConfiguration",
128            self.borrowing_limit_percent.as_ref().map_or(0, |_| 1) +
129            self.lendable_percent.as_ref().map_or(0, |_| 1) +
130            self.limit_response.as_ref().map_or(0, |_| 1) +
131            self.nominal_concurrency_shares.as_ref().map_or(0, |_| 1),
132        )?;
133        if let Some(value) = &self.borrowing_limit_percent {
134            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "borrowingLimitPercent", value)?;
135        }
136        if let Some(value) = &self.lendable_percent {
137            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "lendablePercent", value)?;
138        }
139        if let Some(value) = &self.limit_response {
140            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "limitResponse", value)?;
141        }
142        if let Some(value) = &self.nominal_concurrency_shares {
143            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nominalConcurrencyShares", value)?;
144        }
145        crate::serde::ser::SerializeStruct::end(state)
146    }
147}
148
149#[cfg(feature = "schemars")]
150impl crate::schemars::JsonSchema for LimitedPriorityLevelConfiguration {
151    fn schema_name() -> std::borrow::Cow<'static, str> {
152        "io.k8s.api.flowcontrol.v1beta3.LimitedPriorityLevelConfiguration".into()
153    }
154
155    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
156        crate::schemars::json_schema!({
157            "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?",
158            "type": "object",
159            "properties": {
160                "borrowingLimitPercent": {
161                    "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.",
162                    "type": "integer",
163                    "format": "int32",
164                },
165                "lendablePercent": {
166                    "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 )",
167                    "type": "integer",
168                    "format": "int32",
169                },
170                "limitResponse": ({
171                    let mut schema_obj = __gen.subschema_for::<crate::api::flowcontrol::v1beta3::LimitResponse>();
172                    schema_obj.ensure_object().insert("description".into(), "`limitResponse` indicates what to do with requests that can not be executed right now".into());
173                    schema_obj
174                }),
175                "nominalConcurrencyShares": {
176                    "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. This field has a default value of 30.",
177                    "type": "integer",
178                    "format": "int32",
179                },
180            },
181        })
182    }
183}