opentelemetry_proto/proto/tonic/
opentelemetry.proto.collector.metrics.v1.rs

1// This file is @generated by prost-build.
2#[cfg_attr(feature = "with-schemars", derive(schemars::JsonSchema))]
3#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
4#[cfg_attr(feature = "with-serde", serde(rename_all = "camelCase"))]
5#[derive(Clone, PartialEq, ::prost::Message)]
6pub struct ExportMetricsServiceRequest {
7    /// An array of ResourceMetrics.
8    /// For data coming from a single resource this array will typically contain one
9    /// element. Intermediary nodes (such as OpenTelemetry Collector) that receive
10    /// data from multiple origins typically batch the data before forwarding further and
11    /// in that case this array will contain multiple elements.
12    #[prost(message, repeated, tag = "1")]
13    pub resource_metrics: ::prost::alloc::vec::Vec<
14        super::super::super::metrics::v1::ResourceMetrics,
15    >,
16}
17#[cfg_attr(feature = "with-schemars", derive(schemars::JsonSchema))]
18#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
19#[cfg_attr(feature = "with-serde", serde(rename_all = "camelCase"))]
20#[derive(Clone, PartialEq, ::prost::Message)]
21pub struct ExportMetricsServiceResponse {
22    /// The details of a partially successful export request.
23    ///
24    /// If the request is only partially accepted
25    /// (i.e. when the server accepts only parts of the data and rejects the rest)
26    /// the server MUST initialize the `partial_success` field and MUST
27    /// set the `rejected_<signal>` with the number of items it rejected.
28    ///
29    /// Servers MAY also make use of the `partial_success` field to convey
30    /// warnings/suggestions to senders even when the request was fully accepted.
31    /// In such cases, the `rejected_<signal>` MUST have a value of `0` and
32    /// the `error_message` MUST be non-empty.
33    ///
34    /// A `partial_success` message with an empty value (rejected_<signal> = 0 and
35    /// `error_message` = "") is equivalent to it not being set/present. Senders
36    /// SHOULD interpret it the same way as in the full success case.
37    #[prost(message, optional, tag = "1")]
38    pub partial_success: ::core::option::Option<ExportMetricsPartialSuccess>,
39}
40#[cfg_attr(feature = "with-schemars", derive(schemars::JsonSchema))]
41#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
42#[cfg_attr(feature = "with-serde", serde(rename_all = "camelCase"))]
43#[derive(Clone, PartialEq, ::prost::Message)]
44pub struct ExportMetricsPartialSuccess {
45    /// The number of rejected data points.
46    ///
47    /// A `rejected_<signal>` field holding a `0` value indicates that the
48    /// request was fully accepted.
49    #[prost(int64, tag = "1")]
50    pub rejected_data_points: i64,
51    /// A developer-facing human-readable message in English. It should be used
52    /// either to explain why the server rejected parts of the data during a partial
53    /// success or to convey warnings/suggestions during a full success. The message
54    /// should offer guidance on how users can address such issues.
55    ///
56    /// error_message is an optional field. An error_message with an empty value
57    /// is equivalent to it not being set.
58    #[prost(string, tag = "2")]
59    pub error_message: ::prost::alloc::string::String,
60}
61/// Generated client implementations.
62#[cfg(feature = "gen-tonic")]
63pub mod metrics_service_client {
64    #![allow(
65        unused_variables,
66        dead_code,
67        missing_docs,
68        clippy::wildcard_imports,
69        clippy::let_unit_value,
70    )]
71    use tonic::codegen::*;
72    use tonic::codegen::http::Uri;
73    /// Service that can be used to push metrics between one Application
74    /// instrumented with OpenTelemetry and a collector, or between a collector and a
75    /// central collector.
76    #[derive(Debug, Clone)]
77    pub struct MetricsServiceClient<T> {
78        inner: tonic::client::Grpc<T>,
79    }
80    impl MetricsServiceClient<tonic::transport::Channel> {
81        /// Attempt to create a new client by connecting to a given endpoint.
82        pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
83        where
84            D: TryInto<tonic::transport::Endpoint>,
85            D::Error: Into<StdError>,
86        {
87            let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
88            Ok(Self::new(conn))
89        }
90    }
91    impl<T> MetricsServiceClient<T>
92    where
93        T: tonic::client::GrpcService<tonic::body::Body>,
94        T::Error: Into<StdError>,
95        T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
96        <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
97    {
98        pub fn new(inner: T) -> Self {
99            let inner = tonic::client::Grpc::new(inner);
100            Self { inner }
101        }
102        pub fn with_origin(inner: T, origin: Uri) -> Self {
103            let inner = tonic::client::Grpc::with_origin(inner, origin);
104            Self { inner }
105        }
106        pub fn with_interceptor<F>(
107            inner: T,
108            interceptor: F,
109        ) -> MetricsServiceClient<InterceptedService<T, F>>
110        where
111            F: tonic::service::Interceptor,
112            T::ResponseBody: Default,
113            T: tonic::codegen::Service<
114                http::Request<tonic::body::Body>,
115                Response = http::Response<
116                    <T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
117                >,
118            >,
119            <T as tonic::codegen::Service<
120                http::Request<tonic::body::Body>,
121            >>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
122        {
123            MetricsServiceClient::new(InterceptedService::new(inner, interceptor))
124        }
125        /// Compress requests with the given encoding.
126        ///
127        /// This requires the server to support it otherwise it might respond with an
128        /// error.
129        #[must_use]
130        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
131            self.inner = self.inner.send_compressed(encoding);
132            self
133        }
134        /// Enable decompressing responses.
135        #[must_use]
136        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
137            self.inner = self.inner.accept_compressed(encoding);
138            self
139        }
140        /// Limits the maximum size of a decoded message.
141        ///
142        /// Default: `4MB`
143        #[must_use]
144        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
145            self.inner = self.inner.max_decoding_message_size(limit);
146            self
147        }
148        /// Limits the maximum size of an encoded message.
149        ///
150        /// Default: `usize::MAX`
151        #[must_use]
152        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
153            self.inner = self.inner.max_encoding_message_size(limit);
154            self
155        }
156        pub async fn export(
157            &mut self,
158            request: impl tonic::IntoRequest<super::ExportMetricsServiceRequest>,
159        ) -> std::result::Result<
160            tonic::Response<super::ExportMetricsServiceResponse>,
161            tonic::Status,
162        > {
163            self.inner
164                .ready()
165                .await
166                .map_err(|e| {
167                    tonic::Status::unknown(
168                        format!("Service was not ready: {}", e.into()),
169                    )
170                })?;
171            let codec = tonic::codec::ProstCodec::default();
172            let path = http::uri::PathAndQuery::from_static(
173                "/opentelemetry.proto.collector.metrics.v1.MetricsService/Export",
174            );
175            let mut req = request.into_request();
176            req.extensions_mut()
177                .insert(
178                    GrpcMethod::new(
179                        "opentelemetry.proto.collector.metrics.v1.MetricsService",
180                        "Export",
181                    ),
182                );
183            self.inner.unary(req, path, codec).await
184        }
185    }
186}
187/// Generated server implementations.
188#[cfg(feature = "gen-tonic")]
189pub mod metrics_service_server {
190    #![allow(
191        unused_variables,
192        dead_code,
193        missing_docs,
194        clippy::wildcard_imports,
195        clippy::let_unit_value,
196    )]
197    use tonic::codegen::*;
198    /// Generated trait containing gRPC methods that should be implemented for use with MetricsServiceServer.
199    #[async_trait]
200    pub trait MetricsService: std::marker::Send + std::marker::Sync + 'static {
201        async fn export(
202            &self,
203            request: tonic::Request<super::ExportMetricsServiceRequest>,
204        ) -> std::result::Result<
205            tonic::Response<super::ExportMetricsServiceResponse>,
206            tonic::Status,
207        >;
208    }
209    /// Service that can be used to push metrics between one Application
210    /// instrumented with OpenTelemetry and a collector, or between a collector and a
211    /// central collector.
212    #[derive(Debug)]
213    pub struct MetricsServiceServer<T> {
214        inner: Arc<T>,
215        accept_compression_encodings: EnabledCompressionEncodings,
216        send_compression_encodings: EnabledCompressionEncodings,
217        max_decoding_message_size: Option<usize>,
218        max_encoding_message_size: Option<usize>,
219    }
220    impl<T> MetricsServiceServer<T> {
221        pub fn new(inner: T) -> Self {
222            Self::from_arc(Arc::new(inner))
223        }
224        pub fn from_arc(inner: Arc<T>) -> Self {
225            Self {
226                inner,
227                accept_compression_encodings: Default::default(),
228                send_compression_encodings: Default::default(),
229                max_decoding_message_size: None,
230                max_encoding_message_size: None,
231            }
232        }
233        pub fn with_interceptor<F>(
234            inner: T,
235            interceptor: F,
236        ) -> InterceptedService<Self, F>
237        where
238            F: tonic::service::Interceptor,
239        {
240            InterceptedService::new(Self::new(inner), interceptor)
241        }
242        /// Enable decompressing requests with the given encoding.
243        #[must_use]
244        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
245            self.accept_compression_encodings.enable(encoding);
246            self
247        }
248        /// Compress responses with the given encoding, if the client supports it.
249        #[must_use]
250        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
251            self.send_compression_encodings.enable(encoding);
252            self
253        }
254        /// Limits the maximum size of a decoded message.
255        ///
256        /// Default: `4MB`
257        #[must_use]
258        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
259            self.max_decoding_message_size = Some(limit);
260            self
261        }
262        /// Limits the maximum size of an encoded message.
263        ///
264        /// Default: `usize::MAX`
265        #[must_use]
266        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
267            self.max_encoding_message_size = Some(limit);
268            self
269        }
270    }
271    impl<T, B> tonic::codegen::Service<http::Request<B>> for MetricsServiceServer<T>
272    where
273        T: MetricsService,
274        B: Body + std::marker::Send + 'static,
275        B::Error: Into<StdError> + std::marker::Send + 'static,
276    {
277        type Response = http::Response<tonic::body::Body>;
278        type Error = std::convert::Infallible;
279        type Future = BoxFuture<Self::Response, Self::Error>;
280        fn poll_ready(
281            &mut self,
282            _cx: &mut Context<'_>,
283        ) -> Poll<std::result::Result<(), Self::Error>> {
284            Poll::Ready(Ok(()))
285        }
286        fn call(&mut self, req: http::Request<B>) -> Self::Future {
287            match req.uri().path() {
288                "/opentelemetry.proto.collector.metrics.v1.MetricsService/Export" => {
289                    #[allow(non_camel_case_types)]
290                    struct ExportSvc<T: MetricsService>(pub Arc<T>);
291                    impl<
292                        T: MetricsService,
293                    > tonic::server::UnaryService<super::ExportMetricsServiceRequest>
294                    for ExportSvc<T> {
295                        type Response = super::ExportMetricsServiceResponse;
296                        type Future = BoxFuture<
297                            tonic::Response<Self::Response>,
298                            tonic::Status,
299                        >;
300                        fn call(
301                            &mut self,
302                            request: tonic::Request<super::ExportMetricsServiceRequest>,
303                        ) -> Self::Future {
304                            let inner = Arc::clone(&self.0);
305                            let fut = async move {
306                                <T as MetricsService>::export(&inner, request).await
307                            };
308                            Box::pin(fut)
309                        }
310                    }
311                    let accept_compression_encodings = self.accept_compression_encodings;
312                    let send_compression_encodings = self.send_compression_encodings;
313                    let max_decoding_message_size = self.max_decoding_message_size;
314                    let max_encoding_message_size = self.max_encoding_message_size;
315                    let inner = self.inner.clone();
316                    let fut = async move {
317                        let method = ExportSvc(inner);
318                        let codec = tonic::codec::ProstCodec::default();
319                        let mut grpc = tonic::server::Grpc::new(codec)
320                            .apply_compression_config(
321                                accept_compression_encodings,
322                                send_compression_encodings,
323                            )
324                            .apply_max_message_size_config(
325                                max_decoding_message_size,
326                                max_encoding_message_size,
327                            );
328                        let res = grpc.unary(method, req).await;
329                        Ok(res)
330                    };
331                    Box::pin(fut)
332                }
333                _ => {
334                    Box::pin(async move {
335                        let mut response = http::Response::new(
336                            tonic::body::Body::default(),
337                        );
338                        let headers = response.headers_mut();
339                        headers
340                            .insert(
341                                tonic::Status::GRPC_STATUS,
342                                (tonic::Code::Unimplemented as i32).into(),
343                            );
344                        headers
345                            .insert(
346                                http::header::CONTENT_TYPE,
347                                tonic::metadata::GRPC_CONTENT_TYPE,
348                            );
349                        Ok(response)
350                    })
351                }
352            }
353        }
354    }
355    impl<T> Clone for MetricsServiceServer<T> {
356        fn clone(&self) -> Self {
357            let inner = self.inner.clone();
358            Self {
359                inner,
360                accept_compression_encodings: self.accept_compression_encodings,
361                send_compression_encodings: self.send_compression_encodings,
362                max_decoding_message_size: self.max_decoding_message_size,
363                max_encoding_message_size: self.max_encoding_message_size,
364            }
365        }
366    }
367    /// Generated gRPC service name
368    pub const SERVICE_NAME: &str = "opentelemetry.proto.collector.metrics.v1.MetricsService";
369    impl<T> tonic::server::NamedService for MetricsServiceServer<T> {
370        const NAME: &'static str = SERVICE_NAME;
371    }
372}