brooks_lib/cdni/logging/record.rs
1// brooks, Copyright 2026, Will Hawkins
2//
3// This file is part of brooks.
4
5// This file is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18// This file is auto-generated. Use ./tools/logging_record_gen.py to update.
19
20use chrono::Utc;
21use serde::{Deserialize, Serialize};
22use std::net;
23
24#[derive(Debug, Clone, Deserialize, Serialize, Default)]
25pub struct LogRecordRaw {
26 // The timestamp of the first byte read by the OCN application to a best effort of accuracy.
27 #[serde(rename = "timestamp-ns")]
28 pub timestamp_ns: u64,
29 // The timestamp of the first byte read by the OCN application to a best effort of accuracy. It is RECOMMENDED that timestamps use Coordinated Universal Time (UTC).
30 #[serde(skip_serializing_if = "Option::is_none")]
31 #[serde(rename = "timestamp-iso8601")]
32 pub timestamp_iso8601: Option<String>,
33 // The elapsed time between reading the first byte of the request and sending the last byte of the response to a best effort of accuracy.
34 #[serde(skip_serializing_if = "Option::is_none")]
35 #[serde(rename = "s-time-total-ms")]
36 pub s_time_total_ms: Option<u64>,
37 // An opaque identifier for an aggregate set of clients, derived from the client IPv4 or IPv6 address in the request received by the surrogate and/or other network-level identifying information. See [RFC7937] section 3.4.1.
38 #[serde(skip_serializing_if = "Option::is_none")]
39 #[serde(rename = "c-groupid")]
40 pub c_groupid: Option<String>,
41 // The HTTP request method.
42 #[serde(skip_serializing_if = "Option::is_none")]
43 #[serde(rename = "cs-method")]
44 pub cs_method: Option<String>,
45 // The protocol version (e.g., HTTP/1.1).
46 #[serde(skip_serializing_if = "Option::is_none")]
47 #[serde(rename = "cs-version")]
48 pub cs_version: Option<String>,
49 // Request URI prior to any transformation from MI.ProcessingStages. It is RECOMMENDED to limit the maximum length of this field with an applied MI.LoggingTransformTruncate, allowing at least 2048 bytes.
50 #[serde(rename = "cs-uri")]
51 pub cs_uri: String,
52 // Full request URI, including query parameters. If this field is identical to cs-uri, the field SHOULD be truncated to an empty string.
53 #[serde(skip_serializing_if = "Option::is_none")]
54 #[serde(rename = "cs-uri-transformed")]
55 pub cs_uri_transformed: Option<String>,
56 // The response status code.
57 #[serde(rename = "sc-status")]
58 pub sc_status: String,
59 // The response size total bytes, including headers.
60 #[serde(rename = "sc-total-bytes")]
61 pub sc_total_bytes: u64,
62 // The ccid assigned via MI.Grouping or MI.GroupingExtended configuration. For backward compatibility, s-ccid is aliased to ccid, and either identifier may be used to refer to this field.
63 #[serde(rename = "s-ccid")]
64 pub s_ccid: String,
65 // The Session ID assigned by the dCDN. This can be derived from Common Media Client Data (CMCD) or another mechanism, but it is defined by the dCDN, and uCDN allocated session identifiers are outside the scope of this field.
66 #[serde(skip_serializing_if = "Option::is_none")]
67 #[serde(rename = "s-sid")]
68 pub s_sid: Option<String>,
69 // Indicates a cache hit or cache miss. For this field, a cache hit is defined as a request that does not result in content retrieval from the upstream source.
70 #[serde(skip_serializing_if = "Option::is_none")]
71 #[serde(rename = "s-cached")]
72 pub s_cached: Option<bool>,
73 // The client IP address.
74 #[serde(skip_serializing_if = "Option::is_none")]
75 #[serde(rename = "c-ip")]
76 pub c_ip: Option<String>,
77 // A short name for the dCDN intended to be used as an identifier, e.g. in log records. Example: "CDN Example Company" might have s-shortname of "cdn-ec".
78 #[serde(skip_serializing_if = "Option::is_none")]
79 #[serde(rename = "s-shortname")]
80 pub s_shortname: Option<String>,
81 // The server instance ID assigned by the dCDN. This value SHOULD be unique to a particular instance.
82 #[serde(skip_serializing_if = "Option::is_none")]
83 #[serde(rename = "s-id")]
84 pub s_id: Option<String>,
85 // The elapsed time from the first request byte read until the first response byte sent.
86 #[serde(skip_serializing_if = "Option::is_none")]
87 #[serde(rename = "s-time-first-ms")]
88 pub s_time_first_ms: Option<u64>,
89 // The session duration as determined by the dCDN.
90 #[serde(skip_serializing_if = "Option::is_none")]
91 #[serde(rename = "s-sdur-ms")]
92 pub s_sdur_ms: Option<u64>,
93 // The time spent accessing the upstream source. The value of this field is a "best effort". If there are intermediate cache layers, it is understood that this value may not accurately reflect the complete upstream picture.
94 #[serde(skip_serializing_if = "Option::is_none")]
95 #[serde(rename = "s-time-upstream-ms")]
96 pub s_time_upstream_ms: Option<u64>,
97 // Content header length from the upstream source. The value of this field is a "best effort". If there are intermediate cache layers, it is understood that this value may not accurately reflect the complete upstream picture.
98 #[serde(rename = "s-upstream-header-size-bytes")]
99 pub s_upstream_header_size_bytes: u64,
100 // Total bytes transferred from the upstream source. The value of this field is a "best effort". If there are intermediate cache layers, it is understood that this value may not accurately reflect the complete upstream picture.
101 #[serde(rename = "s-upstream-total-bytes")]
102 pub s_upstream_total_bytes: u64,
103 // The response status code returned by the upstream source in the event of a cache miss.
104 #[serde(skip_serializing_if = "Option::is_none")]
105 #[serde(rename = "s-upstream-status")]
106 pub s_upstream_status: Option<String>,
107 // The IP address of the upstream source.
108 #[serde(skip_serializing_if = "Option::is_none")]
109 #[serde(rename = "s-upstream-ip")]
110 pub s_upstream_ip: Option<String>,
111}
112#[derive(Debug, Clone, Default)]
113pub struct LogRecord {
114 // The timestamp of the first byte read by the OCN application to a best effort of accuracy.
115 pub timestamp_ns: u64,
116 // The timestamp of the first byte read by the OCN application to a best effort of accuracy. It is RECOMMENDED that timestamps use Coordinated Universal Time (UTC).
117 pub timestamp_iso8601: Option<chrono::DateTime<Utc>>,
118 // The elapsed time between reading the first byte of the request and sending the last byte of the response to a best effort of accuracy.
119 pub s_time_total_ms: Option<u64>,
120 // An opaque identifier for an aggregate set of clients, derived from the client IPv4 or IPv6 address in the request received by the surrogate and/or other network-level identifying information. See [RFC7937] section 3.4.1.
121 pub c_groupid: Option<String>,
122 // The HTTP request method.
123 pub cs_method: Option<http::method::Method>,
124 // The protocol version (e.g., HTTP/1.1).
125 pub cs_version: Option<String>,
126 // Request URI prior to any transformation from MI.ProcessingStages. It is RECOMMENDED to limit the maximum length of this field with an applied MI.LoggingTransformTruncate, allowing at least 2048 bytes.
127 pub cs_uri: http::Uri,
128 // Full request URI, including query parameters. If this field is identical to cs-uri, the field SHOULD be truncated to an empty string.
129 pub cs_uri_transformed: Option<http::Uri>,
130 // The response status code.
131 pub sc_status: http::StatusCode,
132 // The response size total bytes, including headers.
133 pub sc_total_bytes: u64,
134 // The ccid assigned via MI.Grouping or MI.GroupingExtended configuration. For backward compatibility, s-ccid is aliased to ccid, and either identifier may be used to refer to this field.
135 pub s_ccid: String,
136 // The Session ID assigned by the dCDN. This can be derived from Common Media Client Data (CMCD) or another mechanism, but it is defined by the dCDN, and uCDN allocated session identifiers are outside the scope of this field.
137 pub s_sid: Option<String>,
138 // Indicates a cache hit or cache miss. For this field, a cache hit is defined as a request that does not result in content retrieval from the upstream source.
139 pub s_cached: Option<bool>,
140 // The client IP address.
141 pub c_ip: Option<net::IpAddr>,
142 // A short name for the dCDN intended to be used as an identifier, e.g. in log records. Example: "CDN Example Company" might have s-shortname of "cdn-ec".
143 pub s_shortname: Option<String>,
144 // The server instance ID assigned by the dCDN. This value SHOULD be unique to a particular instance.
145 pub s_id: Option<String>,
146 // The elapsed time from the first request byte read until the first response byte sent.
147 pub s_time_first_ms: Option<u64>,
148 // The session duration as determined by the dCDN.
149 pub s_sdur_ms: Option<u64>,
150 // The time spent accessing the upstream source. The value of this field is a "best effort". If there are intermediate cache layers, it is understood that this value may not accurately reflect the complete upstream picture.
151 pub s_time_upstream_ms: Option<u64>,
152 // Content header length from the upstream source. The value of this field is a "best effort". If there are intermediate cache layers, it is understood that this value may not accurately reflect the complete upstream picture.
153 pub s_upstream_header_size_bytes: u64,
154 // Total bytes transferred from the upstream source. The value of this field is a "best effort". If there are intermediate cache layers, it is understood that this value may not accurately reflect the complete upstream picture.
155 pub s_upstream_total_bytes: u64,
156 // The response status code returned by the upstream source in the event of a cache miss.
157 pub s_upstream_status: Option<http::StatusCode>,
158 // The IP address of the upstream source.
159 pub s_upstream_ip: Option<net::IpAddr>,
160}