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

add Name method to ReceiveChannel and SendChannel interface #1538

Conversation

bentveljanzx
Copy link
Contributor

@bentveljanzx bentveljanzx commented Jul 5, 2024

What was changed

  • Added Name method to SendChannel and ReceiveChannel interface
  • Added tests to assert Namereturns back the same given name.

Why?

  • We have custom wrappers around signalling receive and send calls so that we can attach OpenTelemetry to our signal payload. Since we want our spans to contain the signal name and happen before calling into the underlying channel.Send method, ideally we could simplify our API to not require a redundant sending of the channelName again.
    • ie. telemetrytemporal.ChannelSend[T](ctx workflow.Context, channel workflow.SendChannel, channelName string, payload T)

Checklist

Closes #1304

  1. How was this tested:
  • Added "TestChannelName" in internal/internal_coroutines_test.go which creates named channels and asserts that the Name method returns back the same name you gave it.
  1. Any docs updates needed?
  • N/A

@bentveljanzx bentveljanzx requested a review from a team as a code owner July 5, 2024 00:54
@CLAassistant
Copy link

CLAassistant commented Jul 5, 2024

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@bentveljanzx bentveljanzx changed the title add Name method to ReceiveChannel and SendChannel add Name method to ReceiveChannel and SendChannel interface Jul 5, 2024
@@ -66,8 +66,16 @@ var (
)

type (
// commonChannel contains methods common to both SendChannel and ReceiveChannel
commonChannel interface {
// Name returns the name of the channel.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a few things to the docs:

  1. Specify that for a SignalChannel , Name is the signal name. Some places in Temporal refer to signal "Name" as "Type" so it may not obvious.
  2. Specify that channels created without an explicit name have a name generated by the SDK and they should not assume it is deterministic. Normally all workflow APIs are deterministic, but in this case the channel name would not be.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added clarity to the documentation as requested

@Quinn-With-Two-Ns
Copy link
Contributor

Overall LGTM, just a couple of documentation points.

// SendChannel is a write only view of the Channel
SendChannel interface {
commonChannel
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this should be on the receive side only (send channel only used if user explicitly chooses to break it up, and they can't get things like Len() either even though technically we could provide it).

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason to restrict Name to only receive side channels? A sender could be interested in them name as much as the receiver is.

Copy link
Member

@cretz cretz Jul 8, 2024

Choose a reason for hiding this comment

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

Just wondering aloud. Can ask the same of Len. Go allows you to get len and cap on both recv-only and send-only channels but we decided Len() should only be on receive. I just wonder if we need to apply whatever that thought process is here. I don't mind if that same thing shouldn't apply here and we put Name() on both (though I think it'd be worth copying the definition twice vs making a new interface).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For our use-case we only use Name for the SendChannel case, so if anything I'd only want it on the SendChannel.

// SendChannel is a write only view of the Channel
SendChannel interface {
commonChannel
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if, even though we use aliases which make this harder, inlining the Name() method with the docs is clearer than a shared interface. It's just two places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will make the change if there's agreement between @Quinn-With-Two-Ns and yourself :)

One readability benefit of sharing the interface is it'll ensure documentation remains synced over time if it gets modified

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I think inlining is better for readability

Copy link
Contributor Author

@bentveljanzx bentveljanzx Jul 9, 2024

Choose a reason for hiding this comment

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

Updated and inlined. Also made tests explicitly test ReceiveChannel and SendChannel interfaces with Name

Comment on lines +74 to +75
// A Channel created without an explicit name will use a generated name by the SDK and
// is not deterministic.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// A Channel created without an explicit name will use a generated name by the SDK and
// is not deterministic.
// A Channel created without an explicit name will use a generated name by the SDK and
// is deterministic.

It is deterministic correct? (built from channel sequence)

Copy link
Contributor

Choose a reason for hiding this comment

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

It is not given our normal definition for what is deterministic, and I would not want suers to have any expectation of the SDK generated name

Copy link
Member

Choose a reason for hiding this comment

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

Our normal definition is "same during replay" I thought. Definitely no expectation of generated name, but it's still deterministic. Maybe we should just say "generated name by the SDK" without any additional info about determinism.

Copy link
Contributor

Choose a reason for hiding this comment

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

Even just creating another channel would change the value, we generally don't say creating a channel or switching the order you create channels in not deterministic.

@Quinn-With-Two-Ns Quinn-With-Two-Ns force-pushed the add-name-method-to-send-and-receive-channel-interface branch from c3bf2b8 to eb6ac13 Compare July 8, 2024 23:26
@bentveljanzx
Copy link
Contributor Author

If there's anything else outstanding / blocking merge, please let me know :)

@Quinn-With-Two-Ns Quinn-With-Two-Ns merged commit 25f450f into temporalio:master Jul 9, 2024
13 checks passed
@Quinn-With-Two-Ns
Copy link
Contributor

Thanks, merged!

@bentveljanzx bentveljanzx deleted the add-name-method-to-send-and-receive-channel-interface branch December 9, 2024 23:39
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.

Add GetName() func to Signal Chanel to return human readable name
4 participants