-
Notifications
You must be signed in to change notification settings - Fork 948
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
feature: support event service #2053
feature: support event service #2053
Conversation
8a0ab24
to
341dd69
Compare
2c97668
to
46cf65f
Compare
Codecov Report
@@ Coverage Diff @@
## master #2053 +/- ##
==========================================
+ Coverage 63.8% 63.92% +0.12%
==========================================
Files 202 205 +3
Lines 15621 15759 +138
==========================================
+ Hits 9967 10074 +107
- Misses 4413 4435 +22
- Partials 1241 1250 +9
|
46cf65f
to
9b007dd
Compare
@@ -3597,6 +3597,49 @@ definitions: | |||
items: | |||
type: "string" | |||
|
|||
EventsMessage: |
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.
Please also add the route definition. like:
/containers/{id}/stop:
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.
i have split this whole feature into 4 parts, the api will be added at API pr
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.
@allencloud more information can refer: #2052
apis/swagger.yml
Outdated
description: "represents the information an event contains" | ||
type: "object" | ||
properties: | ||
status: |
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.
Please more details about the description of all these field. It would helps a lot for others to understand these.
apis/swagger.yml
Outdated
EventType: | ||
description: the type of event. For example, "container" or "image" | ||
type: "string" | ||
enum: ["container", "daemon", "image", "network", "plugin", "volume"] |
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.
We have already implemented all these object's events? Just double check.
Otherwise, I encourage that we add more information about which ones are TODO.
daemon/events/events.go
Outdated
|
||
defer func() { | ||
if err != nil { | ||
logrus.Errorf("failed to publishing event {action: %s, type: %s, id: %s}: %v", msg.Action, msg.Type, msg.ID, err) |
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.
s/publishing/publish
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.
good catch
apis/filters/parse.go
Outdated
// ErrBadFormat is an error returned when a filter is not in the form key=value | ||
// | ||
// Deprecated: this error will be removed in a future version | ||
var ErrBadFormat = errors.New("bad format of filter (expected name=value)") |
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.
could we remove this part? 😄
apis/filters/parse_test.go
Outdated
) | ||
|
||
func TestParseArgs(t *testing.T) { | ||
// equivalent of `docker ps -f 'created=today' -f 'image.name=ubuntu*' -f 'image.name=*untu'` |
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.
s/docker/pouch/g
695bcab
to
904a45f
Compare
) | ||
|
||
func TestParseArgs(t *testing.T) { | ||
// equivalent of `pouch ps -f 'created=today' -f 'image.name=ubuntu*' -f 'image.name=*untu'` |
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.
ping @Ace-Tang This function is duplicate with your implementation about ps filter
?
daemon/events/events.go
Outdated
msg.Status = action | ||
} | ||
|
||
defer func() { |
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.
we don't defer here and can log the info if err = nil. defer is not straight forward
daemon/events/events.go
Outdated
) | ||
|
||
closeAll := func() { | ||
defer close(errq) |
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.
why we use defer here? it is not necessary.
case ev := <-channel.C: | ||
env, ok := ev.(*types.EventsMessage) | ||
if !ok { | ||
err = errors.Errorf("invalid message encountered %#v; please file a bug", ev) |
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.
please file a bug
. funny. If we meet it, could we panic?
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.
no need panic, return err is ok, WDYT?
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.
ok
daemon/events/events.go
Outdated
defer channel.Close() | ||
} | ||
|
||
ch = evch |
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.
I don't need named return var here. The two statements are unless here.
daemon/events/events.go
Outdated
// Publish sends an event. The caller will be considered the initial | ||
// publisher of the event. This means the timestamp will be calculated | ||
// at this point and this method may read from the calling context. | ||
// TODO: do we need lock when use broadcaster??? |
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.
we don't need to lock the broadcaster, because broadcaster uses channel to receive the event. please remove this comment.
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.
you are right, i just record this to reminder me to check the lock.
daemon/events/events_test.go
Outdated
eventsService := NewEvents() | ||
|
||
t.Log("subscribe") | ||
var cancel1, cancel2 func() |
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.
since the following statements use :=
, it seems this line is useless here. how do you think?
Signed-off-by: Michael Wan <zirenwan@gmail.com>
904a45f
to
c72af5e
Compare
Updated @fuweid |
dismiss change request, since you separate the whole functionality
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.
LGTM
Signed-off-by: Michael Wan zirenwan@gmail.com
Ⅰ. Describe what this PR did
This PR is to finish the core logic of event service
Event
Service has two function:Event
ServiceI also support the
filter
to filter the event messages that client does not care aboutⅡ. Does this pull request fix one issue?
fixes part of #2052
Ⅲ. Describe how you did it
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews