fn: runner status and docker load images (#1116)

* fn: runner status and docker load images

Introducing a function run for pure runner Status
calls. Previously, Status gRPC calls returned active
inflight request counts with the purpose of a simple
health checker. However this is not sufficient since
it does not show if agent or docker is healthy. With
this change, if pure runner is configured with a status
image, that image is executed through docker. The
call uses zero memory/cpu/tmpsize settings to ensure
resource tracker does not block it.

However, operators might not always have a docker
repository accessible/available for status image. Or
operators might not want the status to go over the
network. To allow such cases, and in general possibly
caching docker images, added a new environment variable
FN_DOCKER_LOAD_FILE. If this is set, fn-agent during
startup will load these images that were previously
saved with 'docker save' into docker.
This commit is contained in:
Tolga Ceylan
2018-07-12 13:58:38 -07:00
committed by GitHub
parent 62461d93a7
commit 5dc5740a54
26 changed files with 745 additions and 57 deletions

View File

@@ -18,6 +18,8 @@ import (
"github.com/fnproject/fn/api/models"
pool "github.com/fnproject/fn/api/runnerpool"
"github.com/fnproject/fn/grpcutil"
pb_empty "github.com/golang/protobuf/ptypes/empty"
"github.com/sirupsen/logrus"
)
@@ -103,6 +105,44 @@ func isTooBusy(err error) bool {
return false
}
// Translate runner.RunnerStatus to runnerpool.RunnerStatus
func TranslateGRPCStatusToRunnerStatus(status *pb.RunnerStatus) *pool.RunnerStatus {
if status == nil {
return nil
}
creat, _ := common.ParseDateTime(status.CreatedAt)
start, _ := common.ParseDateTime(status.StartedAt)
compl, _ := common.ParseDateTime(status.CompletedAt)
return &pool.RunnerStatus{
ActiveRequestCount: status.Active,
StatusFailed: status.Failed,
StatusId: status.Id,
Details: status.Details,
ErrorCode: status.ErrorCode,
ErrorStr: status.ErrorStr,
CreatedAt: creat,
StartedAt: start,
CompletedAt: compl,
}
}
// implements Runner
func (r *gRPCRunner) Status(ctx context.Context) (*pool.RunnerStatus, error) {
log := common.Logger(ctx).WithField("runner_addr", r.address)
rid := common.RequestIDFromContext(ctx)
if rid != "" {
// Create a new gRPC metadata where we store the request ID
mp := metadata.Pairs(common.RequestIDContextKey, rid)
ctx = metadata.NewOutgoingContext(ctx, mp)
}
status, err := r.client.Status(ctx, &pb_empty.Empty{})
log.WithError(err).Debugf("Status Call %+v", status)
return TranslateGRPCStatusToRunnerStatus(status), err
}
// implements Runner
func (r *gRPCRunner) TryExec(ctx context.Context, call pool.RunnerCall) (bool, error) {
log := common.Logger(ctx).WithField("runner_addr", r.address)