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

Event all the things! #18888

Merged
merged 5 commits into from Jan 4, 2016
Merged

Event all the things! #18888

merged 5 commits into from Jan 4, 2016

Conversation

calavera
Copy link
Contributor

@calavera calavera commented Dec 23, 2015

This is an attempt to make our events more rich and extensible.

In order to do that, we stop using JSONMessage as a struct to deliver events. That struct is an abomination for all kind of purposes, and the less we use it the better (imo). I created a specific purpose structure that includes new fields:

  • Type: it's the type of resource the event is triggered for, container, image, volume and network.
  • Action: it's the name of the event itself, create, destroy, mount, connect and so on.
  • Actor: it's information about the resource, ID, Name and Attributes. Attributes is an open map to send extra metadata, like the labels for a container event.

IMPORTANT: This change is backwards compatible at the API level, but not at the CLI level.

The new event structure preserves old fields that we've been using until now for container and image events. People consuming the API won't see any difference in those events, but will start to see events without information in those fields, because they come from storage and network operations.

I've included a test to guarantee that we keep that backwards compatible information: https://github.com/docker/docker/compare/master...calavera:event_types?expand=1#diff-1e68c88f5c9fa605c0f84199cd04feb0R38

The CLI output has been completely modified and it's standard for all types of events, the syntax is as follow:

timestamp actor_type action actor_id (<optional>actor_attributes)

The attributes are listed in KEY=VALUE format to be consistent with other places where we show this kind of values, like labels.

Some examples:

Networking and container events

Network events that operate on containers (connect and disconnect) include the container id as part of the attributes:

2015-12-23T21:38:24.705709133Z network create 8b111217944ba0ba844a65b13efcd57dc494932ee2527577758f939315ba2c5b (name=test-event-network-local, type=bridge)
2015-12-23T21:38:25.075955890Z container create b4be644031a3d90b400f88ab3d4bdf4dc23adb250e696b6328b85441abe2c54e (name=test-network-container, image=busybox)
2015-12-23T21:38:25.119625123Z network connect 8b111217944ba0ba844a65b13efcd57dc494932ee2527577758f939315ba2c5b (name=test-event-network-local, container=b4be644031a3d90b400f88ab3d4bdf4dc23adb250e696b6328b85441abe2c54e, type=bridge)
2015-12-23T21:38:25.121051956Z container start b4be644031a3d90b400f88ab3d4bdf4dc23adb250e696b6328b85441abe2c54e (name=test-network-container, image=busybox)

Storage and container events:

Storage events that operate on containers include the container id as part of the attributes:

2015-12-23T21:05:28.136212689Z volume create test-event-volume-local (driver=local)
2015-12-23T21:05:28.383462717Z volume mount test-event-volume-local (read/write=true, container=562fe10671e9273da25eed36cdce26159085ac7ee6707105fd534866340a5025, destination=/foo, driver=local, propagation=rprivate)
2015-12-23T21:05:28.650314265Z volume unmount test-event-volume-local (container=562fe10671e9273da25eed36cdce26159085ac7ee6707105fd534866340a5025, driver=local)
2015-12-23T21:05:28.716218405Z volume destroy test-event-volume-local (driver=local)

Future improvements out of the scope here

  1. Add a format flag with a go template.

TODO

  • Modify the events documentation.

/cc @coolljt0725, @dnephin

@thaJeztah
Copy link
Member

Nice! Looking at the command line output, should we put the type of event earlier on? the type of event is kinda hurried now. E.g.

2015-12-23T21:38:24.705709133Z network create 8b111217944ba0ba844a65b13efcd57dc494932ee2527577758f939315ba2c5b (test-event-network-local) (type: bridge)
2015-12-23T21:38:25.075955890Z container create b4be644031a3d90b400f88ab3d4bdf4dc23adb250e696b6328b85441abe2c54e (test-network-container) (image: busybox)
2015-12-23T21:38:25.119625123Z network connect 8b111217944ba0ba844a65b13efcd57dc494932ee2527577758f939315ba2c5b (test-event-network-local) (container: b4be644031a3d90b400f88ab3d4bdf4dc23adb250e696b6328b85441abe2c54e, type: bridge)
2015-12-23T21:38:25.121051956Z container start b4be644031a3d90b400f88ab3d4bdf4dc23adb250e696b6328b85441abe2c54e (test-network-container)  (image: busybox)

Or

2015-12-23T21:38:24.705709133Z create network 8b111217944ba0ba844a65b13efcd57dc494932ee2527577758f939315ba2c5b (test-event-network-local) (type: bridge)
2015-12-23T21:38:25.075955890Z create container  b4be644031a3d90b400f88ab3d4bdf4dc23adb250e696b6328b85441abe2c54e (test-network-container) (image: busybox)
2015-12-23T21:38:25.119625123Z connect network 8b111217944ba0ba844a65b13efcd57dc494932ee2527577758f939315ba2c5b (test-event-network-local) (container: b4be644031a3d90b400f88ab3d4bdf4dc23adb250e696b6328b85441abe2c54e, type: bridge)
2015-12-23T21:38:25.121051956Z start container b4be644031a3d90b400f88ab3d4bdf4dc23adb250e696b6328b85441abe2c54e (test-network-container)  (image: busybox)

We could even consider a --format flag in the future

@calavera
Copy link
Contributor Author

Obligatory regular expression meme (do not look at events_utils.go):

image

@thaJeztah I'm okay with moving the action at the beginning, let's wait to hear from other people to see if we agree in a format and I only need to change it once 😸

@thaJeztah
Copy link
Member

@calavera haha, absolutely, just my first impression looking at it. great work otherwise, I like it!

@thaJeztah
Copy link
Member

Oh, and
/cc @TomasTomecek @samsabed

@calavera calavera force-pushed the event_types branch 2 times, most recently from 3cef129 to 411e141 Compare December 23, 2015 22:30
ID: imageID.String(),
Name: newTag.String(),
}
daemon.EventsService.Log("tag", eventtypes.ImageEventType, actor)
Copy link
Member

Choose a reason for hiding this comment

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

I believe all the eventtypes.ImageEventType events should include the image labels in Actor.Attributes. Previously this was being injected by daemon.GetLabels()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, thanks!

Copy link
Member

Choose a reason for hiding this comment

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

I think they're all done except for this one place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😔 fixing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually there are a couple more places in pull/push :goberserk:

@dnephin
Copy link
Member

dnephin commented Dec 23, 2015

Nice! I think this is awesome. We'll be able to make use of the new event data in the soon-to-be-released docker-compose events command.

@calavera calavera force-pushed the event_types branch 4 times, most recently from f063836 to ce954d8 Compare December 23, 2015 23:54
@calavera
Copy link
Contributor Author

@thaJeztah one thing that I don't like about your suggested syntax is that it becomes harder to parse, because both name and attributes are optional at the end and are between parenthesis. But I'm open to suggestions.

@calavera
Copy link
Contributor Author

But I'm open to suggestions.

maybe we should add the name to the attributes. That would leave us only with one optional field, which I think it's better:

timestamp type action id (<optional>attributes)

Example:

2015-12-23T21:38:25.075955890Z container create b4be644031a3d90b400f88ab3d4bdf4dc23adb250e696b6328b85441abe2c54e (name: test-network-container, image: busybox)

@TomasTomecek
Copy link
Contributor

This is really impressive. Very nice work! A couple questions.

Will there be a precise documentation of what are the possible values (states) to expect? Regarding the new changes to layering, image IDs 'n stuff, would it make sense to also include digest? How about untagging an image, will I get the tag name? And last thing: would be super cool to unite events status and inspect status (inspect status contains text starting with capital letter and human-readable time which is a nightmare to parse).

@thaJeztah
Copy link
Member

@calavera oh, I like the suggestion of adding name to attributes. In addition, we can still add --format in a future PR. My primary concern was that the "type" of event got a bit lost in the other information, putting it more to the start of the line makes that easier to read (visually).

@calavera
Copy link
Contributor Author

Regarding the new changes to layering, image IDs 'n stuff, would it make sense to also include digest? How about untagging an image, will I get the tag name?

@TomasTomecek yes, with the new attributes, we can include more relevant information about the events, like that one. This is not a one time only change, we can improve the information we add to each event in the future.

And last thing: would be super cool to unite events status and inspect status (inspect status contains text starting with capital letter and human-readable time which is a nightmare to parse).

I'm not completely sure that's related to this change. I think we should discuss it further, but I understand your issues.

@calavera calavera force-pushed the event_types branch 3 times, most recently from 9eb3945 to 93be08b Compare December 28, 2015 20:18
@calavera
Copy link
Contributor Author

@thaJeztah I've changed the log format to put the name in the attributes.

I've also added a new feature to be able to filter by event type with --filter type=eventType, like --filter type=container or --filter type=network.

Can I have some 👍 / 👎 to all this before moving it to code review?

@TomasTomecek documentation is coming.

@calavera calavera force-pushed the event_types branch 2 times, most recently from 7027b1b to 5afee52 Compare December 28, 2015 20:42
Signed-off-by: David Calavera <david.calavera@gmail.com>
@calavera
Copy link
Contributor Author

calavera commented Jan 4, 2016

good point @moxiegirl. The API still works with old fields, but I agree that's worth noticing in the deprecation document. I added it already.

@thaJeztah
Copy link
Member

docs LGTM

@moxiegirl the API is backwards compatible, but CLI output changed, I think we should mention that in the release notes

@moxiegirl
Copy link
Contributor

@thaJeztah If by release notes you mean the changelog. Then we are good. :-)

@thaJeztah
Copy link
Member

potatoes potatos, yup that's what I meant, haha

@calavera
Copy link
Contributor Author

calavera commented Jan 4, 2016

calavera added a commit that referenced this pull request Jan 4, 2016
@calavera calavera merged commit 723be0a into moby:master Jan 4, 2016
@calavera calavera deleted the event_types branch January 4, 2016 21:07
@thaJeztah thaJeztah added this to the 1.10 milestone Jan 4, 2016
@TomasTomecek
Copy link
Contributor

@calavera very nice! can't wait to play with this

@thaJeztah
Copy link
Member

@TomasTomecek for playing; https://master.dockerproject.org is your friend :-) And please do! We can never have enough testers :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment