Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Update Events #549

Merged
merged 11 commits into from
Jan 4, 2017
Merged

Update Events #549

merged 11 commits into from
Jan 4, 2017

Conversation

johnflavin
Copy link
Contributor

  • Add event fields from docker updates
  • Document the version each had been added
  • Deprecate older fields
  • Update event tests to assert on new fields
  • Refactor event tests (now explicitly test event streaming and polling modes)

@johnflavin johnflavin mentioned this pull request Dec 22, 2016
@codecov-io
Copy link

codecov-io commented Dec 22, 2016

Current coverage is 47.79% (diff: 72.97%)

No coverage report found for master at 05446c8.

Powered by Codecov. Last update 05446c8...5e6a201

@davidxia
Copy link
Contributor

Looks like two event tests still fail on Docker 1.9.1. https://travis-ci.org/spotify/docker-client/jobs/186413456

@johnflavin
Copy link
Contributor Author

I fixed the tests for 1.9. Current build fails on 1.10, but it looks like a random, transient failure. Unrelated to my updates.

@davidxia
Copy link
Contributor

@johnflavin Thanks for the PR. I think the 1.10.3 build keeps failing for some reason though.

@johnflavin
Copy link
Contributor Author

Yes, that does look like a real failure. I spun up a 1.10.3 docker-machine vm, but I wasn't able to reproduce this.

I added assertions to the test that the stream does have events so that, at the very least, the test can FAIL with a message rather than just ERROR with an exception.

If this continues to happen on the travis machines, I do have a suspicion about the cause. In the past I have had issues with docker events not behaving like I expected; the cause turned out to be an mismatch between the clocks on the docker vm and the host machine (see moby/moby#25579 for more). I'm not sure if that is happening on the travis machines, but that is where I would investigate.

@johnflavin
Copy link
Contributor Author

Hey, all green! ✅

return new EventsFilterParam(name, value);
}

/**
* Show only certain events. For example, "event=pull" for image pull events.
* @param event Type of event to show
* @return EventsParam
* @since API 1.21
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think you are correct. Can fix.

/**
* Valid event types for EventsParam.type
*/
public enum EventType {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also test this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me think this through. I'm not sure exactly what you’re asking to test.

Do you mean we should test whether the filter=type=<> param works correctly, and that if we ask for, say, only image events, then that's all we get back? That's doable. A test could do a bunch of stuff—pull an image, create a container, create a volume, etc.—then ask docker for the different types of events one-by-one, and verify that we only get back what we expect.

Or do you mean to test the validity of the enum itself, that it has all the values that it needs to have? I don't know how that would be tested. I'm kind of trusting that the API fully documents all the valid values.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I meant the former.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. That might take a little time, but it shouldn't be too complicated.


public static class Actor {
@JsonProperty("ID") private String id;
@JsonProperty("Attributes") private ImmutableMap<String, Object> attributes;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this just be ImmutableMap<String, String> or do we expect nested JSON objects?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like it can be <String, String>. I'm not sure why I thought it was possible to get an Object there, but their swagger.yaml says Attributes will always have String values.

I'll fix that.

@davidxia
Copy link
Contributor

Nice. What changed to make it pass?

@johnflavin
Copy link
Contributor Author

Short answer: nothing. I'm pretty sure that event errors like that, where for some reason docker just doesn't give back events, are machine-dependent and not always reproducible. Like I said in my comment above it could very well be that the clock on the particular docker vm that they were using is out of sync with the host clock. Docker re-syncs occasionally, but in my experience it doesn't happen reliably and I have to manually sync to make the errors stop.

Copy link
Contributor

@davidxia davidxia left a comment

Choose a reason for hiding this comment

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

@johnflavin Thanks for adding the extra test. I had a few questions.

.build();

// Wait once to clean our event "palette" of events from other tests
Thread.sleep(1000);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably fine for now, but is there a way to check there are no leftover events? Perhaps we can use awaitility in the future here.

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 think I could do that. There is a case to avoid: when you are streaming events, if you ask for the next one and there is none, the thread will hang while it waits for more to come over the stream. But I can careful in my tests to only assert that there are no events when I have polled for events and the stream is already closed. Also, setting timeouts on the tests will help.

final ContainerCreation container = sut.createContainer(config, containerName);
final String containerId = container.id();
sut.startContainer(containerId);
Thread.sleep(1000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this to wait for the container to exit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is correct. Writing these tests, I got into problems when I tried to remove a container that was still running. I also tried to stop the container first, but sometimes it was stopped already so that caused its own problems.

assertThat(pullEvent.time(), notNullValue());
if (dockerApiVersionAtLeast("1.22")) {
assertEquals("image", pullEvent.type());
assertEquals(IMAGE.getName(), pullEvent.type());
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps make this method take more parameters like containerEventAssertions() below so we don't have to hard-code IMAGE and BUSYBOX_LATEST?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can do

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 left the IMAGE.getName() hard-coded. The method is a helper for assertions about image events only, so they will always have that event.type(). But I generalized the image name and the type of action.

@johnflavin
Copy link
Contributor Author

I just had a thought based on your comment. Currently the event type enum is in DockerClient; it is used as a parameter to filter events to those of certain types. However, the actual type member of Event just returns a String.

It seems it would make more sense to move enum Type from DockerClient into Event, and change String type to Type type.

Maybe I'll give that a go and see if it works.

@johnflavin
Copy link
Contributor Author

👆 ✅

@johnflavin
Copy link
Contributor Author

Ugh. I just realized that the best version of the Events model object is not just one class with enumerated types. It is a different class for each type, with enumerated actions.

@johnflavin
Copy link
Contributor Author

Test failure appears to be a travis hiccup, unrelated to PR.

@davidxia
Copy link
Contributor

davidxia commented Jan 3, 2017

@johnflavin I've seen similar spurious pull failures. I usually click the "restart job" button for the individual failed jobs to fix them.

@johnflavin
Copy link
Contributor Author

I don't have that button. Must be a Travis feature that only repo owners get.

Copy link
Contributor

@davidxia davidxia left a comment

Choose a reason for hiding this comment

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

cc @mattnworb if he wants to take a look.

@johnflavin
Copy link
Contributor Author

Oops. Didn't see the approval before I rebased.

@davidxia
Copy link
Contributor

davidxia commented Jan 3, 2017

That's OK. Your last commit is straight forward.

@mattnworb
Copy link
Member

lgtm 👍 thanks!

@davidxia davidxia merged commit 2164907 into spotify:master Jan 4, 2017
@johnflavin johnflavin deleted the events branch January 4, 2017 21:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants