google_cloud_logging_type/
model.rs

1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16
17#![allow(rustdoc::redundant_explicit_links)]
18#![allow(rustdoc::broken_intra_doc_links)]
19#![no_implicit_prelude]
20extern crate bytes;
21extern crate serde;
22extern crate serde_json;
23extern crate serde_with;
24extern crate std;
25extern crate wkt;
26
27/// A common proto for logging HTTP requests. Only contains semantics
28/// defined by the HTTP specification. Product-specific logging
29/// information MUST be defined in a separate message.
30#[serde_with::serde_as]
31#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
32#[serde(default, rename_all = "camelCase")]
33#[non_exhaustive]
34pub struct HttpRequest {
35    /// The request method. Examples: `"GET"`, `"HEAD"`, `"PUT"`, `"POST"`.
36    #[serde(skip_serializing_if = "std::string::String::is_empty")]
37    pub request_method: std::string::String,
38
39    /// The scheme (http, https), the host name, the path and the query
40    /// portion of the URL that was requested.
41    /// Example: ``http://example.com/some/info?color=red``.
42    #[serde(skip_serializing_if = "std::string::String::is_empty")]
43    pub request_url: std::string::String,
44
45    /// The size of the HTTP request message in bytes, including the request
46    /// headers and the request body.
47    #[serde(skip_serializing_if = "wkt::internal::is_default")]
48    #[serde_as(as = "serde_with::DisplayFromStr")]
49    pub request_size: i64,
50
51    /// The response code indicating the status of response.
52    /// Examples: 200, 404.
53    #[serde(skip_serializing_if = "wkt::internal::is_default")]
54    pub status: i32,
55
56    /// The size of the HTTP response message sent back to the client, in bytes,
57    /// including the response headers and the response body.
58    #[serde(skip_serializing_if = "wkt::internal::is_default")]
59    #[serde_as(as = "serde_with::DisplayFromStr")]
60    pub response_size: i64,
61
62    /// The user agent sent by the client. Example:
63    /// `"Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Q312461; .NET
64    /// CLR 1.0.3705)"`.
65    #[serde(skip_serializing_if = "std::string::String::is_empty")]
66    pub user_agent: std::string::String,
67
68    /// The IP address (IPv4 or IPv6) of the client that issued the HTTP
69    /// request. This field can include port information. Examples:
70    /// `"192.168.1.1"`, `"10.0.0.1:80"`, `"FE80::0202:B3FF:FE1E:8329"`.
71    #[serde(skip_serializing_if = "std::string::String::is_empty")]
72    pub remote_ip: std::string::String,
73
74    /// The IP address (IPv4 or IPv6) of the origin server that the request was
75    /// sent to. This field can include port information. Examples:
76    /// `"192.168.1.1"`, `"10.0.0.1:80"`, `"FE80::0202:B3FF:FE1E:8329"`.
77    #[serde(skip_serializing_if = "std::string::String::is_empty")]
78    pub server_ip: std::string::String,
79
80    /// The referer URL of the request, as defined in
81    /// [HTTP/1.1 Header Field
82    /// Definitions](https://datatracker.ietf.org/doc/html/rfc2616#section-14.36).
83    #[serde(skip_serializing_if = "std::string::String::is_empty")]
84    pub referer: std::string::String,
85
86    /// The request processing latency on the server, from the time the request was
87    /// received until the response was sent.
88    #[serde(skip_serializing_if = "std::option::Option::is_none")]
89    pub latency: std::option::Option<wkt::Duration>,
90
91    /// Whether or not a cache lookup was attempted.
92    #[serde(skip_serializing_if = "wkt::internal::is_default")]
93    pub cache_lookup: bool,
94
95    /// Whether or not an entity was served from cache
96    /// (with or without validation).
97    #[serde(skip_serializing_if = "wkt::internal::is_default")]
98    pub cache_hit: bool,
99
100    /// Whether or not the response was validated with the origin server before
101    /// being served from cache. This field is only meaningful if `cache_hit` is
102    /// True.
103    #[serde(skip_serializing_if = "wkt::internal::is_default")]
104    pub cache_validated_with_origin_server: bool,
105
106    /// The number of HTTP response bytes inserted into cache. Set only when a
107    /// cache fill was attempted.
108    #[serde(skip_serializing_if = "wkt::internal::is_default")]
109    #[serde_as(as = "serde_with::DisplayFromStr")]
110    pub cache_fill_bytes: i64,
111
112    /// Protocol used for the request. Examples: "HTTP/1.1", "HTTP/2", "websocket"
113    #[serde(skip_serializing_if = "std::string::String::is_empty")]
114    pub protocol: std::string::String,
115
116    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
117    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
118}
119
120impl HttpRequest {
121    pub fn new() -> Self {
122        std::default::Default::default()
123    }
124
125    /// Sets the value of [request_method][crate::model::HttpRequest::request_method].
126    pub fn set_request_method<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
127        self.request_method = v.into();
128        self
129    }
130
131    /// Sets the value of [request_url][crate::model::HttpRequest::request_url].
132    pub fn set_request_url<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
133        self.request_url = v.into();
134        self
135    }
136
137    /// Sets the value of [request_size][crate::model::HttpRequest::request_size].
138    pub fn set_request_size<T: std::convert::Into<i64>>(mut self, v: T) -> Self {
139        self.request_size = v.into();
140        self
141    }
142
143    /// Sets the value of [status][crate::model::HttpRequest::status].
144    pub fn set_status<T: std::convert::Into<i32>>(mut self, v: T) -> Self {
145        self.status = v.into();
146        self
147    }
148
149    /// Sets the value of [response_size][crate::model::HttpRequest::response_size].
150    pub fn set_response_size<T: std::convert::Into<i64>>(mut self, v: T) -> Self {
151        self.response_size = v.into();
152        self
153    }
154
155    /// Sets the value of [user_agent][crate::model::HttpRequest::user_agent].
156    pub fn set_user_agent<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
157        self.user_agent = v.into();
158        self
159    }
160
161    /// Sets the value of [remote_ip][crate::model::HttpRequest::remote_ip].
162    pub fn set_remote_ip<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
163        self.remote_ip = v.into();
164        self
165    }
166
167    /// Sets the value of [server_ip][crate::model::HttpRequest::server_ip].
168    pub fn set_server_ip<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
169        self.server_ip = v.into();
170        self
171    }
172
173    /// Sets the value of [referer][crate::model::HttpRequest::referer].
174    pub fn set_referer<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
175        self.referer = v.into();
176        self
177    }
178
179    /// Sets the value of [latency][crate::model::HttpRequest::latency].
180    pub fn set_latency<T: std::convert::Into<std::option::Option<wkt::Duration>>>(
181        mut self,
182        v: T,
183    ) -> Self {
184        self.latency = v.into();
185        self
186    }
187
188    /// Sets the value of [cache_lookup][crate::model::HttpRequest::cache_lookup].
189    pub fn set_cache_lookup<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
190        self.cache_lookup = v.into();
191        self
192    }
193
194    /// Sets the value of [cache_hit][crate::model::HttpRequest::cache_hit].
195    pub fn set_cache_hit<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
196        self.cache_hit = v.into();
197        self
198    }
199
200    /// Sets the value of [cache_validated_with_origin_server][crate::model::HttpRequest::cache_validated_with_origin_server].
201    pub fn set_cache_validated_with_origin_server<T: std::convert::Into<bool>>(
202        mut self,
203        v: T,
204    ) -> Self {
205        self.cache_validated_with_origin_server = v.into();
206        self
207    }
208
209    /// Sets the value of [cache_fill_bytes][crate::model::HttpRequest::cache_fill_bytes].
210    pub fn set_cache_fill_bytes<T: std::convert::Into<i64>>(mut self, v: T) -> Self {
211        self.cache_fill_bytes = v.into();
212        self
213    }
214
215    /// Sets the value of [protocol][crate::model::HttpRequest::protocol].
216    pub fn set_protocol<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
217        self.protocol = v.into();
218        self
219    }
220}
221
222impl wkt::message::Message for HttpRequest {
223    fn typename() -> &'static str {
224        "type.googleapis.com/google.logging.type.HttpRequest"
225    }
226}
227
228/// The severity of the event described in a log entry, expressed as one of the
229/// standard severity levels listed below.  For your reference, the levels are
230/// assigned the listed numeric values. The effect of using numeric values other
231/// than those listed is undefined.
232///
233/// You can filter for log entries by severity.  For example, the following
234/// filter expression will match log entries with severities `INFO`, `NOTICE`,
235/// and `WARNING`:
236///
237/// ```norust
238/// severity > DEBUG AND severity <= WARNING
239/// ```
240///
241/// If you are writing log entries, you should map other severity encodings to
242/// one of these standard levels. For example, you might map all of Java's FINE,
243/// FINER, and FINEST levels to `LogSeverity.DEBUG`. You can preserve the
244/// original severity level in the log entry payload if you wish.
245///
246/// # Working with unknown values
247///
248/// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
249/// additional enum variants at any time. Adding new variants is not considered
250/// a breaking change. Applications should write their code in anticipation of:
251///
252/// - New values appearing in future releases of the client library, **and**
253/// - New values received dynamically, without application changes.
254///
255/// Please consult the [Working with enums] section in the user guide for some
256/// guidelines.
257///
258/// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
259#[derive(Clone, Debug, PartialEq)]
260#[non_exhaustive]
261pub enum LogSeverity {
262    /// (0) The log entry has no assigned severity level.
263    Default,
264    /// (100) Debug or trace information.
265    Debug,
266    /// (200) Routine information, such as ongoing status or performance.
267    Info,
268    /// (300) Normal but significant events, such as start up, shut down, or
269    /// a configuration change.
270    Notice,
271    /// (400) Warning events might cause problems.
272    Warning,
273    /// (500) Error events are likely to cause problems.
274    Error,
275    /// (600) Critical events cause more severe problems or outages.
276    Critical,
277    /// (700) A person must take an action immediately.
278    Alert,
279    /// (800) One or more systems are unusable.
280    Emergency,
281    /// If set, the enum was initialized with an unknown value.
282    ///
283    /// Applications can examine the value using [LogSeverity::value] or
284    /// [LogSeverity::name].
285    UnknownValue(log_severity::UnknownValue),
286}
287
288#[doc(hidden)]
289pub mod log_severity {
290    #[allow(unused_imports)]
291    use super::*;
292    #[derive(Clone, Debug, PartialEq)]
293    pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
294}
295
296impl LogSeverity {
297    /// Gets the enum value.
298    ///
299    /// Returns `None` if the enum contains an unknown value deserialized from
300    /// the string representation of enums.
301    pub fn value(&self) -> std::option::Option<i32> {
302        match self {
303            Self::Default => std::option::Option::Some(0),
304            Self::Debug => std::option::Option::Some(100),
305            Self::Info => std::option::Option::Some(200),
306            Self::Notice => std::option::Option::Some(300),
307            Self::Warning => std::option::Option::Some(400),
308            Self::Error => std::option::Option::Some(500),
309            Self::Critical => std::option::Option::Some(600),
310            Self::Alert => std::option::Option::Some(700),
311            Self::Emergency => std::option::Option::Some(800),
312            Self::UnknownValue(u) => u.0.value(),
313        }
314    }
315
316    /// Gets the enum value as a string.
317    ///
318    /// Returns `None` if the enum contains an unknown value deserialized from
319    /// the integer representation of enums.
320    pub fn name(&self) -> std::option::Option<&str> {
321        match self {
322            Self::Default => std::option::Option::Some("DEFAULT"),
323            Self::Debug => std::option::Option::Some("DEBUG"),
324            Self::Info => std::option::Option::Some("INFO"),
325            Self::Notice => std::option::Option::Some("NOTICE"),
326            Self::Warning => std::option::Option::Some("WARNING"),
327            Self::Error => std::option::Option::Some("ERROR"),
328            Self::Critical => std::option::Option::Some("CRITICAL"),
329            Self::Alert => std::option::Option::Some("ALERT"),
330            Self::Emergency => std::option::Option::Some("EMERGENCY"),
331            Self::UnknownValue(u) => u.0.name(),
332        }
333    }
334}
335
336impl std::default::Default for LogSeverity {
337    fn default() -> Self {
338        use std::convert::From;
339        Self::from(0)
340    }
341}
342
343impl std::fmt::Display for LogSeverity {
344    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
345        wkt::internal::display_enum(f, self.name(), self.value())
346    }
347}
348
349impl std::convert::From<i32> for LogSeverity {
350    fn from(value: i32) -> Self {
351        match value {
352            0 => Self::Default,
353            100 => Self::Debug,
354            200 => Self::Info,
355            300 => Self::Notice,
356            400 => Self::Warning,
357            500 => Self::Error,
358            600 => Self::Critical,
359            700 => Self::Alert,
360            800 => Self::Emergency,
361            _ => Self::UnknownValue(log_severity::UnknownValue(
362                wkt::internal::UnknownEnumValue::Integer(value),
363            )),
364        }
365    }
366}
367
368impl std::convert::From<&str> for LogSeverity {
369    fn from(value: &str) -> Self {
370        use std::string::ToString;
371        match value {
372            "DEFAULT" => Self::Default,
373            "DEBUG" => Self::Debug,
374            "INFO" => Self::Info,
375            "NOTICE" => Self::Notice,
376            "WARNING" => Self::Warning,
377            "ERROR" => Self::Error,
378            "CRITICAL" => Self::Critical,
379            "ALERT" => Self::Alert,
380            "EMERGENCY" => Self::Emergency,
381            _ => Self::UnknownValue(log_severity::UnknownValue(
382                wkt::internal::UnknownEnumValue::String(value.to_string()),
383            )),
384        }
385    }
386}
387
388impl serde::ser::Serialize for LogSeverity {
389    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
390    where
391        S: serde::Serializer,
392    {
393        match self {
394            Self::Default => serializer.serialize_i32(0),
395            Self::Debug => serializer.serialize_i32(100),
396            Self::Info => serializer.serialize_i32(200),
397            Self::Notice => serializer.serialize_i32(300),
398            Self::Warning => serializer.serialize_i32(400),
399            Self::Error => serializer.serialize_i32(500),
400            Self::Critical => serializer.serialize_i32(600),
401            Self::Alert => serializer.serialize_i32(700),
402            Self::Emergency => serializer.serialize_i32(800),
403            Self::UnknownValue(u) => u.0.serialize(serializer),
404        }
405    }
406}
407
408impl<'de> serde::de::Deserialize<'de> for LogSeverity {
409    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
410    where
411        D: serde::Deserializer<'de>,
412    {
413        deserializer.deserialize_any(wkt::internal::EnumVisitor::<LogSeverity>::new(
414            ".google.logging.type.LogSeverity",
415        ))
416    }
417}