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

🎁 Pretty print cloud events #25

Merged

Conversation

cardil
Copy link
Member

@cardil cardil commented May 11, 2023

Changes

  • 🎁 Pretty print cloud events via wasm

Fixes #15
Follow up to #24

@cardil cardil marked this pull request as ready for review May 12, 2023 08:32
@openshift-ci openshift-ci bot requested review from alanfx and mgencur May 12, 2023 08:32
Copy link

@mgencur mgencur left a comment

Choose a reason for hiding this comment

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

Hey @cardil , I'm still playing with it but overall looks good to me.
I left some comments about putting , in the output vs. using :
Should the whole output on the console be json ? Or just the body might be json? (ok, I think just the body in the event of application/json contenttype)

This is my early feedback, will let you know when I'm done reviewing it.

* @returns {string} - the buffer
*/
function printAttr(attr) {
let buf = 'Context Attributes,\n'
Copy link

Choose a reason for hiding this comment

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

Should there be : after Context Attributes?
Running the tests, it gives me this:

Received event:
☁️  cloudevents.Event
Validation: valid
Context Attributes,
  specversion: 1.0
  type: com.redhat.openshift.knative.showcase.Hello
  source: //localhost/dev
  id: 780ed118-9509-4d7b-a612-97f278eb2b55
  time: 2022-02-24T02:15:27.522Z
  datacontenttype: application/json
Data,
  {
    "greeting": "Welcome",
    "who": "Developer31",
    "number": 64
  }

Copy link

Choose a reason for hiding this comment

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

@mgencur fwiw, this is the format that the golang cloudevents SDK prints events. I'm not saying one way or the other how it should be printed here other than to note that there is precedent for this format.

Copy link

Choose a reason for hiding this comment

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

I guess I should have read all of the comments, including @cardil's first. 🤣

Copy link

Choose a reason for hiding this comment

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

For the original viewer app, the output was just to print the event using the String() method. https://github.com/cloudevents/sdk-go/blob/ff0a142752d3253c3b974246c07f450421714f23/v2/event/event.go#L70-L97

Copy link

Choose a reason for hiding this comment

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

Thanks, ok good to know. I guess this is alright. Not saying I like it but we can use it as it's used elsewhere.

let buf = ''
const exts = extensions(ce, attr)
if (Object.keys(exts).length > 0) {
buf += `Extensions,\n`
Copy link

Choose a reason for hiding this comment

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

Should there be : after Extensions?
See my previous comment about the output.

var buf = new StringBuilder();
var data = ce.getData();
if (data != null) {
buf.append("Data,\n");
Copy link

Choose a reason for hiding this comment

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

Should there be : after Data instead of comma?

function printData(ce) {
let buf = ''
if (ce.data) {
buf += `Data,\n`
Copy link

Choose a reason for hiding this comment

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

Should there be : after Data?

var buf = new StringBuilder();
var exts = extensions(ce);
if (!exts.isEmpty()) {
buf.append("Extensions,\n");
Copy link

Choose a reason for hiding this comment

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

Should there be : after Extensions ?

private CharSequence printAttr(Map<String, Serializable> attr) {
var buf = new StringBuilder();
if (!attr.isEmpty()) {
buf.append("Context Attributes,\n");
Copy link

Choose a reason for hiding this comment

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

Should there be : after Attributes ?

@cardil
Copy link
Member Author

cardil commented May 16, 2023

The idea behind this exact format is to mimic the eventing event-display app: https://github.com/knative/eventing/blob/main/cmd/event_display/main.go#L41

The event display app is currently used in our docs, so I thought this would be the easier path to transition for our customers.

@mgencur
Copy link

mgencur commented May 16, 2023

Apparently, there's no easy way to build the target images locally. I guess we can merge it and I will check the image once the github action builds it.
This PR looks ok to me.

@mgencur
Copy link

mgencur commented May 18, 2023

/lgtm

@openshift-ci
Copy link

openshift-ci bot commented May 18, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cardil, mgencur

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 6000d2c into openshift-knative:latest May 18, 2023
@cardil cardil deleted the feature/pretty-print branch May 18, 2023 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Received events should be logged in human-readable form
4 participants