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

feature: support event service #2053

Merged
merged 1 commit into from
Aug 9, 2018

Conversation

HusterWan
Copy link
Contributor

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:

  • Publish: send event msg to Event Service
  • Subscribe: the client can subscribe all events of the pouchd

I 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

@codecov-io
Copy link

codecov-io commented Aug 5, 2018

Codecov Report

Merging #2053 into master will increase coverage by 0.12%.
The diff coverage is 71.73%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#criv1alpha1test 33.23% <0%> (-0.31%) ⬇️
#criv1alpha2test 33.87% <0%> (-0.34%) ⬇️
#integrationtest 37.94% <0%> (-0.33%) ⬇️
#unittest 23.6% <71.73%> (+0.49%) ⬆️
Impacted Files Coverage Δ
daemon/events/filter.go 60% <60%> (ø)
daemon/events/events.go 72.05% <72.05%> (ø)
apis/filters/parse.go 72.3% <72.3%> (ø)
cri/v1alpha2/cri.go 66.02% <0%> (-0.18%) ⬇️
daemon/mgr/container.go 53.89% <0%> (+0.15%) ⬆️
cri/v1alpha1/cri.go 65.36% <0%> (+0.17%) ⬆️
daemon/logger/jsonfile/utils.go 73.17% <0%> (+1.62%) ⬆️
... and 2 more

@@ -3597,6 +3597,49 @@ definitions:
items:
type: "string"

EventsMessage:
Copy link
Collaborator

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:

Copy link
Contributor Author

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

Copy link
Contributor Author

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:
Copy link
Collaborator

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"]
Copy link
Collaborator

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.


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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/publishing/publish

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch

// 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)")
Copy link
Contributor

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? 😄

)

func TestParseArgs(t *testing.T) {
// equivalent of `docker ps -f 'created=today' -f 'image.name=ubuntu*' -f 'image.name=*untu'`
Copy link
Contributor

Choose a reason for hiding this comment

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

s/docker/pouch/g

@HusterWan HusterWan force-pushed the zr/support-event branch 2 times, most recently from 695bcab to 904a45f Compare August 6, 2018 05:13
)

func TestParseArgs(t *testing.T) {
// equivalent of `pouch ps -f 'created=today' -f 'image.name=ubuntu*' -f 'image.name=*untu'`
Copy link
Contributor

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?

msg.Status = action
}

defer func() {
Copy link
Contributor

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

)

closeAll := func() {
defer close(errq)
Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

defer channel.Close()
}

ch = evch
Copy link
Contributor

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.

// 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???
Copy link
Contributor

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.

Copy link
Contributor Author

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.

eventsService := NewEvents()

t.Log("subscribe")
var cancel1, cancel2 func()
Copy link
Contributor

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>
@HusterWan
Copy link
Contributor Author

Updated @fuweid

@allencloud allencloud dismissed their stale review August 9, 2018 00:35

dismiss change request, since you separate the whole functionality

Copy link
Contributor

@fuweid fuweid left a comment

Choose a reason for hiding this comment

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

LGTM

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.

5 participants