Skip to content

Refactor stream connections for better readability, add stream metrics#131

Merged
temporal-nick merged 4 commits intomainfrom
nick/moremetrics
Aug 4, 2025
Merged

Refactor stream connections for better readability, add stream metrics#131
temporal-nick merged 4 commits intomainfrom
nick/moremetrics

Conversation

@temporal-nick
Copy link
Collaborator

What was changed

Added a bunch of metrics:

  • AdminServiceStreamDuration - Length the stream was open. If this drops to near-0, there's a problem
  • AdminServiceStreamsOpenedCount - Number of new streams opened
  • AdminServiceStreamsClosedCount - Number of streams closed
  • AdminServiceStreamReqCount - Number of requests sent through the stream
  • AdminServiceStreamRespCount - number of responses received through the stream
  • AdminServiceStreamTerminatedCount - Number of non-proxy-initiated stream terminations

Also refactored the logic in StreamWorkflowMessages to make it a little more obviously symmetric.

@temporal-nick temporal-nick requested a review from a team as a code owner July 30, 2025 23:07
@temporal-nick temporal-nick changed the title Refactor stream connections for better readability Refactor stream connections for better readability, add stream metrics Jul 30, 2025
Comment on lines +19 to +28
type StreamRequestOrResponse interface {
adminservice.StreamWorkflowReplicationMessagesRequest | adminservice.StreamWorkflowReplicationMessagesResponse
}
type ValueWithError[T StreamRequestOrResponse] struct {
val *T
err error
}
type recvable[T StreamRequestOrResponse] interface {
Recv() (*T, error)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: our style is to use a single type block for adjacent type declartions

(but it passes lint so 🤷 )

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update in a new PR

}
}()

wg.Add(2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, it looks like we didn't wait for both goroutines to finish. We only waited for one of the two 🤔

Seems like a good idea to wait for them both to finish, but calling it out as a difference anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, there's a little more machinery here now: I have the two goroutines communicate on when to stop so that both sides hangup when one dies. The major difference here is we will be returning io.EOF and hanging up the client more reliably in more situations. In non-exceptional behavior, it's the same.

return targetStreamServerData
}

func transferSourceToTarget(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it looks like the same parameter list for the two transfer funcs (transferSourceToTarget and transferTargetToSource). Can we make a new type that has those two funcs as methods?

One maybe benefit is that would enable shared state as an option instead of message passing, if that seems useful or simpler here (I haven't thought about it too closely though)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did try pretty hard to combine these, but I couldn't settle on a sane implementation. We'd need a pretty gnarly interface to grab what we needed out of the GRPC types, because the request and response aren't symmetric that way

@temporal-nick temporal-nick merged commit 5dafb3c into main Aug 4, 2025
6 checks passed
@temporal-nick temporal-nick deleted the nick/moremetrics branch August 4, 2025 22:33
hai719 pushed a commit to hai719/s2s-proxy that referenced this pull request Nov 24, 2025
temporalio#131)

* Refactor stream connections for better readability

* remove breaks to conform to linter

* Native histograms are behaving badly in Grafana, remove for now

* Remove remaining native histogram
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants