-
Notifications
You must be signed in to change notification settings - Fork 218
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 grpc protocol. #984
base: main
Are you sure you want to change the base?
add grpc protocol. #984
Conversation
44f145a
to
8286859
Compare
/cc @yanmxa |
376249c
to
ca8841e
Compare
protocol/grpc/write_message.go
Outdated
if value == nil { | ||
delete(b.Attributes, contenttype) | ||
} | ||
b.Attributes[contenttype], _ = attributeFor(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we delete the item from the map just to then re-add it here with nil
? Seems like this should be under an else
or just remove the if+delete on lines 126-128. Same for below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, added else
to handle non-nil case.
return err | ||
} | ||
} | ||
} else if name == contenttype { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if there's both 'contenttype' and 'ce-datacontenttype' ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'ce-datacontenttype' will be handled by:
sdk-go/protocol/grpc/message.go
Lines 122 to 128 in ab07228
if strings.HasPrefix(name, prefix) { | |
attr := m.version.Attribute(name) | |
if attr != nil { | |
err = encoder.SetAttribute(attr, attrVal) | |
if err != nil { | |
return err | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes but which one wins? Should we require them to be the same (if both are there)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When both 'ce-datacontenttype' and 'contenttype' are set, 'ce-datacontenttype' takes precedence. In practical scenarios, only 'contenttype' is necessary. Check how the 'contenttype' attribute is configured here:
sdk-go/protocol/grpc/write_message.go
Lines 121 to 130 in 6523960
case spec.DataContentType: | |
if value == nil { | |
delete(b.Attributes, contenttype) | |
} else { | |
attrVal, err := attributeFor(value) | |
if err != nil { | |
return err | |
} | |
b.Attributes[contenttype] = attrVal | |
} |
This follow the similar approach that the Kafka protocol and PubSub protocol take, refer to the implementations in the CloudEvents SDK for Kafka (https://github.com/cloudevents/sdk-go/blob/main/protocol/kafka_sarama/v2/write_producer_message.go#L103-L114) and PubSub (https://github.com/cloudevents/sdk-go/blob/main/protocol/pubsub/v2/write_pubsub_message.go#L70-L80).
protocol/grpc/write_message.go
Outdated
delete(b.Attributes, prefix+time) | ||
} | ||
b.Attributes[prefix+time], _ = attributeFor(value) | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: you can remove all of these "return nil" lines since it'll happen due to the return on line 156
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, done.
protocol/grpc/write_message.go
Outdated
|
||
b.Attributes[prefix+name], err = attributeFor(value) | ||
|
||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's define 'err' in the func instead of in the return arg - just for consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
I see we have a sample, but can we get some testcases too? |
unit tests are failing |
ca8841e
to
d4ad609
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some test cases, PTAL @duglin @lionelvillard
ab07228
to
f719045
Compare
@morvencao can you take a look at the failing checks? |
@duglin I've resolved the issues with testing and successfully executed it on my local environment, passing all tests. |
@@ -7,7 +7,8 @@ | |||
package pb | |||
|
|||
import ( | |||
any "github.com/golang/protobuf/ptypes/any" | |||
any1 "github.com/golang/protobuf/ptypes/any" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why replace any
with any1
? Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is generated by proto compiler, not manually altered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect it does this since any
is now a data type in go
// CloudEventServiceClient is the client API for CloudEventService service. | ||
// | ||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. | ||
type CloudEventServiceClient interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Publish-subscribe model has the characteristics: The publisher sends events without specifically targeting any recipient. Subscribers express interest in certain types of messages and receive notifications or updates when messages of interest are published.
In my opinion, the gRPC does not explicitly refer to the publish-subscribe model. Instead, it resembles more of a request-response model, like the HTTP protocol. So I suggest aligning these interfaces with the http protocol.
@@ -1 +0,0 @@ | |||
mode: atomic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please delete this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did delete the file. but I'm unsure if we should do that.
Based on the UT script at https://github.com/cloudevents/sdk-go/blob/main/hack/unit-test.sh#L20, it seems that coverage.tmp
is produced as intermediate output by UT. Deleting it should pose no harm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can restore it if there are additional uses that I overlooked.
4ea25db
to
8f12cd7
Compare
fixed the testing and rebased the code. |
rebase is needed |
Signed-off-by: morvencao <[email protected]>
Signed-off-by: morvencao <[email protected]>
Signed-off-by: morvencao <[email protected]>
Signed-off-by: morvencao <[email protected]>
Signed-off-by: morvencao <[email protected]>
Signed-off-by: morvencao <[email protected]>
Signed-off-by: morvencao <[email protected]>
8f12cd7
to
9dcecb3
Compare
resolve: #980