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_as(as = "serde_with::DisplayFromStr")]
48    pub request_size: i64,
49
50    /// The response code indicating the status of response.
51    /// Examples: 200, 404.
52    pub status: i32,
53
54    /// The size of the HTTP response message sent back to the client, in bytes,
55    /// including the response headers and the response body.
56    #[serde_as(as = "serde_with::DisplayFromStr")]
57    pub response_size: i64,
58
59    /// The user agent sent by the client. Example:
60    /// `"Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Q312461; .NET
61    /// CLR 1.0.3705)"`.
62    #[serde(skip_serializing_if = "std::string::String::is_empty")]
63    pub user_agent: std::string::String,
64
65    /// The IP address (IPv4 or IPv6) of the client that issued the HTTP
66    /// request. This field can include port information. Examples:
67    /// `"192.168.1.1"`, `"10.0.0.1:80"`, `"FE80::0202:B3FF:FE1E:8329"`.
68    #[serde(skip_serializing_if = "std::string::String::is_empty")]
69    pub remote_ip: std::string::String,
70
71    /// The IP address (IPv4 or IPv6) of the origin server that the request was
72    /// sent to. This field can include port information. Examples:
73    /// `"192.168.1.1"`, `"10.0.0.1:80"`, `"FE80::0202:B3FF:FE1E:8329"`.
74    #[serde(skip_serializing_if = "std::string::String::is_empty")]
75    pub server_ip: std::string::String,
76
77    /// The referer URL of the request, as defined in
78    /// [HTTP/1.1 Header Field
79    /// Definitions](https://datatracker.ietf.org/doc/html/rfc2616#section-14.36).
80    #[serde(skip_serializing_if = "std::string::String::is_empty")]
81    pub referer: std::string::String,
82
83    /// The request processing latency on the server, from the time the request was
84    /// received until the response was sent.
85    #[serde(skip_serializing_if = "std::option::Option::is_none")]
86    pub latency: std::option::Option<wkt::Duration>,
87
88    /// Whether or not a cache lookup was attempted.
89    pub cache_lookup: bool,
90
91    /// Whether or not an entity was served from cache
92    /// (with or without validation).
93    pub cache_hit: bool,
94
95    /// Whether or not the response was validated with the origin server before
96    /// being served from cache. This field is only meaningful if `cache_hit` is
97    /// True.
98    pub cache_validated_with_origin_server: bool,
99
100    /// The number of HTTP response bytes inserted into cache. Set only when a
101    /// cache fill was attempted.
102    #[serde_as(as = "serde_with::DisplayFromStr")]
103    pub cache_fill_bytes: i64,
104
105    /// Protocol used for the request. Examples: "HTTP/1.1", "HTTP/2", "websocket"
106    #[serde(skip_serializing_if = "std::string::String::is_empty")]
107    pub protocol: std::string::String,
108
109    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
110    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
111}
112
113impl HttpRequest {
114    pub fn new() -> Self {
115        std::default::Default::default()
116    }
117
118    /// Sets the value of [request_method][crate::model::HttpRequest::request_method].
119    pub fn set_request_method<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
120        self.request_method = v.into();
121        self
122    }
123
124    /// Sets the value of [request_url][crate::model::HttpRequest::request_url].
125    pub fn set_request_url<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
126        self.request_url = v.into();
127        self
128    }
129
130    /// Sets the value of [request_size][crate::model::HttpRequest::request_size].
131    pub fn set_request_size<T: std::convert::Into<i64>>(mut self, v: T) -> Self {
132        self.request_size = v.into();
133        self
134    }
135
136    /// Sets the value of [status][crate::model::HttpRequest::status].
137    pub fn set_status<T: std::convert::Into<i32>>(mut self, v: T) -> Self {
138        self.status = v.into();
139        self
140    }
141
142    /// Sets the value of [response_size][crate::model::HttpRequest::response_size].
143    pub fn set_response_size<T: std::convert::Into<i64>>(mut self, v: T) -> Self {
144        self.response_size = v.into();
145        self
146    }
147
148    /// Sets the value of [user_agent][crate::model::HttpRequest::user_agent].
149    pub fn set_user_agent<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
150        self.user_agent = v.into();
151        self
152    }
153
154    /// Sets the value of [remote_ip][crate::model::HttpRequest::remote_ip].
155    pub fn set_remote_ip<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
156        self.remote_ip = v.into();
157        self
158    }
159
160    /// Sets the value of [server_ip][crate::model::HttpRequest::server_ip].
161    pub fn set_server_ip<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
162        self.server_ip = v.into();
163        self
164    }
165
166    /// Sets the value of [referer][crate::model::HttpRequest::referer].
167    pub fn set_referer<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
168        self.referer = v.into();
169        self
170    }
171
172    /// Sets the value of [latency][crate::model::HttpRequest::latency].
173    pub fn set_latency<T: std::convert::Into<std::option::Option<wkt::Duration>>>(
174        mut self,
175        v: T,
176    ) -> Self {
177        self.latency = v.into();
178        self
179    }
180
181    /// Sets the value of [cache_lookup][crate::model::HttpRequest::cache_lookup].
182    pub fn set_cache_lookup<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
183        self.cache_lookup = v.into();
184        self
185    }
186
187    /// Sets the value of [cache_hit][crate::model::HttpRequest::cache_hit].
188    pub fn set_cache_hit<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
189        self.cache_hit = v.into();
190        self
191    }
192
193    /// Sets the value of [cache_validated_with_origin_server][crate::model::HttpRequest::cache_validated_with_origin_server].
194    pub fn set_cache_validated_with_origin_server<T: std::convert::Into<bool>>(
195        mut self,
196        v: T,
197    ) -> Self {
198        self.cache_validated_with_origin_server = v.into();
199        self
200    }
201
202    /// Sets the value of [cache_fill_bytes][crate::model::HttpRequest::cache_fill_bytes].
203    pub fn set_cache_fill_bytes<T: std::convert::Into<i64>>(mut self, v: T) -> Self {
204        self.cache_fill_bytes = v.into();
205        self
206    }
207
208    /// Sets the value of [protocol][crate::model::HttpRequest::protocol].
209    pub fn set_protocol<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
210        self.protocol = v.into();
211        self
212    }
213}
214
215impl wkt::message::Message for HttpRequest {
216    fn typename() -> &'static str {
217        "type.googleapis.com/google.logging.type.HttpRequest"
218    }
219}
220
221/// The severity of the event described in a log entry, expressed as one of the
222/// standard severity levels listed below.  For your reference, the levels are
223/// assigned the listed numeric values. The effect of using numeric values other
224/// than those listed is undefined.
225///
226/// You can filter for log entries by severity.  For example, the following
227/// filter expression will match log entries with severities `INFO`, `NOTICE`,
228/// and `WARNING`:
229///
230/// ```norust
231/// severity > DEBUG AND severity <= WARNING
232/// ```
233///
234/// If you are writing log entries, you should map other severity encodings to
235/// one of these standard levels. For example, you might map all of Java's FINE,
236/// FINER, and FINEST levels to `LogSeverity.DEBUG`. You can preserve the
237/// original severity level in the log entry payload if you wish.
238#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
239pub struct LogSeverity(i32);
240
241impl LogSeverity {
242    /// (0) The log entry has no assigned severity level.
243    pub const DEFAULT: LogSeverity = LogSeverity::new(0);
244
245    /// (100) Debug or trace information.
246    pub const DEBUG: LogSeverity = LogSeverity::new(100);
247
248    /// (200) Routine information, such as ongoing status or performance.
249    pub const INFO: LogSeverity = LogSeverity::new(200);
250
251    /// (300) Normal but significant events, such as start up, shut down, or
252    /// a configuration change.
253    pub const NOTICE: LogSeverity = LogSeverity::new(300);
254
255    /// (400) Warning events might cause problems.
256    pub const WARNING: LogSeverity = LogSeverity::new(400);
257
258    /// (500) Error events are likely to cause problems.
259    pub const ERROR: LogSeverity = LogSeverity::new(500);
260
261    /// (600) Critical events cause more severe problems or outages.
262    pub const CRITICAL: LogSeverity = LogSeverity::new(600);
263
264    /// (700) A person must take an action immediately.
265    pub const ALERT: LogSeverity = LogSeverity::new(700);
266
267    /// (800) One or more systems are unusable.
268    pub const EMERGENCY: LogSeverity = LogSeverity::new(800);
269
270    /// Creates a new LogSeverity instance.
271    pub(crate) const fn new(value: i32) -> Self {
272        Self(value)
273    }
274
275    /// Gets the enum value.
276    pub fn value(&self) -> i32 {
277        self.0
278    }
279
280    /// Gets the enum value as a string.
281    pub fn as_str_name(&self) -> std::borrow::Cow<'static, str> {
282        match self.0 {
283            0 => std::borrow::Cow::Borrowed("DEFAULT"),
284            100 => std::borrow::Cow::Borrowed("DEBUG"),
285            200 => std::borrow::Cow::Borrowed("INFO"),
286            300 => std::borrow::Cow::Borrowed("NOTICE"),
287            400 => std::borrow::Cow::Borrowed("WARNING"),
288            500 => std::borrow::Cow::Borrowed("ERROR"),
289            600 => std::borrow::Cow::Borrowed("CRITICAL"),
290            700 => std::borrow::Cow::Borrowed("ALERT"),
291            800 => std::borrow::Cow::Borrowed("EMERGENCY"),
292            _ => std::borrow::Cow::Owned(std::format!("UNKNOWN-VALUE:{}", self.0)),
293        }
294    }
295
296    /// Creates an enum value from the value name.
297    pub fn from_str_name(name: &str) -> std::option::Option<Self> {
298        match name {
299            "DEFAULT" => std::option::Option::Some(Self::DEFAULT),
300            "DEBUG" => std::option::Option::Some(Self::DEBUG),
301            "INFO" => std::option::Option::Some(Self::INFO),
302            "NOTICE" => std::option::Option::Some(Self::NOTICE),
303            "WARNING" => std::option::Option::Some(Self::WARNING),
304            "ERROR" => std::option::Option::Some(Self::ERROR),
305            "CRITICAL" => std::option::Option::Some(Self::CRITICAL),
306            "ALERT" => std::option::Option::Some(Self::ALERT),
307            "EMERGENCY" => std::option::Option::Some(Self::EMERGENCY),
308            _ => std::option::Option::None,
309        }
310    }
311}
312
313impl std::convert::From<i32> for LogSeverity {
314    fn from(value: i32) -> Self {
315        Self::new(value)
316    }
317}
318
319impl std::default::Default for LogSeverity {
320    fn default() -> Self {
321        Self::new(0)
322    }
323}