Skip to content

Commit 756b212

Browse files
authored
fix: fixes timestamps for finished containers in agent (#3509)
1 parent dae2877 commit 756b212

File tree

7 files changed

+204
-176
lines changed

7 files changed

+204
-176
lines changed

internal/agent/client.go

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -253,18 +253,19 @@ func (c *Client) StreamNewContainers(ctx context.Context, containers chan<- dock
253253
}
254254

255255
containers <- docker.Container{
256-
ID: resp.Container.Id,
257-
Name: resp.Container.Name,
258-
Image: resp.Container.Image,
259-
Labels: resp.Container.Labels,
260-
Group: resp.Container.Group,
261-
Created: resp.Container.Created.AsTime(),
262-
State: resp.Container.State,
263-
Health: resp.Container.Health,
264-
Host: resp.Container.Host,
265-
Tty: resp.Container.Tty,
266-
StartedAt: resp.Container.Started.AsTime(),
267-
Command: resp.Container.Command,
256+
ID: resp.Container.Id,
257+
Name: resp.Container.Name,
258+
Image: resp.Container.Image,
259+
Labels: resp.Container.Labels,
260+
Group: resp.Container.Group,
261+
Created: resp.Container.Created.AsTime(),
262+
State: resp.Container.State,
263+
Health: resp.Container.Health,
264+
Host: resp.Container.Host,
265+
Tty: resp.Container.Tty,
266+
StartedAt: resp.Container.Started.AsTime(),
267+
FinishedAt: resp.Container.Finished.AsTime(),
268+
Command: resp.Container.Command,
268269
}
269270
}
270271
}
@@ -287,19 +288,20 @@ func (c *Client) FindContainer(ctx context.Context, containerID string) (docker.
287288
}
288289

289290
return docker.Container{
290-
ID: response.Container.Id,
291-
Name: response.Container.Name,
292-
Image: response.Container.Image,
293-
Labels: response.Container.Labels,
294-
Group: response.Container.Group,
295-
Created: response.Container.Created.AsTime(),
296-
State: response.Container.State,
297-
Health: response.Container.Health,
298-
Host: response.Container.Host,
299-
Tty: response.Container.Tty,
300-
Command: response.Container.Command,
301-
StartedAt: response.Container.Started.AsTime(),
302-
Stats: utils.RingBufferFrom(300, stats),
291+
ID: response.Container.Id,
292+
Name: response.Container.Name,
293+
Image: response.Container.Image,
294+
Labels: response.Container.Labels,
295+
Group: response.Container.Group,
296+
Created: response.Container.Created.AsTime(),
297+
State: response.Container.State,
298+
Health: response.Container.Health,
299+
Host: response.Container.Host,
300+
Tty: response.Container.Tty,
301+
Command: response.Container.Command,
302+
StartedAt: response.Container.Started.AsTime(),
303+
FinishedAt: response.Container.Finished.AsTime(),
304+
Stats: utils.RingBufferFrom(300, stats),
303305
}, nil
304306
}
305307

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

333335
containers = append(containers, docker.Container{
334-
ID: container.Id,
335-
Name: container.Name,
336-
Image: container.Image,
337-
Labels: container.Labels,
338-
Group: container.Group,
339-
Created: container.Created.AsTime(),
340-
State: container.State,
341-
Health: container.Health,
342-
Host: container.Host,
343-
Tty: container.Tty,
344-
Command: container.Command,
345-
StartedAt: container.Started.AsTime(),
346-
Stats: utils.RingBufferFrom(300, stats),
336+
ID: container.Id,
337+
Name: container.Name,
338+
Image: container.Image,
339+
Labels: container.Labels,
340+
Group: container.Group,
341+
Created: container.Created.AsTime(),
342+
State: container.State,
343+
Health: container.Health,
344+
Host: container.Host,
345+
Tty: container.Tty,
346+
Command: container.Command,
347+
StartedAt: container.Started.AsTime(),
348+
FinishedAt: container.Finished.AsTime(),
349+
Stats: utils.RingBufferFrom(300, stats),
347350
})
348351
}
349352

internal/agent/client_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ func init() {
124124
Labels: map[string]string{
125125
"test": "test",
126126
},
127-
Stats: utils.NewRingBuffer[docker.ContainerStat](300),
127+
Stats: utils.NewRingBuffer[docker.ContainerStat](300),
128+
Created: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
129+
StartedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
130+
FinishedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
128131
}, nil)
129132

130133
server, _ := NewServer(client, certs, "test", docker.ContainerFilter{})
@@ -157,7 +160,10 @@ func TestFindContainer(t *testing.T) {
157160
Labels: map[string]string{
158161
"test": "test",
159162
},
160-
Stats: utils.NewRingBuffer[docker.ContainerStat](300),
163+
Stats: utils.NewRingBuffer[docker.ContainerStat](300),
164+
Created: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
165+
StartedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
166+
FinishedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
161167
})
162168
}
163169

@@ -183,7 +189,10 @@ func TestListContainers(t *testing.T) {
183189
Labels: map[string]string{
184190
"test": "test",
185191
},
186-
Stats: utils.NewRingBuffer[docker.ContainerStat](300),
192+
Stats: utils.NewRingBuffer[docker.ContainerStat](300),
193+
Created: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
194+
StartedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
195+
FinishedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
187196
},
188197
})
189198
}

internal/agent/pb/rpc.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/agent/pb/rpc_grpc.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)