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: add Status and ID as event attributes #3232

Merged
merged 1 commit into from
Jul 24, 2024

Conversation

CodeChanning
Copy link
Contributor

Adding Status and ID as attributes

Makes nerdctl events --format=json output more docker compatible by adding some missing attributes in nerdctl

Example docker events --format json output:

{"status":"start","id":"196016a57679bf42424484918746a9474cd905dd993c4d0f42..

(src: docker events doc)

Example nerdctl events --format json output after change:

{"Timestamp":"2024-07-18T19:10:40.489404968Z","ID":"ea3b75d7c5cf7e81b13f151dc7b4875e13c4f19776ca4c74f213866f0b016971","Namespace":"finch","Topic":"/tasks/start","Status":"START","Event":"{\"container_id\":\"ea3b75d7c5cf7e81b13f151dc7b4875e13c4f19776ca4c74f213866f0b016971\",\"pid\":39443}"}

(includes both status and id in output)

@CodeChanning CodeChanning marked this pull request as ready for review July 18, 2024 23:04
log.G(ctx).WithError(err).Warn("cannot marshal Any into JSON")
}

id := "unknown"
Copy link
Contributor

Choose a reason for hiding this comment

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

should we initialize as "" which is default for golang

Copy link
Contributor

Choose a reason for hiding this comment

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

because i think the clients might expect something like null to verify if the ID exist or not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. Changed the default value to be "".

@CodeChanning
Copy link
Contributor Author

@AkihiroSuda PTAL when you get the chance

}

id := ""
_, ok := data["container_id"]
Copy link
Member

Choose a reason for hiding this comment

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

This should be skipped when json.Unmarshal returned an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it should. I added an else statement, so now this will only run if json.Unmarshal doesn't return an error.

@CodeChanning CodeChanning force-pushed the events_attr branch 2 times, most recently from 265bfbd to 7456760 Compare July 23, 2024 21:52
@AkihiroSuda AkihiroSuda added this to the v2.0.0 milestone Jul 24, 2024
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda AkihiroSuda merged commit bec95c4 into containerd:main Jul 24, 2024
19 checks passed
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.

3 participants