Repository navigation
feat(streaming): add telemetry tags to stream metrics - #8631
Conversation
08da875 to
1b162ac
Compare
1b162ac to
3596e12
Compare
|
It's alive! @ReubenBond |
b046194 to
5749ab7
Compare
This commit introduces telemetry features to several components of the Orleans streaming system. Specifically, a new class, StreamInstrumentsTagUtils, has been created to provide methods for initializing the relevant telemetry tags. This utility is now utilized in numerous places throughout the codebase, including the PubSubRendezvousGrain and PersistentStreamPullingAgent classes, where it facilitates the monitoring of crucial streaming activities. This aids in diagnostics and performance tracking, contributing to ongoing system improvement efforts.
Use grain type instead of per-stream identifiers, keep consumer metrics balanced across add and remove paths, and add focused coverage in Orleans.Core.Tests. Co-authored-by: Copilot <[email protected]>
Enable nullable annotations for the stream tag helper, align new tests with file-scoped namespace conventions, and preserve DiagnosticListener emissions while applying tagged stream metrics. Co-authored-by: Copilot <[email protected]>
Revert formatting-only edits in PubSubRendezvousGrain while preserving the telemetry tag behavior changes. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot App <[email protected]> Copilot-Session: cd7955ca-4f1e-42b5-ac19-5d6d2c7c3959
a16145c to
2e03d91
Compare
There was a problem hiding this comment.
Pull request overview
Adds low-cardinality telemetry tags to Orleans streaming metrics to improve diagnostics and performance tracking across pub/sub and persistent streaming components.
Changes:
- Introduces
StreamInstrumentsTagUtilsto centralize creation of bounded, stable tag dimensions for streaming-related metrics. - Updates pub/sub (
PubSubRendezvousGrain) and persistent streaming (PersistentStreamPullingAgent) to emit metrics with tags only when instruments are enabled. - Adds unit tests validating tag stability/low cardinality and bounded dimensions.
Show a summary per file
| File | Description |
|---|---|
| test/Orleans.Core.Tests/OrleansRuntime/Streams/StreamInstrumentsTagUtilsTests.cs | Adds coverage verifying tag stability and bounded dimensions for stream/grain and queue scenarios. |
| src/Orleans.Streaming/StreamInstrumentsTagUtils.cs | New internal utility for generating low-cardinality TagList sets for stream/grain/queue metrics. |
| src/Orleans.Streaming/PubSub/PubSubRendezvousGrain.cs | Emits pub/sub counters with tags when enabled (added/removed/total for producers/consumers). |
| src/Orleans.Streaming/PersistentStreams/PersistentStreamPullingAgent.cs | Emits persistent stream read/sent message counters with tags when enabled. |
Copilot's findings
- Files reviewed: 4/4 changed files
- Comments generated: 1
| if (_streamInstruments.PubSubConsumersTotal.Enabled) | ||
| { | ||
| tags ??= StreamInstrumentsTagUtils.InitializeTags(streamId, streamConsumer); | ||
| _streamInstruments.PubSubConsumersTotal.Add( | ||
| -(initialProducerCount - State.Producers.Count), tags.Value); | ||
| } |
Co-authored-by: Copilot App <[email protected]> Copilot-Session: cd7955ca-4f1e-42b5-ac19-5d6d2c7c3959
There was a problem hiding this comment.
Copilot's findings
Suppressed comments (3)
src/Orleans.Streaming/PersistentStreams/PersistentStreamPullingAgent.cs:828
_streamInstrumentsis nullable, but is dereferenced without a null-guard when recordingPersistentStreamSentMessages. Capturing_streamInstrumentsinto a local avoids nullable dereference warnings and keeps the null-check and usage tied together.
if (_streamInstruments?.PersistentStreamSentMessages.Enabled is true)
{
tags ??= StreamInstrumentsTagUtils.InitializeTags(
consumerData.StreamId, consumerData.StreamConsumer.GetGrainId());
_streamInstruments.PersistentStreamSentMessages.Add(1, tags.Value);
}
src/Orleans.Streaming/PubSub/PubSubRendezvousGrain.cs:313
consumerStateis looked up unconditionally, even when bothPubSubConsumersRemovedandPubSubConsumersTotalinstruments are disabled. That adds an avoidable linear scan on every call. Consider only performing the lookup when at least one of those instruments is enabled.
var consumerState = State.Consumers.FirstOrDefault(s => s.Equals(subscriptionId));
src/Orleans.Streaming/PersistentStreams/PersistentStreamPullingAgent.cs:546
_streamInstrumentsis declared nullable, but is dereferenced without a null-guard in this block. While the?. ... is truecondition makes this safe at runtime, nullable flow analysis may still flag it and it’s easy to regress later. Capture_streamInstrumentsinto a local and use that for the check and theAddcall.
This issue also appears on line 823 of the same file.
if (_streamInstruments?.PersistentStreamReadMessages.Enabled is true)
{
tags = StreamInstrumentsTagUtils.InitializeTags(myQueueId, streamProviderName);
_streamInstruments.PersistentStreamReadMessages.Add(multiBatch.Count, tags.Value);
}
- Files reviewed: 4/4 changed files
- Comments generated: 0 new
Co-authored-by: Copilot App <[email protected]> Copilot-Session: cd7955ca-4f1e-42b5-ac19-5d6d2c7c3959
There was a problem hiding this comment.
Copilot's findings
Suppressed comments (3)
src/Orleans.Streaming/PubSub/PubSubRendezvousGrain.cs:223
PubSubConsumersTotalis incremented unconditionally, even if this call is re-registering an existing subscription (ie,pubSubStatewas already present). Since this counter is used as a +/- delta to represent the current total, it can drift upward and become inaccurate.
if (_streamInstruments.PubSubConsumersTotal.Enabled)
{
tags ??= StreamInstrumentsTagUtils.InitializeTags(streamId, streamConsumer);
_streamInstruments.PubSubConsumersTotal.Add(1, tags.Value);
}
src/Orleans.Streaming/StreamInstrumentsTagUtils.cs:18
grainId.Type.ToString()will not be null and does not map default/empty grain types to the intended low-cardinality"unknown"value. If a defaultGrainIdis ever passed, this will emit an empty/implicit grain_type dimension instead ofunknown.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static TagList InitializeTags(QualifiedStreamId streamId, GrainId grainId) =>
CreateStreamTags(streamId, grainId.Type.ToString() ?? UnknownGrainType);
src/Orleans.Streaming/PubSub/PubSubRendezvousGrain.cs:133
PubSubProducersTotalis being incremented even whenState.Producers.Add(...)is a no-op (eg, producer re-registers due to retries). Since this counter is used as a +/- delta to represent the current total, it can drift upward and become inaccurate.
This issue also appears on line 219 of the same file.
if (_streamInstruments.PubSubProducersTotal.Enabled)
{
tags ??= StreamInstrumentsTagUtils.InitializeTags(streamId, streamProducer);
_streamInstruments.PubSubProducersTotal.Add(1, tags.Value);
}
- Files reviewed: 4/4 changed files
- Comments generated: 0 new
This commit introduces telemetry features to several components of the Orleans streaming system. Specifically, a new class, StreamInstrumentsTagUtils, has been created to provide methods for initializing the relevant telemetry tags. This utility is now utilized in numerous places throughout the codebase, including the PubSubRendezvousGrain and PersistentStreamPullingAgent classes, where it facilitates the monitoring of crucial streaming activities. This aids in diagnostics and performance tracking, contributing to ongoing system improvement efforts.
Microsoft Reviewers: Open in CodeFlow