Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/streams/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub use runtime::{
MEMORY_RUNTIME_NAME, MemoryStreamRuntime, REDIS_RUNTIME_NAME, RedisStreamRuntime,
RuntimeOptions, StreamRuntime,
};
pub use service::{MAX_RECORDS, MAX_WAIT};

/// The protos that lang and the crate exchange.
pub mod proto {
Expand Down
13 changes: 12 additions & 1 deletion crates/streams/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//! The crate's metrics. They use the meter that lang gives, or a no-op meter.

use temporalio_common::telemetry::metrics::{
Counter, MetricAttributes, MetricParameters, TemporalMeter,
Counter, MetricAttributes, MetricParameters, TemporalMeter, UpDownCounter,
};

#[derive(Clone)]
pub(crate) struct Metrics {
attributes: MetricAttributes,
fenced: Counter,
superseded: Counter,
blocking_reads_waiting: UpDownCounter,
}

fn parameters(
Expand Down Expand Up @@ -37,6 +38,11 @@ impl Metrics {
"Superseded flags that the Store set",
"",
)),
blocking_reads_waiting: meter.up_down_counter(parameters(
"stream_blocking_reads_waiting",
"Reads that wait on the Store",
"",
)),
}
}

Expand All @@ -47,4 +53,9 @@ impl Metrics {
pub(crate) fn superseded(&self) {
self.superseded.add(1, &self.attributes);
}

pub(crate) fn read_waits(&self, waiting: bool) {
self.blocking_reads_waiting
.add(if waiting { 1 } else { -1 }, &self.attributes);
}
}
9 changes: 8 additions & 1 deletion crates/streams/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use crate::{
Reason, StreamError, StreamResult,
memory::MemoryStore,
metrics::Metrics,
proto::{AppendRecordsRequest, CloseStreamRequest, DescribeStreamRequest, RedisStreamConfig},
proto::{
AppendRecordsRequest, CloseStreamRequest, DescribeStreamRequest, ReadRecordsRequest,
RedisStreamConfig,
},
redis::{RedisStore, RedisStoreOptions},
service::StreamService,
store::Store,
Expand Down Expand Up @@ -173,6 +176,10 @@ impl StreamRuntime {
.close_stream(decode::<CloseStreamRequest>(input)?)
.await?
.encode_to_vec(),
"ReadRecords" => service
.read_records(decode::<ReadRecordsRequest>(input)?)
.await?
.encode_to_vec(),
"DescribeStream" => service
.describe_stream(decode::<DescribeStreamRequest>(input)?)
.await?
Expand Down
Loading
Loading