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

remove unused TopContainer API #3079

Merged
merged 1 commit into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions agent/dockerclient/dockerapi/docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ type DockerClient interface {
// provided for the request.
InspectContainer(context.Context, string, time.Duration) (*types.ContainerJSON, error)

// TopContainer returns information about the top processes running in the specified container. A timeout value and a context
// should be provided for the request. The last argument is an optional parameter for passing in 'ps' arguments
// as part of the top command.
TopContainer(context.Context, string, time.Duration, ...string) (*dockercontainer.ContainerTopOKBody, error)

// CreateContainerExec creates a new exec configuration to run an exec process with the provided Config. A timeout value
// and a context should be provided for the request.
CreateContainerExec(ctx context.Context, containerID string, execConfig types.ExecConfig, timeout time.Duration) (*types.IDResponse, error)
Expand Down Expand Up @@ -687,45 +682,6 @@ func (dg *dockerGoClient) inspectContainer(ctx context.Context, dockerID string)
return &containerData, err
}

func (dg *dockerGoClient) TopContainer(ctx context.Context, dockerID string, timeout time.Duration, psArgs ...string) (*dockercontainer.ContainerTopOKBody, error) {
type topResponse struct {
top *dockercontainer.ContainerTopOKBody
err error
}
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
defer metrics.MetricsEngineGlobal.RecordDockerMetric("TOP_CONTAINER")()
// Buffered channel so in the case of timeout it takes one write, never gets
// read, and can still be GC'd
response := make(chan topResponse, 1)
go func() {
top, err := dg.topContainer(ctx, dockerID, psArgs...)
response <- topResponse{top, err}
}()

// Wait until we get a response or for the 'done' context channel
select {
case resp := <-response:
return resp.top, resp.err
case <-ctx.Done():
err := ctx.Err()
if err == context.DeadlineExceeded {
return nil, &DockerTimeoutError{timeout, "listing top"}
}

return nil, &CannotGetContainerTopError{err}
}
}

func (dg *dockerGoClient) topContainer(ctx context.Context, dockerID string, psArgs ...string) (*dockercontainer.ContainerTopOKBody, error) {
client, err := dg.sdkDockerClient()
if err != nil {
return nil, err
}
topResponse, err := client.ContainerTop(ctx, dockerID, psArgs)
return &topResponse, err
}

func (dg *dockerGoClient) StopContainer(ctx context.Context, dockerID string, timeout time.Duration) DockerContainerMetadata {
ctxTimeout := timeout + stopContainerTimeoutBuffer
ctx, cancel := context.WithTimeout(ctx, ctxTimeout)
Expand Down
33 changes: 0 additions & 33 deletions agent/dockerclient/dockerapi/docker_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,39 +762,6 @@ func TestInspectContainer(t *testing.T) {
assert.True(t, reflect.DeepEqual(&containerOutput, container))
}

func TestTopContainerTimeout(t *testing.T) {
mockDockerSDK, client, _, _, _, done := dockerClientSetup(t)
defer done()

wait := &sync.WaitGroup{}
wait.Add(1)
mockDockerSDK.EXPECT().ContainerTop(gomock.Any(), "id", gomock.Any()).Do(func(ctx context.Context, x interface{}, y interface{}) {
wait.Wait()
}).MaxTimes(1).Return(dockercontainer.ContainerTopOKBody{}, nil)

ctx, cancel := context.WithCancel(context.TODO())
defer cancel()
_, err := client.TopContainer(ctx, "id", xContainerShortTimeout)
assert.Error(t, err, "Expected error for top timeout")
assert.Equal(t, "DockerTimeoutError", err.(apierrors.NamedError).ErrorName())
wait.Done()
}

func TestTopContainer(t *testing.T) {
mockDockerSDK, client, _, _, _, done := dockerClientSetup(t)
defer done()

topOutput := dockercontainer.ContainerTopOKBody{}
gomock.InOrder(
mockDockerSDK.EXPECT().ContainerTop(gomock.Any(), "id", gomock.Any()).Return(topOutput, nil),
)
ctx, cancel := context.WithCancel(context.TODO())
defer cancel()
topResponse, err := client.TopContainer(ctx, "id", dockerclient.TopContainerTimeout, "pid")
assert.NoError(t, err)
assert.Equal(t, &topOutput, topResponse)
}

func TestContainerEvents(t *testing.T) {
mockDockerSDK, client, _, _, _, done := dockerClientSetup(t)
defer done()
Expand Down
20 changes: 0 additions & 20 deletions agent/dockerclient/dockerapi/mocks/dockerapi_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions agent/dockerclient/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ const (
ListContainersTimeout = 10 * time.Minute
// InspectContainerTimeout is the timeout for the InspectContainer API.
InspectContainerTimeout = 30 * time.Second
// TopContainerTimeout is the timeout for the TopContainer API.
TopContainerTimeout = 30 * time.Second
// ContainerExecCreateTimeout is the timeout for the ContainerExecCreate API.
ContainerExecCreateTimeout = 1 * time.Minute
// ContainerExecStartTimeout is the timeout for the ContainerExecStart API.
Expand Down
10 changes: 1 addition & 9 deletions agent/engine/docker_task_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3468,12 +3468,9 @@ func TestMonitorExecAgentsMultipleContainers(t *testing.T) {
func TestPeriodicExecAgentsMonitoring(t *testing.T) {
ctx, cancel := context.WithCancel(context.TODO())
defer cancel()
ctrl, client, _, taskEngine, _, _, _ := mocks(t, ctx, &defaultConfig)
ctrl, _, _, taskEngine, _, _, _ := mocks(t, ctx, &defaultConfig)
defer ctrl.Finish()
execAgentPID := "1234"
resp := &dockercontainer.ContainerTopOKBody{
Processes: [][]string{{"root", execAgentPID}},
}
testTask := &apitask.Task{
Arn: "arn:aws:ecs:region:account-id:task/test-task-arn",
Containers: []*apicontainer.Container{
Expand All @@ -3492,11 +3489,6 @@ func TestPeriodicExecAgentsMonitoring(t *testing.T) {
taskEngine.(*DockerTaskEngine).managedTasks[testTask.Arn] = &managedTask{Task: testTask}
topCtx, topCancel := context.WithTimeout(context.Background(), time.Second)
defer topCancel()
client.EXPECT().TopContainer(gomock.Any(), testTask.Containers[0].RuntimeID, 30*time.Second, execAgentPID).DoAndReturn(
func(ctx context.Context, containerID string, timeout time.Duration, psArgs ...string) (*dockercontainer.ContainerTopOKBody, error) {
defer topCancel()
return resp, nil
}).AnyTimes()
go taskEngine.(*DockerTaskEngine).startPeriodicExecAgentsMonitoring(ctx)
<-topCtx.Done()
time.Sleep(5 * time.Millisecond)
Expand Down