@@ -103,13 +103,24 @@ pub struct OtlpServerSettings {
103103 /// Whether the receiver should wait.
104104 pub wait_for_result : bool ,
105105 /// Maximum size for inbound gRPC messages.
106+ /// ToDo: Note the Collector calls this max_recv_msg_size_mib,
107+ /// consider max_receive_message_size to reduce difference, add
108+ /// serde::from byte sizes.
109+ /// https://github.com/open-telemetry/opentelemetry-collector/blob/152042ebfa9d67731b23ae3cb5b23f585e13d2a2/config/configgrpc/configgrpc.go#L183
106110 pub max_decoding_message_size : Option < usize > ,
107111 /// Request compression allowed
108112 pub request_compression_encodings : EnabledCompressionEncodings ,
109113 /// Response compression used
110114 pub response_compression_encodings : EnabledCompressionEncodings ,
111115}
112116
117+ /// Encodes a default response for repeated use.
118+ fn encode_response < T : Message + Default > ( ) -> Bytes {
119+ let mut buf = Vec :: with_capacity ( T :: default ( ) . encoded_len ( ) ) ;
120+ T :: default ( ) . encode ( & mut buf) . expect ( "encode response" ) ;
121+ Bytes :: from ( buf)
122+ }
123+
113124/// Precomputed empty responses per signal to avoid per-call prost encoding.
114125fn precomputed_response ( signal : SignalType ) -> & ' static [ u8 ] {
115126 static LOGS : OnceLock < Bytes > = OnceLock :: new ( ) ;
@@ -118,52 +129,13 @@ fn precomputed_response(signal: SignalType) -> &'static [u8] {
118129
119130 match signal {
120131 SignalType :: Logs => LOGS
121- . get_or_init ( || {
122- let mut buf = Vec :: with_capacity (
123- ExportLogsServiceResponse {
124- partial_success : None ,
125- }
126- . encoded_len ( ) ,
127- ) ;
128- ExportLogsServiceResponse {
129- partial_success : None ,
130- }
131- . encode ( & mut buf)
132- . expect ( "encode logs response" ) ;
133- Bytes :: from ( buf)
134- } )
132+ . get_or_init ( encode_response :: < ExportLogsServiceResponse > )
135133 . as_ref ( ) ,
136134 SignalType :: Metrics => METRICS
137- . get_or_init ( || {
138- let mut buf = Vec :: with_capacity (
139- ExportMetricsServiceResponse {
140- partial_success : None ,
141- }
142- . encoded_len ( ) ,
143- ) ;
144- ExportMetricsServiceResponse {
145- partial_success : None ,
146- }
147- . encode ( & mut buf)
148- . expect ( "encode metrics response" ) ;
149- Bytes :: from ( buf)
150- } )
135+ . get_or_init ( encode_response :: < ExportMetricsServiceResponse > )
151136 . as_ref ( ) ,
152137 SignalType :: Traces => TRACES
153- . get_or_init ( || {
154- let mut buf = Vec :: with_capacity (
155- ExportTraceServiceResponse {
156- partial_success : None ,
157- }
158- . encoded_len ( ) ,
159- ) ;
160- ExportTraceServiceResponse {
161- partial_success : None ,
162- }
163- . encode ( & mut buf)
164- . expect ( "encode trace response" ) ;
165- Bytes :: from ( buf)
166- } )
138+ . get_or_init ( encode_response :: < ExportTraceServiceResponse > )
167139 . as_ref ( ) ,
168140 }
169141}
0 commit comments