-
Notifications
You must be signed in to change notification settings - Fork 99
libartifact: introduce handling of artifact store events #768
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
Open
nimdrak
wants to merge
4
commits into
containers:main
Choose a base branch
from
nimdrak:introduce_an_event_channel_for_artifactstore
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a61bb36
libartifact: introduce handling of artifact store events
nimdrak 6362450
libartifact: use pointer receivers
nimdrak 1356a9a
libartifact: deduplicate Pull and Push logic
nimdrak 8afbf4d
libartifact: add tests for copyArtifact, withLockedLayout and EventCh…
nimdrak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| //go:build !remote | ||
|
|
||
| package libartifact | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/sirupsen/logrus" | ||
| ) | ||
|
|
||
| // EventType indicates the type of an event. | ||
| type EventType int | ||
|
|
||
| const ( | ||
| // EventTypeUnknown is an uninitialized EventType. | ||
| EventTypeUnknown EventType = iota | ||
| // EventTypeArtifactPull represents an artifact pull. | ||
| EventTypeArtifactPull | ||
| // EventTypeArtifactPullError represents a failed artifact pull. | ||
| EventTypeArtifactPullError | ||
| // EventTypeArtifactPush represents an artifact push. | ||
| EventTypeArtifactPush | ||
| // EventTypeArtifactPushError represents a failed artifact push. | ||
| EventTypeArtifactPushError | ||
| // EventTypeArtifactRemove represents an artifact removal. | ||
| EventTypeArtifactRemove | ||
| // EventTypeArtifactRemoveError represents a failed artifact removal. | ||
| EventTypeArtifactRemoveError | ||
| // EventTypeArtifactAdd represents an artifact being added. | ||
| EventTypeArtifactAdd | ||
| // EventTypeArtifactAddError represents a failed artifact add. | ||
| EventTypeArtifactAddError | ||
| ) | ||
|
|
||
| // Event represents an event such as an artifact pull or push. | ||
| type Event struct { | ||
| // ID of the object (e.g., artifact digest). | ||
| ID string | ||
| // Name of the object (e.g., artifact name "quay.io/foobar/artifact:special") | ||
| Name string | ||
| // Time of the event. | ||
| Time time.Time | ||
| // Type of the event. | ||
| Type EventType | ||
| // Error in case of failure. | ||
| Error error | ||
| } | ||
|
|
||
| // 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) { | ||
| select { | ||
| case as.eventChannel <- event: | ||
| // Done | ||
| case <-time.After(2 * time.Second): | ||
| // The store's event channel has a buffer of size 100 which | ||
| // should be enough even under high load. However, we | ||
| // shouldn't block too long in case the buffer runs full (could | ||
| // be an honest user error or bug). | ||
| logrus.Warnf("Discarding libartifact event which was not read within 2 seconds: %v", event) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this new? Do we report errors as events?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, some of these are new.
Our podman/libpod and container-libs/common/libimage only handles
PullErrorI thought it would be beneficial to notify clients about other errors as well, such as
AddError,RemoveError, andPushError. And I also addHowever, if there's a specific reason why we only track
PullError, I am completely open to removing these new additions.What do you think?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I introduced
AddEvent, I intentionally left out other events likeExtractandInspect. These are new too, but I only addedAddEventsince it's the only one that actually modifies the artifact store.