|
| 1 | +use futures::stream; |
| 2 | +use prost::Message as _; |
| 3 | +use vector_lib::{ |
| 4 | + codecs::decoding::format::{Deserializer as _, OtlpDeserializer}, |
| 5 | + config::LogNamespace, |
| 6 | + opentelemetry::proto::{ |
| 7 | + collector::logs::v1::ExportLogsServiceRequest, |
| 8 | + logs::v1::{LogRecord, ResourceLogs, ScopeLogs}, |
| 9 | + resource::v1::Resource, |
| 10 | + }, |
| 11 | +}; |
| 12 | + |
| 13 | +use super::grpc::GrpcSinkConfig; |
| 14 | +use crate::{ |
| 15 | + config::SinkContext, |
| 16 | + test_util::{ |
| 17 | + components::{HTTP_SINK_TAGS, run_and_assert_sink_compliance}, |
| 18 | + wait_for_tcp, |
| 19 | + }, |
| 20 | +}; |
| 21 | + |
| 22 | +fn sink_grpc_address() -> String { |
| 23 | + std::env::var("OTEL_GRPC_SINK_ADDRESS") |
| 24 | + .unwrap_or_else(|_| "opentelemetry-collector:4317".to_owned()) |
| 25 | +} |
| 26 | + |
| 27 | +fn otlp_log_event() -> vector_lib::event::Event { |
| 28 | + let req = ExportLogsServiceRequest { |
| 29 | + resource_logs: vec![ResourceLogs { |
| 30 | + resource: Some(Resource { |
| 31 | + attributes: vec![], |
| 32 | + dropped_attributes_count: 0, |
| 33 | + }), |
| 34 | + scope_logs: vec![ScopeLogs { |
| 35 | + scope: None, |
| 36 | + log_records: vec![LogRecord { |
| 37 | + severity_text: "INFO".to_string(), |
| 38 | + body: Some(vector_lib::opentelemetry::proto::common::v1::AnyValue { |
| 39 | + value: Some( |
| 40 | + vector_lib::opentelemetry::proto::common::v1::any_value::Value::StringValue( |
| 41 | + "integration test log message".to_string(), |
| 42 | + ), |
| 43 | + ), |
| 44 | + }), |
| 45 | + ..Default::default() |
| 46 | + }], |
| 47 | + schema_url: String::new(), |
| 48 | + }], |
| 49 | + schema_url: String::new(), |
| 50 | + }], |
| 51 | + }; |
| 52 | + |
| 53 | + let bytes = bytes::Bytes::from(req.encode_to_vec()); |
| 54 | + let mut events = OtlpDeserializer::default() |
| 55 | + .parse(bytes, LogNamespace::Legacy) |
| 56 | + .expect("failed to deserialize OTLP log event"); |
| 57 | + events.remove(0) |
| 58 | +} |
| 59 | + |
| 60 | +#[tokio::test] |
| 61 | +async fn delivers_logs_via_grpc() { |
| 62 | + let address = sink_grpc_address(); |
| 63 | + wait_for_tcp(&address).await; |
| 64 | + |
| 65 | + let config: GrpcSinkConfig = toml::from_str(&format!( |
| 66 | + r#" |
| 67 | + endpoint = "http://{address}" |
| 68 | + "# |
| 69 | + )) |
| 70 | + .unwrap(); |
| 71 | + |
| 72 | + let (sink, _healthcheck) = config.build(SinkContext::default()).await.unwrap(); |
| 73 | + |
| 74 | + let events = vec![otlp_log_event()]; |
| 75 | + run_and_assert_sink_compliance(sink, stream::iter(events), &HTTP_SINK_TAGS).await; |
| 76 | +} |
0 commit comments