mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
* fn: introducing lb placer basic metrics This change adds basic metrics to naive and consistent hash LB placers. The stats show how many times we scanned the full runner list, if runner pool failed to return a runner list or if runner pool returned an empty list. Placed and not placed status are also tracked along with if TryExec returned an error or not. Most common error code, Too-Busy is specifically tracked. If client cancels/times out, this is also tracked as a client cancel metric. For placer latency, we would like to know how much time the placer spent on searching for a runner until it successfully places a call. This includes round-trip times for NACK responses from the runners until a successful TryExec() call. By excluding last successful TryExec() latency, we try to exclude function execution & runner container startup time from this metric in an attempt to isolate Placer only latency. * fn: latency and attempt tracker Removing full scan metric. Tracking number of runners attempted is a better metric for this purpose. Also, if rp.Runners() fail, this is an unrecoverable error and we should bail out instead of retrying. * fn: typo fix, ch placer finalize err return * fn: enable LB placer metrics in WithAgentFromEnv if prometheus is enabled
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package runnerpool
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
|
|
"github.com/fnproject/fn/api/models"
|
|
)
|
|
|
|
// Placer implements a placement strategy for calls that are load-balanced
|
|
// across runners in a pool
|
|
type Placer interface {
|
|
PlaceCall(rp RunnerPool, ctx context.Context, call RunnerCall) error
|
|
}
|
|
|
|
// RunnerPool is the abstraction for getting an ordered list of runners to try for a call
|
|
type RunnerPool interface {
|
|
// returns an error for unrecoverable errors that should not be retried
|
|
Runners(call RunnerCall) ([]Runner, error)
|
|
Shutdown(ctx context.Context) error
|
|
}
|
|
|
|
// PKIData encapsulates TLS certificate data
|
|
type PKIData struct {
|
|
Ca string
|
|
Key string
|
|
Cert string
|
|
}
|
|
|
|
// MTLSRunnerFactory represents a factory method for constructing runners using mTLS
|
|
type MTLSRunnerFactory func(addr, certCommonName string, pki *PKIData) (Runner, error)
|
|
|
|
// Runner is the interface to invoke the execution of a function call on a specific runner
|
|
type Runner interface {
|
|
TryExec(ctx context.Context, call RunnerCall) (bool, error)
|
|
Close(ctx context.Context) error
|
|
Address() string
|
|
}
|
|
|
|
// RunnerCall provides access to the necessary details of request in order for it to be
|
|
// processed by a RunnerPool
|
|
type RunnerCall interface {
|
|
SlotHashId() string
|
|
RequestBody() io.ReadCloser
|
|
ResponseWriter() http.ResponseWriter
|
|
StdErr() io.ReadWriteCloser
|
|
Model() *models.Call
|
|
}
|