ryerraguntla commented on code in PR #3516:
URL: https://github.com/apache/iggy/pull/3516#discussion_r3449578802


##########
core/connectors/sources/otlp_source/src/server.rs:
##########
@@ -0,0 +1,152 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::convert;
+use iggy_connector_sdk::ProducedMessage;
+use opentelemetry_proto::tonic::collector::logs::v1::{
+    ExportLogsPartialSuccess, ExportLogsServiceRequest, 
ExportLogsServiceResponse,
+    logs_service_server::{LogsService, LogsServiceServer},
+};
+use opentelemetry_proto::tonic::collector::metrics::v1::{
+    ExportMetricsPartialSuccess, ExportMetricsServiceRequest, 
ExportMetricsServiceResponse,
+    metrics_service_server::{MetricsService, MetricsServiceServer},
+};
+use opentelemetry_proto::tonic::collector::trace::v1::{
+    ExportTracePartialSuccess, ExportTraceServiceRequest, 
ExportTraceServiceResponse,
+    trace_service_server::{TraceService, TraceServiceServer},
+};
+use tokio::sync::{mpsc, oneshot};
+use tonic::codec::CompressionEncoding;
+use tonic::transport::server::TcpIncoming;
+use tonic::{Request, Response, Status};
+use tracing::{error, info, warn};
+
+pub async fn run_grpc_server(
+    incoming: TcpIncoming,
+    tx: mpsc::Sender<ProducedMessage>,
+    shutdown: oneshot::Receiver<()>,
+) {
+    let logs_svc = LogsServiceImpl { tx: tx.clone() };
+    let metrics_svc = MetricsServiceImpl { tx: tx.clone() };
+    let trace_svc = TraceServiceImpl { tx };
+
+    // OTel SDKs and the Collector's OTLP exporter gzip-compress payloads by
+    // default, so every service must accept gzip on the wire. Responses are 
tiny
+    // (empty partial_success), but advertising gzip on send is harmless and 
lets
+    // clients negotiate it.
+    let logs_server = LogsServiceServer::new(logs_svc)
+        .accept_compressed(CompressionEncoding::Gzip)
+        .send_compressed(CompressionEncoding::Gzip);
+    let metrics_server = MetricsServiceServer::new(metrics_svc)
+        .accept_compressed(CompressionEncoding::Gzip)
+        .send_compressed(CompressionEncoding::Gzip);
+    let trace_server = TraceServiceServer::new(trace_svc)
+        .accept_compressed(CompressionEncoding::Gzip)
+        .send_compressed(CompressionEncoding::Gzip);
+
+    if let Err(err) = tonic::transport::Server::builder()
+        .add_service(logs_server)
+        .add_service(metrics_server)
+        .add_service(trace_server)
+        .serve_with_incoming_shutdown(incoming, async {
+            let _ = shutdown.await;
+            info!("OTLP gRPC server received shutdown signal");
+        })
+        .await
+    {
+        error!("OTLP gRPC server error: {err}");
+    }
+}
+
+struct LogsServiceImpl {
+    tx: mpsc::Sender<ProducedMessage>,
+}
+
+struct MetricsServiceImpl {
+    tx: mpsc::Sender<ProducedMessage>,
+}
+
+struct TraceServiceImpl {
+    tx: mpsc::Sender<ProducedMessage>,
+}
+
+#[tonic::async_trait]
+impl LogsService for LogsServiceImpl {
+    async fn export(
+        &self,
+        request: Request<ExportLogsServiceRequest>,
+    ) -> Result<Response<ExportLogsServiceResponse>, Status> {
+        let messages = convert::export_logs_to_messages(request.into_inner());
+        let rejected = send_messages(&self.tx, messages, "logs").await;
+        let partial_success = (rejected > 0).then(|| ExportLogsPartialSuccess {
+            rejected_log_records: rejected,
+            error_message: "channel full; records dropped".to_string(),
+        });
+        Ok(Response::new(ExportLogsServiceResponse { partial_success }))
+    }
+}
+
+#[tonic::async_trait]
+impl MetricsService for MetricsServiceImpl {
+    async fn export(
+        &self,
+        request: Request<ExportMetricsServiceRequest>,
+    ) -> Result<Response<ExportMetricsServiceResponse>, Status> {
+        let messages = 
convert::export_metrics_to_messages(request.into_inner());
+        let rejected = send_messages(&self.tx, messages, "metrics").await;
+        let partial_success = (rejected > 0).then(|| 
ExportMetricsPartialSuccess {
+            rejected_data_points: rejected,
+            error_message: "channel full; data points dropped".to_string(),
+        });
+        Ok(Response::new(ExportMetricsServiceResponse {
+            partial_success,
+        }))
+    }
+}
+
+#[tonic::async_trait]
+impl TraceService for TraceServiceImpl {
+    async fn export(
+        &self,
+        request: Request<ExportTraceServiceRequest>,
+    ) -> Result<Response<ExportTraceServiceResponse>, Status> {
+        let messages = 
convert::export_traces_to_messages(request.into_inner());
+        let rejected = send_messages(&self.tx, messages, "traces").await;
+        let partial_success = (rejected > 0).then(|| ExportTracePartialSuccess 
{
+            rejected_spans: rejected,
+            error_message: "channel full; spans dropped".to_string(),
+        });
+        Ok(Response::new(ExportTraceServiceResponse {
+            partial_success,
+        }))
+    }
+}
+

Review Comment:
   Log flood + misleading async: try_send failure at line 144 logs warn! per 
dropped message. Batch of 1000 saturated-channel messages → 1000 warn! calls 
per export. Additionally  async fn send_messages  contains no .await — 
misleading signature, function never yields. **Fix:** make it fn send_messages 
(non-async); count drops in loop, single warn!("dropped {dropped}/{total}   
{signal} messages") after loop.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to