Skip to content

Commit

Permalink
fix: fixes timestamps for finished containers in agent (#3509)
Browse files Browse the repository at this point in the history
  • Loading branch information
amir20 authored Jan 6, 2025
1 parent dae2877 commit 756b212
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 176 deletions.
79 changes: 41 additions & 38 deletions internal/agent/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,19 @@ func (c *Client) StreamNewContainers(ctx context.Context, containers chan<- dock
}

containers <- docker.Container{
ID: resp.Container.Id,
Name: resp.Container.Name,
Image: resp.Container.Image,
Labels: resp.Container.Labels,
Group: resp.Container.Group,
Created: resp.Container.Created.AsTime(),
State: resp.Container.State,
Health: resp.Container.Health,
Host: resp.Container.Host,
Tty: resp.Container.Tty,
StartedAt: resp.Container.Started.AsTime(),
Command: resp.Container.Command,
ID: resp.Container.Id,
Name: resp.Container.Name,
Image: resp.Container.Image,
Labels: resp.Container.Labels,
Group: resp.Container.Group,
Created: resp.Container.Created.AsTime(),
State: resp.Container.State,
Health: resp.Container.Health,
Host: resp.Container.Host,
Tty: resp.Container.Tty,
StartedAt: resp.Container.Started.AsTime(),
FinishedAt: resp.Container.Finished.AsTime(),
Command: resp.Container.Command,
}
}
}
Expand All @@ -287,19 +288,20 @@ func (c *Client) FindContainer(ctx context.Context, containerID string) (docker.
}

return docker.Container{
ID: response.Container.Id,
Name: response.Container.Name,
Image: response.Container.Image,
Labels: response.Container.Labels,
Group: response.Container.Group,
Created: response.Container.Created.AsTime(),
State: response.Container.State,
Health: response.Container.Health,
Host: response.Container.Host,
Tty: response.Container.Tty,
Command: response.Container.Command,
StartedAt: response.Container.Started.AsTime(),
Stats: utils.RingBufferFrom(300, stats),
ID: response.Container.Id,
Name: response.Container.Name,
Image: response.Container.Image,
Labels: response.Container.Labels,
Group: response.Container.Group,
Created: response.Container.Created.AsTime(),
State: response.Container.State,
Health: response.Container.Health,
Host: response.Container.Host,
Tty: response.Container.Tty,
Command: response.Container.Command,
StartedAt: response.Container.Started.AsTime(),
FinishedAt: response.Container.Finished.AsTime(),
Stats: utils.RingBufferFrom(300, stats),
}, nil
}

Expand Down Expand Up @@ -331,19 +333,20 @@ func (c *Client) ListContainers(ctx context.Context, filter docker.ContainerFilt
}

containers = append(containers, docker.Container{
ID: container.Id,
Name: container.Name,
Image: container.Image,
Labels: container.Labels,
Group: container.Group,
Created: container.Created.AsTime(),
State: container.State,
Health: container.Health,
Host: container.Host,
Tty: container.Tty,
Command: container.Command,
StartedAt: container.Started.AsTime(),
Stats: utils.RingBufferFrom(300, stats),
ID: container.Id,
Name: container.Name,
Image: container.Image,
Labels: container.Labels,
Group: container.Group,
Created: container.Created.AsTime(),
State: container.State,
Health: container.Health,
Host: container.Host,
Tty: container.Tty,
Command: container.Command,
StartedAt: container.Started.AsTime(),
FinishedAt: container.Finished.AsTime(),
Stats: utils.RingBufferFrom(300, stats),
})
}

Expand Down
15 changes: 12 additions & 3 deletions internal/agent/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ func init() {
Labels: map[string]string{
"test": "test",
},
Stats: utils.NewRingBuffer[docker.ContainerStat](300),
Stats: utils.NewRingBuffer[docker.ContainerStat](300),
Created: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
StartedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
FinishedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
}, nil)

server, _ := NewServer(client, certs, "test", docker.ContainerFilter{})
Expand Down Expand Up @@ -157,7 +160,10 @@ func TestFindContainer(t *testing.T) {
Labels: map[string]string{
"test": "test",
},
Stats: utils.NewRingBuffer[docker.ContainerStat](300),
Stats: utils.NewRingBuffer[docker.ContainerStat](300),
Created: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
StartedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
FinishedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
})
}

Expand All @@ -183,7 +189,10 @@ func TestListContainers(t *testing.T) {
Labels: map[string]string{
"test": "test",
},
Stats: utils.NewRingBuffer[docker.ContainerStat](300),
Stats: utils.NewRingBuffer[docker.ContainerStat](300),
Created: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
StartedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
FinishedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
},
})
}
2 changes: 1 addition & 1 deletion internal/agent/pb/rpc.pb.go

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

2 changes: 1 addition & 1 deletion internal/agent/pb/rpc_grpc.pb.go

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

Loading

0 comments on commit 756b212

Please sign in to comment.