mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
possible breakages: * `FN_HEADER` on cold are no longer `s/-/_/` -- this is so that cold functions can rebuild the headers as they were when they came in on the request (fdks, specifically), there's no guarantee that a reversal `s/_/-/` is the original header on the request. * app and route config no longer `s/-/_/` -- it seemed really weird to rewrite the users config vars on these. should just pass them exactly as is to env. * headers no longer contain the environment vars (previously, base config; app config, route config, `FN_PATH`, etc.), these are still available in the environment. this gets rid of a lot of the code around headers, specifically the stuff that shoved everything into headers when constructing a call to begin with. now we just store the headers separately and add a few things, like FN_CALL_ID to them, and build a separate 'config' now to store on the call. I thought 'config' was more aptly named, 'env' was confusing, though now 'config' is exactly what 'base_vars' was, which is only the things being put into the env. we weren't storing this field in the db, this doesn't break unless there are messages in a queue from another version, anyway, don't think we're there and don't expect any breakage for anybody with field name changes. this makes the configuration stuff pretty straight forward, there's just two separate buckets of things, and cold just needs to mash them together into the env, and otherwise hot containers just need to put 'config' in the env, and then hot format can shove 'headers' in however they'd like. this seems better than my last idea about making this easier but worse (RIP). this means: * headers no longer contain all vars, the set of base vars can only be found in the environment. * headers is only the headers from request + call_id, deadline, method, url * for cold, we simply add the headers to the environment, prepending `FN_HEADER_` to them, BUT NOT upper casing or `s/-/_/` * fixes issue where async hot functions would end up with `Fn_header_` prefixed headers * removes idea of 'base' vars and 'env'. this was a strange concept. now we just have 'config' which was base vars, and headers, which was base_env+headers; i.e. they are disjoint now. * casing for all headers will lean to be `My-Header` style, which should help with consistency. notable exceptions for cold only are FN_CALL_ID, FN_METHOD, and FN_REQUEST_URL -- this is simply to avoid breakage, in either hot format they appear as `Fn_call_id` still. * removes FN_PARAM stuff * updated doc with behavior weird things left: `Fn_call_id` e.g. isn't a correctly formatted http header, it should likely be `Fn-Call-Id` but I wanted to live to fight another day on this one, it would add some breakage. examples to be posted of each format below closes #329
152 lines
5.2 KiB
Go
152 lines
5.2 KiB
Go
package models
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/fnproject/fn/api/agent/drivers"
|
|
"github.com/go-openapi/strfmt"
|
|
)
|
|
|
|
const (
|
|
// TypeNone ...
|
|
TypeNone = ""
|
|
// TypeSync ...
|
|
TypeSync = "sync"
|
|
// TypeAsync ...
|
|
TypeAsync = "async"
|
|
)
|
|
|
|
const (
|
|
// FormatDefault ...
|
|
FormatDefault = "default"
|
|
// FormatHTTP ...
|
|
FormatHTTP = "http"
|
|
// FormatJSON ...
|
|
FormatJSON = "json"
|
|
)
|
|
|
|
var possibleStatuses = [...]string{"delayed", "queued", "running", "success", "error", "cancelled"}
|
|
|
|
type CallLog struct {
|
|
CallID string `json:"call_id" db:"id"`
|
|
Log string `json:"log" db:"log"`
|
|
AppName string `json:"app_name" db:"app_name"`
|
|
}
|
|
|
|
// Call is a representation of a specific invocation of a route.
|
|
type Call struct {
|
|
// Unique identifier representing a specific call.
|
|
ID string `json:"id" db:"id"`
|
|
|
|
// NOTE: this is stale, retries are not implemented atm, but this is nice, so leaving
|
|
// States and valid transitions.
|
|
//
|
|
// +---------+
|
|
// +---------> delayed <----------------+
|
|
// +----+----+ |
|
|
// | |
|
|
// | |
|
|
// +----v----+ |
|
|
// +---------> queued <----------------+
|
|
// +----+----+ *
|
|
// | *
|
|
// | retry * creates new call
|
|
// +----v----+ *
|
|
// | running | *
|
|
// +--+-+-+--+ |
|
|
// +---------|-|-|-----+-------------+
|
|
// +---|---------+ | +-----|---------+ |
|
|
// | | | | | |
|
|
// +-----v---^-+ +--v-------^+ +--v---^-+
|
|
// | success | | cancelled | | error |
|
|
// +-----------+ +-----------+ +--------+
|
|
//
|
|
// * delayed - has a delay.
|
|
// * queued - Ready to be consumed when it's turn comes.
|
|
// * running - Currently consumed by a runner which will attempt to process it.
|
|
// * success - (or complete? success/error is common javascript terminology)
|
|
// * error - Something went wrong. In this case more information can be obtained
|
|
// by inspecting the "reason" field.
|
|
// - timeout
|
|
// - killed - forcibly killed by worker due to resource restrictions or access
|
|
// violations.
|
|
// - bad_exit - exited with non-zero status due to program termination/crash.
|
|
// * cancelled - cancelled via API. More information in the reason field.
|
|
// - client_request - Request was cancelled by a client.
|
|
Status string `json:"status" db:"status"`
|
|
|
|
// App this call belongs to.
|
|
AppName string `json:"app_name" db:"app_name"`
|
|
|
|
// Path of the route that is responsible for this call
|
|
Path string `json:"path" db:"path"`
|
|
|
|
// Name of Docker image to use.
|
|
Image string `json:"image,omitempty" db:"-"`
|
|
|
|
// Number of seconds to wait before queueing the call for consumption for the
|
|
// first time. Must be a positive integer. Calls with a delay start in state
|
|
// "delayed" and transition to "running" after delay seconds.
|
|
Delay int32 `json:"delay,omitempty" db:"-"`
|
|
|
|
// Type indicates whether a task is to be run synchronously or asynchronously.
|
|
Type string `json:"type,omitempty" db:"-"`
|
|
|
|
// Format is the format to pass input into the function.
|
|
Format string `json:"format,omitempty" db:"-"`
|
|
|
|
// Payload for the call. This is only used by async calls, to store their input.
|
|
// TODO should we copy it into here too for debugging sync?
|
|
Payload string `json:"payload,omitempty" db:"-"`
|
|
|
|
// Full request url that spawned this invocation.
|
|
URL string `json:"url,omitempty" db:"-"`
|
|
|
|
// Method of the http request used to make this call.
|
|
Method string `json:"method,omitempty" db:"-"`
|
|
|
|
// Priority of the call. Higher has more priority. 3 levels from 0-2. Calls
|
|
// at same priority are processed in FIFO order.
|
|
Priority *int32 `json:"priority,omitempty" db:"-"`
|
|
|
|
// Maximum runtime in seconds.
|
|
Timeout int32 `json:"timeout,omitempty" db:"-"`
|
|
|
|
// Hot function idle timeout in seconds before termination.
|
|
IdleTimeout int32 `json:"idle_timeout,omitempty" db:"-"`
|
|
|
|
// Memory is the amount of RAM this call is allocated.
|
|
Memory uint64 `json:"memory,omitempty" db:"-"`
|
|
|
|
// Config is the set of configuration variables for the call
|
|
Config Config `json:"config,omitempty" db:"-"`
|
|
|
|
// Headers are headers from the request that created this call
|
|
Headers http.Header `json:"headers,omitempty" db:"-"`
|
|
|
|
// Time when call completed, whether it was successul or failed. Always in UTC.
|
|
CompletedAt strfmt.DateTime `json:"completed_at,omitempty" db:"completed_at"`
|
|
|
|
// Time when call was submitted. Always in UTC.
|
|
CreatedAt strfmt.DateTime `json:"created_at,omitempty" db:"created_at"`
|
|
|
|
// Time when call started execution. Always in UTC.
|
|
StartedAt strfmt.DateTime `json:"started_at,omitempty" db:"started_at"`
|
|
|
|
// Stats is a list of metrics from this call's execution, possibly empty.
|
|
Stats drivers.Stats `json:"stats,omitempty" db:"stats"`
|
|
|
|
// Error is the reason why the call failed, it is only non-empty if
|
|
// status is equal to "error".
|
|
Error string `json:"error,omitempty" db:"error"`
|
|
}
|
|
|
|
type CallFilter struct {
|
|
Path string // match
|
|
AppName string // match
|
|
FromTime strfmt.DateTime
|
|
ToTime strfmt.DateTime
|
|
Cursor string
|
|
PerPage int
|
|
}
|