Skip to content

Commit

Permalink
wip finished
Browse files Browse the repository at this point in the history
  • Loading branch information
amir20 committed Jan 3, 2025
1 parent cc620ad commit 294ad89
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
8 changes: 6 additions & 2 deletions internal/docker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,16 @@ func newContainerFromJSON(c types.ContainerJSON, host string) Container {
Tty: c.Config.Tty,
}

if createdAt, err := time.Parse(time.RFC3339Nano, c.Created); err == nil {
container.Created = createdAt.UTC()
}

if startedAt, err := time.Parse(time.RFC3339Nano, c.State.StartedAt); err == nil {
container.StartedAt = startedAt.UTC()
}

if createdAt, err := time.Parse(time.RFC3339Nano, c.Created); err == nil {
container.Created = createdAt.UTC()
if stoppedAt, err := time.Parse(time.RFC3339Nano, c.State.FinishedAt); err == nil {
container.FinishedAt = stoppedAt.UTC()
}

if c.State.Health != nil {
Expand Down
28 changes: 15 additions & 13 deletions internal/docker/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ import (

// Container represents an internal representation of docker containers
type Container struct {
ID string `json:"id"`
Name string `json:"name"`
Image string `json:"image"`
Command string `json:"command"`
Created time.Time `json:"created"`
StartedAt time.Time `json:"startedAt,omitempty"`
State string `json:"state"`
Health string `json:"health,omitempty"`
Host string `json:"host,omitempty"`
Tty bool `json:"-"`
Labels map[string]string `json:"labels,omitempty"`
Stats *utils.RingBuffer[ContainerStat] `json:"stats,omitempty"`
Group string `json:"group,omitempty"`
ID string `json:"id"`
Name string `json:"name"`
Image string `json:"image"`
Command string `json:"command"`
Created time.Time `json:"created"`
StartedAt time.Time `json:"startedAt"`
FinishedAt time.Time `json:"finishedAt"`
State string `json:"state"`
Health string `json:"health,omitempty"`
Host string `json:"host,omitempty"`
Tty bool `json:"-"`
Labels map[string]string `json:"labels,omitempty"`
Stats *utils.RingBuffer[ContainerStat] `json:"stats,omitempty"`
Group string `json:"group,omitempty"`
}

// ContainerStat represent stats instant for a container
Expand All @@ -41,6 +42,7 @@ type ContainerEvent struct {
Host string `json:"host"`
ActorID string `json:"actorId"`
ActorAttributes map[string]string `json:"actorAttributes,omitempty"`
Time time.Time `json:"time"`
}

type ContainerFilter map[string][]string
Expand Down
11 changes: 10 additions & 1 deletion internal/web/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,16 @@ func (h *handler) streamLogsForContainers(w http.ResponseWriter, r *http.Request
if err != nil {
if errors.Is(err, io.EOF) {
log.Debug().Str("container", container.ID).Msg("streaming ended")
events <- &docker.ContainerEvent{ActorID: container.ID, Name: "container-stopped", Host: container.Host}
finishedAt := container.FinishedAt
if container.FinishedAt.IsZero() {
finishedAt = time.Now()
}
events <- &docker.ContainerEvent{
ActorID: container.ID,
Name: "container-stopped",
Host: container.Host,
Time: finishedAt,
}
} else if !errors.Is(err, context.Canceled) {
log.Error().Err(err).Str("container", container.ID).Msg("unknown error while streaming logs")
}
Expand Down

0 comments on commit 294ad89

Please sign in to comment.