Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add metrics for native chunk #8997

Merged
merged 2 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/connector/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ macro_rules! impl_common_split_reader_logic {
let data_stream = self.into_data_stream();

let data_stream = data_stream
.map_ok(move |data_batch| {
.inspect_ok(move |data_batch| {
metrics
.partition_input_count
.with_label_values(&[&actor_id, &source_id, &split_id])
Expand All @@ -286,7 +286,6 @@ macro_rules! impl_common_split_reader_logic {
.partition_input_bytes
.with_label_values(&[&actor_id, &source_id, &split_id])
.inc_by(sum_bytes);
data_batch
})
.boxed();
let parser =
Expand Down
18 changes: 16 additions & 2 deletions src/connector/src/source/datagen/source/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,22 @@ impl SplitReader for DatagenSplitReader {
// spawn_data_generation_stream(self.generator.into_native_stream(), BUFFER_SIZE).boxed()
match self.parser_config.specific {
SpecificParserConfig::Native => {
spawn_data_generation_stream(self.generator.into_native_stream(), BUFFER_SIZE)
.boxed()
let actor_id = self.source_ctx.source_info.actor_id.to_string();
let source_id = self.source_ctx.source_info.source_id.to_string();
let split_id = self.split_id.to_string();
let metrics = self.source_ctx.metrics.clone();
spawn_data_generation_stream(
self.generator
.into_native_stream()
.inspect_ok(move |chunk_with_states| {
metrics
.partition_input_count
.with_label_values(&[&actor_id, &source_id, &split_id])
.inc_by(chunk_with_states.chunk.cardinality() as u64);
}),
BUFFER_SIZE,
)
.boxed()
}
_ => self.into_chunk_stream(),
}
Expand Down
21 changes: 18 additions & 3 deletions src/connector/src/source/nexmark/source/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::time::Duration;

use anyhow::Result;
use async_trait::async_trait;
use futures::StreamExt;
use futures::{StreamExt, TryStreamExt};
use futures_async_stream::try_stream;
use maplit::hashmap;
use nexmark::config::NexmarkConfig;
Expand Down Expand Up @@ -105,15 +105,30 @@ impl SplitReader for NexmarkSplitReader {
}

fn into_stream(self) -> BoxSourceWithStateStream {
let actor_id = self.source_ctx.source_info.actor_id.to_string();
let source_id = self.source_ctx.source_info.source_id.to_string();
let split_id = self.split_id.clone();
let metrics = self.source_ctx.metrics.clone();

// Will buffer at most 4 event chunks.
const BUFFER_SIZE: usize = 4;
spawn_data_generation_stream(self.into_chunk_stream(), BUFFER_SIZE).boxed()
spawn_data_generation_stream(
self.into_native_stream()
.inspect_ok(move |chunk_with_states| {
metrics
.partition_input_count
.with_label_values(&[&actor_id, &source_id, &split_id])
.inc_by(chunk_with_states.chunk.cardinality() as u64);
}),
BUFFER_SIZE,
)
.boxed()
}
}

impl NexmarkSplitReader {
#[try_stream(boxed, ok = StreamChunkWithState, error = RwError)]
async fn into_chunk_stream(mut self) {
async fn into_native_stream(mut self) {
let start_time = Instant::now();
let start_offset = self.generator.global_offset();
let start_ts = self.generator.timestamp();
Expand Down