Revert "Merge pull request #16228 from duglin/ContextualizeEvents"
Although having a request ID available throughout the codebase is very valuable, the impact of requiring a Context as an argument to every function in the codepath of an API request, is too significant and was not properly understood at the time of the review. Furthermore, mixing API-layer code with non-API-layer code makes the latter usable only by API-layer code (one that has a notion of Context). This reverts commit de4164043546d2b9ee3bf323dbc41f4979c84480, reversing changes made to 7daeecd42d7bb112bfe01532c8c9a962bb0c7967. Signed-off-by: Tibor Vass <tibor@docker.com> Conflicts: api/server/container.go builder/internals.go daemon/container_unix.go daemon/create.go Upstream-commit: b08f071e18043abe8ce15f56826d38dd26bedb78 Component: engine
This commit is contained in:
@@ -410,7 +410,7 @@ func (s *DockerSuite) TestEventsFilterContainer(c *check.C) {
|
||||
}
|
||||
|
||||
// Check the id
|
||||
parsedID := strings.TrimSuffix(e[3], ":")
|
||||
parsedID := strings.TrimSuffix(e[1], ":")
|
||||
if parsedID != id {
|
||||
return fmt.Errorf("expected event for container id %s: %s - parsed container id: %s", id, event, parsedID)
|
||||
}
|
||||
@@ -686,78 +686,3 @@ func (s *DockerRegistrySuite) TestEventsImageFilterPush(c *check.C) {
|
||||
c.Fatalf("Missing 'push' log event for image %s\n%s", repoName, out)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsReqID(c *check.C) {
|
||||
// Tests for the "[reqid: xxx]" field in Events
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
reqIDMatch := `[^ ]+ \[reqid: ([0-9a-z]{12})\] [0-9a-z]+: `
|
||||
reqIDRE := regexp.MustCompile(reqIDMatch)
|
||||
|
||||
// Simple test just to make sure it works at all
|
||||
dockerCmd(c, "create", "busybox", "true")
|
||||
|
||||
out, _ := dockerCmd(c, "events", "--since=0", "--until=0s")
|
||||
events := strings.Split(strings.TrimSpace(out), "\n")
|
||||
|
||||
if len(events) == 0 {
|
||||
c.Fatalf("Wrong # of events, should just be one, got:\n%v\n", events)
|
||||
}
|
||||
|
||||
createEvent := events[len(events)-1]
|
||||
|
||||
matched, err := regexp.MatchString(reqIDMatch, createEvent)
|
||||
if err != nil || !matched {
|
||||
c.Fatalf("Error finding reqID in event: %v\n", createEvent)
|
||||
}
|
||||
|
||||
reqID1 := reqIDRE.FindStringSubmatch(createEvent)[1]
|
||||
|
||||
// Now make sure another cmd doesn't get the same reqID
|
||||
dockerCmd(c, "create", "busybox", "true")
|
||||
|
||||
out, _ = dockerCmd(c, "events", "--since=0", "--until=0s")
|
||||
events = strings.Split(strings.TrimSpace(out), "\n")
|
||||
createEvent = events[len(events)-1]
|
||||
|
||||
matched, err = regexp.MatchString(reqIDMatch, createEvent)
|
||||
if err != nil || !matched {
|
||||
c.Fatalf("Error finding reqID in event: %v\n", createEvent)
|
||||
}
|
||||
|
||||
reqID2 := reqIDRE.FindStringSubmatch(createEvent)[1]
|
||||
|
||||
if reqID1 == reqID2 {
|
||||
c.Fatalf("Should not have the same reqID(%s):\n%v\n", reqID1, createEvent)
|
||||
}
|
||||
|
||||
// Now make sure a build **does** use the same reqID for all
|
||||
// 4 events that are generated
|
||||
_, err = buildImage("reqidimg", `
|
||||
FROM busybox
|
||||
RUN echo HI`, true)
|
||||
if err != nil {
|
||||
c.Fatalf("Couldn't create image: %q", err)
|
||||
}
|
||||
|
||||
out, _ = dockerCmd(c, "events", "--since=0", "--until=0s")
|
||||
events = strings.Split(strings.TrimSpace(out), "\n")
|
||||
|
||||
// Get last event's reqID - will use it to find other matching events
|
||||
lastEvent := events[len(events)-1]
|
||||
reqID := reqIDRE.FindStringSubmatch(lastEvent)[1]
|
||||
|
||||
// Find all events with this same reqID
|
||||
eventList := []string{lastEvent}
|
||||
for i := len(events) - 2; i >= 0; i-- {
|
||||
tmpID := reqIDRE.FindStringSubmatch(events[i])[1]
|
||||
if tmpID != reqID {
|
||||
break
|
||||
}
|
||||
eventList = append(eventList, events[i])
|
||||
}
|
||||
|
||||
if len(eventList) != 5 { // create, start, die, commit, destroy
|
||||
c.Fatalf("Wrong # of matching events - should be 5:\n%q\n", eventList)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user