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