Add additional logging around resource polling

This commit is contained in:
Dane Everitt 2020-09-03 21:19:06 -07:00
parent 490f874128
commit d99225c0fb
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
3 changed files with 14 additions and 4 deletions

View File

@ -61,7 +61,11 @@ func (e *Environment) Attach() error {
// from being reached until it is completed if not run in a seperate process. However,
// we still want it to be stopped when the copy operation below is finished running which
// indicates that the container is no longer running.
go e.pollResources(ctx)
go func(ctx context.Context) {
if err := e.pollResources(ctx); err != nil {
log.WithField("environment_id", e.Id).WithField("error", errors.WithStack(err)).Error("error during environment resource polling")
}
}(ctx)
// Stream the reader output to the console which will then fire off events and handle console
// throttling and sending the output to the user.

View File

@ -38,11 +38,14 @@ func (e *Environment) pollResources(ctx context.Context) error {
log.WithField("container_id", e.Id).Warn("encountered error processing docker stats output, stopping collection")
}
log.WithField("container_id", e.Id).Debug("detected io.EOF, stopping resource polling")
return nil
}
// Disable collection if the server is in an offline state and this process is still running.
if e.State() == environment.ProcessOfflineState {
log.WithField("container_id", e.Id).Debug("process in offline state while resource polling is still active; stopping poll")
return nil
}
@ -66,10 +69,13 @@ func (e *Environment) pollResources(ctx context.Context) error {
},
}
b, _ := json.Marshal(st)
if b, err := json.Marshal(st); err != nil {
log.WithField("container_id", e.Id).WithField("error", errors.WithStack(err)).Warn("error while marshaling stats object for environment")
} else {
e.Events().Publish(environment.ResourceEvent, string(b))
}
}
}
}
// The "docker stats" CLI call does not return the same value as the types.MemoryStats.Usage

View File

@ -28,7 +28,7 @@ func (h *Handler) ListenForExpiration(ctx context.Context) {
if jwt != nil {
if jwt.ExpirationTime.Unix()-time.Now().Unix() <= 0 {
_ = h.SendJson(&Message{Event: TokenExpiredEvent})
} else if jwt.ExpirationTime.Unix()-time.Now().Unix() <= 180 {
} else if jwt.ExpirationTime.Unix()-time.Now().Unix() <= 60 {
_ = h.SendJson(&Message{Event: TokenExpiringEvent})
}
}