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

feat: Generate extension attributes from proto annotations #62

Merged
merged 7 commits into from
Apr 21, 2023

Conversation

jskeet
Copy link
Collaborator

@jskeet jskeet commented Jun 9, 2021

No description provided.

@jskeet jskeet requested a review from a team as a code owner June 9, 2021 15:02
@product-auto-label product-auto-label bot added the api: eventarc Issues related to the googleapis/google-cloudevents-dotnet API. label Jun 9, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Jun 9, 2021
Copy link
Collaborator

@amanda-tarafa amanda-tarafa left a comment

Choose a reason for hiding this comment

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

LGTM. This is nice.

copybara-service bot pushed a commit to googleapis/google-cloudevents that referenced this pull request Jun 14, 2021
The `cloud_event_extension_attribute` annotation describes the attribute within events.proto, including the name, description and optional camel-cased name to aid tooling.

The `cloud_event_extension_name` annotation indicates that Eventarc will (sometimes conditionally) include the specified extension attribute for the given event.

Purpose of this change:

- Collect as much information about an event in these protos, as a single source of truth
- Enable tooling to make these extension attributes easier for customers to find. See googleapis/google-cloudevents-dotnet#62 as an example

PiperOrigin-RevId: 379281793
copybara-service bot pushed a commit to googleapis/google-cloudevents that referenced this pull request Jun 14, 2021
The `cloud_event_extension_attribute` annotation describes the attribute within events.proto, including the name, description and optional camel-cased name to aid tooling.

The `cloud_event_extension_name` annotation indicates that Eventarc will (sometimes conditionally) include the specified extension attribute for the given event.

Purpose of this change:

- Collect as much information about an event in these protos, as a single source of truth
- Enable tooling to make these extension attributes easier for customers to find. See googleapis/google-cloudevents-dotnet#62 as an example

PiperOrigin-RevId: 379281793
copybara-service bot pushed a commit to googleapis/google-cloudevents that referenced this pull request Jun 16, 2021
The `cloud_event_extension_attribute` annotation describes the attribute within events.proto, including the name, description and optional camel-cased name to aid tooling.

The `cloud_event_extension_name` annotation indicates that Eventarc will (sometimes conditionally) include the specified extension attribute for the given event.

Purpose of this change:

- Collect as much information about an event in these protos, as a single source of truth
- Enable tooling to make these extension attributes easier for customers to find. See googleapis/google-cloudevents-dotnet#62 as an example

PiperOrigin-RevId: 379281793
copybara-service bot pushed a commit to googleapis/google-cloudevents that referenced this pull request Jun 16, 2021
The `cloud_event_extension_attribute` annotation describes the attribute within events.proto, including the name, description and optional camel-cased name to aid tooling.

The `cloud_event_extension_name` annotation indicates that Eventarc will (sometimes conditionally) include the specified extension attribute for the given event.

Purpose of this change:

- Collect as much information about an event in these protos, as a single source of truth
- Enable tooling to make these extension attributes easier for customers to find. See googleapis/google-cloudevents-dotnet#62 as an example

PiperOrigin-RevId: 379672582
jskeet pushed a commit to googleapis/google-cloudevents that referenced this pull request Jun 16, 2021
The `cloud_event_extension_attribute` annotation describes the attribute within events.proto, including the name, description and optional camel-cased name to aid tooling.

The `cloud_event_extension_name` annotation indicates that Eventarc will (sometimes conditionally) include the specified extension attribute for the given event.

Purpose of this change:

- Collect as much information about an event in these protos, as a single source of truth
- Enable tooling to make these extension attributes easier for customers to find. See googleapis/google-cloudevents-dotnet#62 as an example

PiperOrigin-RevId: 379672582
grant added a commit to googleapis/google-cloudevents that referenced this pull request Jul 13, 2021
* feat: Add proto annotations for extension attributes.

The `cloud_event_extension_attribute` annotation describes the attribute within events.proto, including the name, description and optional camel-cased name to aid tooling.

The `cloud_event_extension_name` annotation indicates that Eventarc will (sometimes conditionally) include the specified extension attribute for the given event.

Purpose of this change:

- Collect as much information about an event in these protos, as a single source of truth
- Enable tooling to make these extension attributes easier for customers to find. See googleapis/google-cloudevents-dotnet#62 as an example

PiperOrigin-RevId: 379672582

* docs: Remove TODO from Firestore event payload comment.

PiperOrigin-RevId: 379709462

* Update to service catalog.

PiperOrigin-RevId: 381051093

* Update to service catalog.

PiperOrigin-RevId: 383638369

* docs: update readme catalog

Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>

Co-authored-by: Copybara Bot <yoshi-code-bot@google.com>
Co-authored-by: Jon Skeet <jonskeet@google.com>
Co-authored-by: Grant Timmerman <744973+grant@users.noreply.github.com>
Co-authored-by: Grant Timmerman <timmerman+devrel@google.com>
jay-shi added a commit to googleapis/google-cloudevents that referenced this pull request Sep 27, 2021
* feat: Add proto annotations for extension attributes.

The `cloud_event_extension_attribute` annotation describes the attribute within events.proto, including the name, description and optional camel-cased name to aid tooling.

The `cloud_event_extension_name` annotation indicates that Eventarc will (sometimes conditionally) include the specified extension attribute for the given event.

Purpose of this change:

- Collect as much information about an event in these protos, as a single source of truth
- Enable tooling to make these extension attributes easier for customers to find. See googleapis/google-cloudevents-dotnet#62 as an example

PiperOrigin-RevId: 379672582

* docs: Remove TODO from Firestore event payload comment.

PiperOrigin-RevId: 379709462

* Update to service catalog.

PiperOrigin-RevId: 381051093

* Update to service catalog.

PiperOrigin-RevId: 383638369

* docs: update readme catalog

Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>

* Update service catalogs

PiperOrigin-RevId: 387121524

* Revert "Update service catalogs"

This reverts commit 0266aac.
This is to address the problem where 0266aac removes the CAL proto.
This commit reverts that change. Later I will add a new CL that updates
the service catalog.

* Update to service catalog.

PiperOrigin-RevId: 391849235

* Update Service Catalog on Sept 27, 2021

PiperOrigin-RevId: 399304046

Co-authored-by: Copybara Bot <yoshi-code-bot@google.com>
Co-authored-by: Jon Skeet <jonskeet@google.com>
Co-authored-by: Grant Timmerman <744973+grant@users.noreply.github.com>
Co-authored-by: Grant Timmerman <timmerman+devrel@google.com>
Co-authored-by: Jay Shi <jayshi@google.com>
Co-authored-by: Averi Kitsch <akitsch@google.com>
jay-shi added a commit to googleapis/google-cloudevents that referenced this pull request Nov 18, 2021
* feat: Add proto annotations for extension attributes.

The `cloud_event_extension_attribute` annotation describes the attribute within events.proto, including the name, description and optional camel-cased name to aid tooling.

The `cloud_event_extension_name` annotation indicates that Eventarc will (sometimes conditionally) include the specified extension attribute for the given event.

Purpose of this change:

- Collect as much information about an event in these protos, as a single source of truth
- Enable tooling to make these extension attributes easier for customers to find. See googleapis/google-cloudevents-dotnet#62 as an example

PiperOrigin-RevId: 379672582

* docs: Remove TODO from Firestore event payload comment.

PiperOrigin-RevId: 379709462

* Update to service catalog.

PiperOrigin-RevId: 381051093

* Update to service catalog.

PiperOrigin-RevId: 383638369

* docs: update readme catalog

Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>

* Update service catalogs

PiperOrigin-RevId: 387121524

* Revert "Update service catalogs"

This reverts commit 0266aac.
This is to address the problem where 0266aac removes the CAL proto.
This commit reverts that change. Later I will add a new CL that updates
the service catalog.

* Update to service catalog.

PiperOrigin-RevId: 391849235

* Update Service Catalog on Sept 27, 2021

PiperOrigin-RevId: 399304046

* Remove invalid method names from service catalog.

PiperOrigin-RevId: 401831500

* Update Service Catalog

PiperOrigin-RevId: 403148687

* Update Service Catalog on Oct 29, 2021

PiperOrigin-RevId: 406397501

* Update Service Catalog with missing methodName

PiperOrigin-RevId: 406825642

* Add matrix_id field to CloudEvent payload for Firebase Test Lab

PiperOrigin-RevId: 409185529

* Update Service Catalog on November 15, 2021

PiperOrigin-RevId: 409994579

Co-authored-by: Copybara Bot <yoshi-code-bot@google.com>
Co-authored-by: Jon Skeet <jonskeet@google.com>
Co-authored-by: Grant Timmerman <744973+grant@users.noreply.github.com>
Co-authored-by: Grant Timmerman <timmerman+devrel@google.com>
Co-authored-by: Averi Kitsch <akitsch@google.com>
@averikitsch
Copy link

@jskeet should this be merged or is this just a prototype example?

@rogerthatdev rogerthatdev added the needs work This is a pull request that needs a little love. label Aug 29, 2022
@jskeet
Copy link
Collaborator Author

jskeet commented Apr 20, 2023

It looks like cloud_event_extension_attribute is being fairly widely used, so I'll revisit this and hopefully be able to merge it.

This allows simpler access to proto annotations.
(This is the result of the previous commit.)
@jskeet jskeet requested a review from a team as a code owner April 20, 2023 08:54
@jskeet jskeet changed the title Prototype of generating extension attributes from proto annotations feat: Generate extension attributes from proto annotations Apr 20, 2023
Copy link
Collaborator

@amanda-tarafa amanda-tarafa left a comment

Choose a reason for hiding this comment

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

LGTM, as my comments are for consideration. But this is fine as is as well.

var bytes = TestResourceHelper.LoadBytes("structured-mode-body-with-extension.json");
var formatter = new ProtobufJsonCloudEventFormatter<FunctionEventData>();
var evt = formatter.DecodeStructuredModeMessage(bytes, null, null);
Assert.Equal("sample-function", evt[ExtensionAttributes.Function]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

If Function is an extension that applies to another event, what's the error message?
Maybe a test for that, if only for documenting the error and trying to improve if needed, could be fine.

I know there's already a TODO on the generation code to take into account the event type the attributes apply to, which would help a lot here. I've left a comment there about that TODO maybe being something to do now?

Also, maybe consider making these actual extension methods: evt.GetFunction();? The Extension name predisposed me to finding extension methods.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If Function is an extension that applies to another event, what's the error message?

There won't be an error - it'll just return null (IIRC, anyway). I'll add a test for that, thanks.

I know there's already a TODO on the generation code to take into account the event type the attributes apply to, which would help a lot here. I've left a comment there about that TODO maybe being something to do now?

Hmm. I don't think it's worth changing how the attributes are generated (in terms of API surface)... partly because there's a problem here in terms of the same event message (e.g. FunctionEventData) being used for multiple event types.

However, I could:

  • Only generate them when we know of at least one event type
  • Generate documentation saying which event types they're used for

Also, maybe consider making these actual extension methods: evt.GetFunction();? The Extension name predisposed me to finding extension methods.

Right, that's CloudEvent terminology clashing with C# terminology. I don't think I want to add extension methods at the moment, partly because it's so easy to get into collisions if you use multiple namespaces. But we could add that later, if we get customer feedback.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, all this sounds good, including documentation for the extension attributes. And thanks for the test.

@@ -125,6 +125,45 @@ private static void GenerateCode(IEnumerable<CloudEventDataInfo> infos, string s
}
}

private static void GenerateCloudEventAttributes(FileDescriptorSet descriptorSet, string srcDirectory, string project)
{
// TODO: Use the information about which extension attribute is used within which event type?
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you want to translate this to something static, say {EventType}ExtensionAttributes classes, that'd be a breaking change. Unless you are thinking more about validation?
I think that both static and validation would be nice.

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 didn't have a specific scenario in mind - but I think documentation generation would be a good start, as described above.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep documentation sounds good actually.

@jskeet jskeet removed the needs work This is a pull request that needs a little love. label Apr 20, 2023
This exposes extension attributes (as static properties) within a static ExtensionAttributes class per directory.
The extension attributes are all expected to be strings, and are not currently used in the formatter - but they can still be accessed afterwards. (Test will come after generation commit.)

Unfortunately, in order to implement this, the generator needed
fairly significant rewriting.
This now generates the extension attributes
This uses a cut-down version of a real event - although Eventarc always delivers it in binary mode, which is harder to test, so I've converted it into structured mode.
@jskeet
Copy link
Collaborator Author

jskeet commented Apr 20, 2023

Okay, this is now rewritten to provide documentation about which event types are used for which extension attributes. PTAL @amanda-tarafa (when you have time).

Copy link
Collaborator

@amanda-tarafa amanda-tarafa left a comment

Choose a reason for hiding this comment

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

LGTM

/// <summary>
/// <para>The resource ID of the Api triggering the event.</para>
///
/// <para>This is used by the following events:</para>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!

@@ -69,8 +69,10 @@ public static partial class DataReflection {
"KAsyNi5nb29nbGUuZXZlbnRzLmNsb3VkLmZpcmVzdG9yZS52MS5NYXBWYWx1",
"ZS5GaWVsZHNFbnRyeRpWCgtGaWVsZHNFbnRyeRILCgNrZXkYASABKAkSNgoF",
"dmFsdWUYAiABKAsyJy5nb29nbGUuZXZlbnRzLmNsb3VkLmZpcmVzdG9yZS52",
"MS5WYWx1ZToCOAFCLKoCKUdvb2dsZS5FdmVudHMuUHJvdG9idWYuQ2xvdWQu",
"RmlyZXN0b3JlLlYxYgZwcm90bzM="));
"MS5WYWx1ZToCOAFCdqoCKUdvb2dsZS5FdmVudHMuUHJvdG9idWYuQ2xvdWQu",
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are no extension attributes generated for Firestore and a few others, like CloudBuild and Storage. Just flagging in case that's not expected.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There are no extension attributes generated for Firestore and a few others, like CloudBuild and Storage. Just flagging in case that's not expected.

Just checked those three, and events.proto doesn't declare any. (I suspect they may be added later, as I'm pretty sure they should have them.) That won't be breaking, so I'm not too worried :)

@jskeet jskeet merged commit 50e03f8 into googleapis:main Apr 21, 2023
4 checks passed
@jskeet jskeet deleted the attribute-annotations branch April 21, 2023 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: eventarc Issues related to the googleapis/google-cloudevents-dotnet API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants