Skip to content

Commit 4af4e6c

Browse files
fix: remove custom flattening for otel logs (#1019)
with generic flattening in place, server doesn't need to perform custom flattening for the otel logs client does not need to send additional header `X-P-Log-Source=OTEL` for API `/v1/logs` which is specifically used for otel log ingestion no custom logic is required to verify if header `X-P-Log-Source` is sent no custom flattening is required either server does the flattening if it finds the nested structure and ingests
1 parent 935ee79 commit 4af4e6c

File tree

5 files changed

+15
-399
lines changed

5 files changed

+15
-399
lines changed

src/handlers/http/ingest.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
use super::logstream::error::{CreateStreamError, StreamError};
2020
use super::modal::utils::ingest_utils::{flatten_and_push_logs, push_logs};
21-
use super::otel;
2221
use super::users::dashboards::DashboardError;
2322
use super::users::filters::FiltersError;
2423
use crate::event::{
@@ -27,7 +26,7 @@ use crate::event::{
2726
format::{self, EventFormat},
2827
};
2928
use crate::handlers::http::modal::utils::logstream_utils::create_stream_and_schema_from_storage;
30-
use crate::handlers::{LOG_SOURCE_KEY, LOG_SOURCE_OTEL, STREAM_NAME_HEADER_KEY};
29+
use crate::handlers::STREAM_NAME_HEADER_KEY;
3130
use crate::localcache::CacheError;
3231
use crate::metadata::error::stream_info::MetadataError;
3332
use crate::metadata::STREAM_INFO;
@@ -115,25 +114,7 @@ pub async fn ingest_otel_logs(req: HttpRequest, body: Bytes) -> Result<HttpRespo
115114
{
116115
let stream_name = stream_name.to_str().unwrap().to_owned();
117116
create_stream_if_not_exists(&stream_name, &StreamType::UserDefined.to_string()).await?;
118-
119-
//flatten logs
120-
if let Some((_, log_source)) = req.headers().iter().find(|&(key, _)| key == LOG_SOURCE_KEY)
121-
{
122-
let log_source: String = log_source.to_str().unwrap().to_owned();
123-
if log_source == LOG_SOURCE_OTEL {
124-
let mut json = otel::flatten_otel_logs(&body);
125-
for record in json.iter_mut() {
126-
let body: Bytes = serde_json::to_vec(record).unwrap().into();
127-
push_logs(stream_name.to_string(), req.clone(), body).await?;
128-
}
129-
} else {
130-
return Err(PostError::CustomError("Unknown log source".to_string()));
131-
}
132-
} else {
133-
return Err(PostError::CustomError(
134-
"log source key header is missing".to_string(),
135-
));
136-
}
117+
push_logs(stream_name.to_string(), req.clone(), body).await?;
137118
} else {
138119
return Err(PostError::Header(ParseHeaderError::MissingStreamName));
139120
}

src/handlers/http/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ pub mod logstream;
3636
pub mod middleware;
3737
pub mod modal;
3838
pub mod oidc;
39-
mod otel;
4039
pub mod query;
4140
pub mod rbac;
4241
pub mod role;

src/handlers/http/modal/utils/ingest_utils.rs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
*
1717
*/
1818

19-
use std::{
20-
collections::{BTreeMap, HashMap},
21-
sync::Arc,
22-
};
19+
use std::{collections::HashMap, sync::Arc};
2320

2421
use actix_web::HttpRequest;
2522
use arrow_schema::Field;
@@ -33,8 +30,8 @@ use crate::{
3330
format::{self, EventFormat},
3431
},
3532
handlers::{
36-
http::{ingest::PostError, kinesis, otel},
37-
LOG_SOURCE_KEY, LOG_SOURCE_KINESIS, LOG_SOURCE_OTEL, PREFIX_META, PREFIX_TAGS, SEPARATOR,
33+
http::{ingest::PostError, kinesis},
34+
LOG_SOURCE_KEY, LOG_SOURCE_KINESIS, PREFIX_META, PREFIX_TAGS, SEPARATOR,
3835
},
3936
metadata::STREAM_INFO,
4037
storage::StreamType,
@@ -46,26 +43,19 @@ pub async fn flatten_and_push_logs(
4643
body: Bytes,
4744
stream_name: String,
4845
) -> Result<(), PostError> {
49-
//flatten logs
50-
if let Some((_, log_source)) = req.headers().iter().find(|&(key, _)| key == LOG_SOURCE_KEY) {
51-
let mut json: Vec<BTreeMap<String, Value>> = Vec::new();
52-
let log_source: String = log_source.to_str().unwrap().to_owned();
53-
match log_source.as_str() {
54-
LOG_SOURCE_KINESIS => json = kinesis::flatten_kinesis_logs(&body),
55-
LOG_SOURCE_OTEL => {
56-
json = otel::flatten_otel_logs(&body);
57-
}
58-
_ => {
59-
log::warn!("Unknown log source: {}", log_source);
60-
push_logs(stream_name.to_string(), req.clone(), body).await?;
61-
}
62-
}
63-
for record in json.iter_mut() {
46+
let log_source = req
47+
.headers()
48+
.get(LOG_SOURCE_KEY)
49+
.map(|header| header.to_str().unwrap_or_default())
50+
.unwrap_or_default();
51+
if log_source == LOG_SOURCE_KINESIS {
52+
let json = kinesis::flatten_kinesis_logs(&body);
53+
for record in json.iter() {
6454
let body: Bytes = serde_json::to_vec(record).unwrap().into();
65-
push_logs(stream_name.to_string(), req.clone(), body).await?;
55+
push_logs(stream_name.clone(), req.clone(), body.clone()).await?;
6656
}
6757
} else {
68-
push_logs(stream_name.to_string(), req, body).await?;
58+
push_logs(stream_name, req, body).await?;
6959
}
7060
Ok(())
7161
}

0 commit comments

Comments
 (0)