libartifact: introduce handling of artifact store events#768
libartifact: introduce handling of artifact store events#768nimdrak wants to merge 4 commits intocontainers:mainfrom
Conversation
4066258 to
0afac95
Compare
|
Packit jobs failed. @containers/packit-build please check. |
0afac95 to
3ee8036
Compare
Signed-off-by: Byounguk Lee <nimdrak@gmail.com>
Signed-off-by: Byounguk Lee <nimdrak@gmail.com>
4f53335 to
6362450
Compare
- Introduced withLockedLayout and copyArtifact helpers to resolve dupl lint issues. - Maintained the original thread-locking scope for as.storePath access. - Fixed a resource leak by ensuring the copier is always closed using defer and capturing the close error. Signed-off-by: Byounguk Lee <nimdrak@gmail.com>
ec94ce0 to
1770e3d
Compare
…annel - TestArtifactStore_EventChannel deals with the cases: AddSuccessAndAddError, RemoveSuccess, PushError, PullError Signed-off-by: Byounguk Lee <nimdrak@gmail.com>
1770e3d to
8afbf4d
Compare
| // EventTypeArtifactPull represents an artifact pull. | ||
| EventTypeArtifactPull | ||
| // EventTypeArtifactPullError represents a failed artifact pull. | ||
| EventTypeArtifactPullError |
There was a problem hiding this comment.
Is this new? Do we report errors as events?
There was a problem hiding this comment.
Yes, some of these are new.
Our podman/libpod and container-libs/common/libimage only handles PullError
I thought it would be beneficial to notify clients about other errors as well, such as AddError, RemoveError, and PushError. And I also add
However, if there's a specific reason why we only track PullError, I am completely open to removing these new additions.
What do you think?
There was a problem hiding this comment.
While I introduced AddEvent, I intentionally left out other events like Extract and Inspect. These are new too, but I only added AddEvent since it's the only one that actually modifies the artifact store.
There was a problem hiding this comment.
I lean towards having events for the errors being unnecessary. Whatever is calling Podman is already going to be seeing the error.
There was a problem hiding this comment.
I objected the purpose of pullError when it was added so I will object any other Error type events, I really do not think we should spam the event channel with ton of errors.
There was a problem hiding this comment.
I think we have consensus: let's pull the error events. I think this is basically fine once they're out.
|
i realize this is not break changes but id like to see if we can get this in ... @nimdrak lets remove the additional events for now. I'm more concerned about you getting in the event handling, etc. |
I have 0 capacity to review this or other larger non 6 work right now so I rather not see this blocking 6 here... |
mtrmac
left a comment
There was a problem hiding this comment.
Just some notes… I suppose maintaining symmetry with libimage is more valuable, and anyway we don’t want to delay for any of this.
I didn’t read the tests.
| return "", err | ||
| } | ||
| // Execute fn while holding the store lock and providing a reference to the local layout. | ||
| func (as *ArtifactStore) withLockedLayout(localName string, fn func(localRef types.ImageReference) (digest.Digest, error)) (digest.Digest, error) { |
There was a problem hiding this comment.
I’d rather prefer using a typed ArtifactReference instead of plain strings whenever possible.
| return "", err | ||
| } | ||
| // Execute fn while holding the store lock and providing a reference to the local layout. | ||
| func (as *ArtifactStore) withLockedLayout(localName string, fn func(localRef types.ImageReference) (digest.Digest, error)) (digest.Digest, error) { |
There was a problem hiding this comment.
I’m not too convinced that this helper is worth it… it’s pretty specific to the two call sites and it does not read idiomatically, combining very unrelated lock handling and reference creation.
An universal withLockHeld would make a bit more sense to me, but that’s
- a bit annoying to do in Go (we can use generics for the return value, but there is no
voidtype) - clearly out of scope of this PR
| // EventChannel creates a buffered channel for events that the ArtifactStore will use | ||
| // to write events to. Callers are expected to read from the channel in a | ||
| // timely manner. | ||
| // Can be called once for a given ArtifactStore. |
There was a problem hiding this comment.
(This restriction seems unnecessary, given the implementation. Is this a general principle we want to hold? Yes, libimage says the same thing.)
| // Time of the event. | ||
| Time time.Time | ||
| // Type of the event. | ||
| Type EventType |
There was a problem hiding this comment.
(To the extent this is an ~enum discriminator, should it go first? OTOH this matches libimage.)
|
|
||
| // writeEvent writes the specified event to the store's event channel. The | ||
| // event is discarded if no event channel has been registered (yet). | ||
| func (as *ArtifactStore) writeEvent(event *Event) { |
There was a problem hiding this comment.
Non-blocking: I wouldn’t mind something like writeEvent(type …, digest digest.Digest, ref ArtifactStoreReference), to decrease the .String() and time.Now() tedium at call sites.
| ID string | ||
| // Name of the object (e.g., artifact name "quay.io/foobar/artifact:special") | ||
| Name string |
There was a problem hiding this comment.
Should these be more strictly typed? I have no idea.
fixed #465