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 grpc protocol. #984

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

morvencao
Copy link

resolve: #980

@morvencao
Copy link
Author

/cc @yanmxa

if value == nil {
delete(b.Attributes, contenttype)
}
b.Attributes[contenttype], _ = attributeFor(value)
Copy link
Contributor

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

Copy link
Author

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 {
Copy link
Contributor

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' ?

Copy link
Author

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:

if strings.HasPrefix(name, prefix) {
attr := m.version.Attribute(name)
if attr != nil {
err = encoder.SetAttribute(attr, attrVal)
if err != nil {
return err
}

Copy link
Contributor

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)?

Copy link
Author

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:

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).

delete(b.Attributes, prefix+time)
}
b.Attributes[prefix+time], _ = attributeFor(value)
return nil
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

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

thanks, done.


b.Attributes[prefix+name], err = attributeFor(value)

return
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

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

done.

@duglin
Copy link
Contributor

duglin commented Nov 10, 2023

I see we have a sample, but can we get some testcases too?

@duglin
Copy link
Contributor

duglin commented Nov 10, 2023

unit tests are failing

Copy link
Author

@morvencao morvencao left a 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

@duglin
Copy link
Contributor

duglin commented Dec 6, 2023

@morvencao can you take a look at the failing checks?

@morvencao
Copy link
Author

@duglin I've resolved the issues with testing and successfully executed it on my local environment, passing all tests.
I kindly request your approval to proceed with running the tests once more.

@@ -7,7 +7,8 @@
package pb

import (
any "github.com/golang/protobuf/ptypes/any"
any1 "github.com/golang/protobuf/ptypes/any"
Copy link
Contributor

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?

Copy link
Author

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.

Copy link
Contributor

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 {
Copy link
Contributor

@yanmxa yanmxa Dec 7, 2023

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
Copy link
Contributor

@duglin duglin Dec 7, 2023

Choose a reason for hiding this comment

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

please delete this file?

Copy link
Author

@morvencao morvencao Dec 7, 2023

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.

Copy link
Author

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.

@morvencao morvencao force-pushed the br_add_grpc_protocol branch 2 times, most recently from 4ea25db to 8f12cd7 Compare December 11, 2023 03:08
@morvencao
Copy link
Author

fixed the testing and rebased the code.

@duglin
Copy link
Contributor

duglin commented Jan 30, 2024

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]>
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.

gRPC protocol implementation
4 participants