mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
FN_MEMORY, FN_TYPE and precedence for app/route vars
This commit is contained in:
@@ -22,6 +22,8 @@ func TestCallConfigurationRequest(t *testing.T) {
|
|||||||
const timeout = 1
|
const timeout = 1
|
||||||
const idleTimeout = 20
|
const idleTimeout = 20
|
||||||
const memory = 256
|
const memory = 256
|
||||||
|
typ := "sync"
|
||||||
|
format := "default"
|
||||||
|
|
||||||
cfg := models.Config{"APP_VAR": "FOO"}
|
cfg := models.Config{"APP_VAR": "FOO"}
|
||||||
rCfg := models.Config{"ROUTE_VAR": "BAR"}
|
rCfg := models.Config{"ROUTE_VAR": "BAR"}
|
||||||
@@ -36,8 +38,8 @@ func TestCallConfigurationRequest(t *testing.T) {
|
|||||||
Path: path,
|
Path: path,
|
||||||
AppName: appName,
|
AppName: appName,
|
||||||
Image: image,
|
Image: image,
|
||||||
Type: "sync",
|
Type: typ,
|
||||||
Format: "default",
|
Format: format,
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
IdleTimeout: idleTimeout,
|
IdleTimeout: idleTimeout,
|
||||||
Memory: memory,
|
Memory: memory,
|
||||||
@@ -112,12 +114,13 @@ func TestCallConfigurationRequest(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expectedBase := map[string]string{
|
expectedBase := map[string]string{
|
||||||
"FN_FORMAT": "default",
|
"FN_FORMAT": format,
|
||||||
"FN_APP_NAME": appName,
|
"FN_APP_NAME": appName,
|
||||||
"FN_ROUTE": path,
|
"FN_ROUTE": path,
|
||||||
"FN_MEMORY_MB": strconv.Itoa(memory),
|
"FN_MEMORY": strconv.Itoa(memory),
|
||||||
"APP_VAR": "FOO",
|
"FN_TYPE": typ,
|
||||||
"ROUTE_VAR": "BAR",
|
"APP_VAR": "FOO",
|
||||||
|
"ROUTE_VAR": "BAR",
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedEnv := make(map[string]string)
|
expectedEnv := make(map[string]string)
|
||||||
@@ -199,14 +202,17 @@ func TestCallConfigurationModel(t *testing.T) {
|
|||||||
method := "GET"
|
method := "GET"
|
||||||
url := "http://127.0.0.1:8080/r/" + appName + path
|
url := "http://127.0.0.1:8080/r/" + appName + path
|
||||||
payload := "payload"
|
payload := "payload"
|
||||||
|
typ := "sync"
|
||||||
|
format := "default"
|
||||||
env := map[string]string{
|
env := map[string]string{
|
||||||
"FN_FORMAT": "default",
|
"FN_FORMAT": format,
|
||||||
"FN_APP_NAME": appName,
|
"FN_APP_NAME": appName,
|
||||||
"FN_ROUTE": path,
|
"FN_ROUTE": path,
|
||||||
"FN_MEMORY_MB": strconv.Itoa(memory),
|
"FN_MEMORY": strconv.Itoa(memory),
|
||||||
"APP_VAR": "FOO",
|
"FN_TYPE": typ,
|
||||||
"ROUTE_VAR": "BAR",
|
"APP_VAR": "FOO",
|
||||||
"DOUBLE_VAR": "BIZ, BAZ",
|
"ROUTE_VAR": "BAR",
|
||||||
|
"DOUBLE_VAR": "BIZ, BAZ",
|
||||||
}
|
}
|
||||||
|
|
||||||
cm := &models.Call{
|
cm := &models.Call{
|
||||||
@@ -215,8 +221,8 @@ func TestCallConfigurationModel(t *testing.T) {
|
|||||||
AppName: appName,
|
AppName: appName,
|
||||||
Path: path,
|
Path: path,
|
||||||
Image: image,
|
Image: image,
|
||||||
Type: "sync",
|
Type: typ,
|
||||||
Format: "default",
|
Format: format,
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
IdleTimeout: idleTimeout,
|
IdleTimeout: idleTimeout,
|
||||||
Memory: memory,
|
Memory: memory,
|
||||||
|
|||||||
@@ -65,12 +65,8 @@ func FromRequest(appName, path string, req *http.Request) CallOpt {
|
|||||||
|
|
||||||
// baseVars are the vars on the route & app, not on this specific request [for hot functions]
|
// baseVars are the vars on the route & app, not on this specific request [for hot functions]
|
||||||
baseVars := make(map[string]string, len(app.Config)+len(route.Config)+3)
|
baseVars := make(map[string]string, len(app.Config)+len(route.Config)+3)
|
||||||
baseVars["FN_FORMAT"] = route.Format
|
|
||||||
baseVars["FN_APP_NAME"] = appName
|
|
||||||
baseVars["FN_ROUTE"] = route.Path
|
|
||||||
baseVars["FN_MEMORY_MB"] = fmt.Sprintf("%d", route.Memory)
|
|
||||||
|
|
||||||
// app config
|
// add app & route config before our standard additions
|
||||||
for k, v := range app.Config {
|
for k, v := range app.Config {
|
||||||
k = toEnvName("", k)
|
k = toEnvName("", k)
|
||||||
baseVars[k] = v
|
baseVars[k] = v
|
||||||
@@ -80,6 +76,12 @@ func FromRequest(appName, path string, req *http.Request) CallOpt {
|
|||||||
baseVars[k] = v
|
baseVars[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
baseVars["FN_FORMAT"] = route.Format
|
||||||
|
baseVars["FN_APP_NAME"] = appName
|
||||||
|
baseVars["FN_ROUTE"] = route.Path
|
||||||
|
baseVars["FN_MEMORY"] = fmt.Sprintf("%d", route.Memory)
|
||||||
|
baseVars["FN_TYPE"] = route.Type
|
||||||
|
|
||||||
// envVars contains the full set of env vars, per request + base
|
// envVars contains the full set of env vars, per request + base
|
||||||
envVars := make(map[string]string, len(baseVars)+len(params)+len(req.Header)+3)
|
envVars := make(map[string]string, len(baseVars)+len(params)+len(req.Header)+3)
|
||||||
|
|
||||||
@@ -169,6 +171,9 @@ func FromRequest(appName, path string, req *http.Request) CallOpt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO this currently relies on FromRequest having happened before to create the model
|
||||||
|
// here, to be a fully qualified model. We probably should double check but having a way
|
||||||
|
// to bypass will likely be what's used anyway unless forced.
|
||||||
func FromModel(mCall *models.Call) CallOpt {
|
func FromModel(mCall *models.Call) CallOpt {
|
||||||
return func(a *agent, c *call) error {
|
return func(a *agent, c *call) error {
|
||||||
c.Call = mCall
|
c.Call = mCall
|
||||||
|
|||||||
Reference in New Issue
Block a user