Skip to content

Commit

Permalink
table_name method in OTLP TraceParser trait
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanbohan committed Oct 20, 2023
1 parent faafad3 commit 7f87dd9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/frontend/src/instance/otlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ impl OpenTelemetryProtocolHandler for Instance {
.check_permission(ctx.current_user(), PermissionReq::Otlp)
.context(AuthSnafu)?;

let spans = match self.plugins.get::<TraceParserRef>() {
Some(parser) => parser.parse(request),
None => otlp::trace::parse(request),
let (table_name, spans) = match self.plugins.get::<TraceParserRef>() {
Some(parser) => (parser.table_name(), parser.parse(request)),
None => (
otlp::trace::TRACE_TABLE_NAME.to_string(),
otlp::trace::parse(request),
),
};

let (requests, rows) = otlp::trace::to_grpc_insert_requests(spans)?;
let (requests, rows) = otlp::trace::to_grpc_insert_requests(table_name, spans)?;

let _ = self
.handle_row_inserts(requests, ctx)
Expand Down
1 change: 1 addition & 0 deletions src/servers/src/otlp/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use super::trace::TraceSpans;
/// - uplift some fields from Attributes (Map type) to column
pub trait TraceParser: Send + Sync {
fn parse(&self, request: ExportTraceServiceRequest) -> TraceSpans;
fn table_name(&self) -> String;
}

pub type TraceParserRef = Arc<dyn TraceParser>;
9 changes: 6 additions & 3 deletions src/servers/src/otlp/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::error::Result;
use crate::row_writer::{self, MultiTableData, TableData};

const APPROXIMATE_COLUMN_COUNT: usize = 16;
const TRACE_TABLE_NAME: &str = "traces_preview_v01";
pub const TRACE_TABLE_NAME: &str = "traces_preview_v01";

#[derive(Debug, Clone)]
#[allow(dead_code)]
Expand Down Expand Up @@ -71,10 +71,13 @@ pub type TraceSpans = Vec<TraceSpan>;
/// for data structure of OTLP metrics.
///
/// Returns `InsertRequests` and total number of rows to ingest
pub fn to_grpc_insert_requests(spans: TraceSpans) -> Result<(RowInsertRequests, usize)> {
pub fn to_grpc_insert_requests(
table_name: String,
spans: TraceSpans,
) -> Result<(RowInsertRequests, usize)> {
let mut multi_table_writer = MultiTableData::default();
let one_table_writer = multi_table_writer.get_or_default_table_data(
TRACE_TABLE_NAME,
table_name,
APPROXIMATE_COLUMN_COUNT,
APPROXIMATE_COLUMN_COUNT,
);
Expand Down

0 comments on commit 7f87dd9

Please sign in to comment.