You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ta...@apache.org on 2019/11/13 23:34:31 UTC

[openwhisk-composer] branch master updated: Support setting all limits on conductor and composed actions (#53)

This is an automated email from the ASF dual-hosted git repository.

tardieu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwhisk-composer.git


The following commit(s) were added to refs/heads/master by this push:
     new 221e0dd  Support setting all limits on conductor and composed actions (#53)
221e0dd is described below

commit 221e0dd5513e0b5f1c5bfbd1ce022f3ad0f15681
Author: Olivier Tardieu <ta...@users.noreply.github.com>
AuthorDate: Wed Nov 13 18:34:24 2019 -0500

    Support setting all limits on conductor and composed actions (#53)
---
 bin/deploy.js       | 14 +++++++++++---
 client.js           |  4 ++--
 composer.js         |  5 ++++-
 conductor.js        |  4 ++--
 docs/COMBINATORS.md | 16 +++++++++++++++-
 docs/COMMANDS.md    |  6 +++++-
 6 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/bin/deploy.js b/bin/deploy.js
index 046dace..d0c3eb5 100755
--- a/bin/deploy.js
+++ b/bin/deploy.js
@@ -30,7 +30,7 @@ const path = require('path')
 const argv = minimist(process.argv.slice(2), {
   string: ['apihost', 'auth', 'source', 'annotation', 'annotation-file', 'debug', 'kind'],
   boolean: ['insecure', 'version', 'overwrite'],
-  alias: { auth: 'u', insecure: 'i', version: 'v', annotation: 'a', 'annotation-file': 'A', overwrite: 'w', timeout: 't' }
+  alias: { auth: 'u', insecure: 'i', version: 'v', annotation: 'a', 'annotation-file': 'A', overwrite: 'w', timeout: 't', memory: 'm', logsize: 'l' }
 })
 
 if (argv.version) {
@@ -47,7 +47,9 @@ if (argv._.length !== 2 || path.extname(argv._[1]) !== '.json') {
   console.error('  --apihost HOST                    API HOST')
   console.error('  -i, --insecure                    bypass certificate checking')
   console.error('  --kind KIND                       the KIND of the conductor action runtime')
-  console.error('  -t, --timeout LIMIT               the timeout LIMIT in milliseconds for the conductor action')
+  console.error('  -l, --logsize LIMIT               the maximum log size LIMIT in MB for the conductor action (default 10)')
+  console.error('  -m, --memory LIMIT                the maximum memory LIMIT in MB for the conductor action (default 256)')
+  console.error('  -t, --timeout LIMIT               the timeout LIMIT in milliseconds for the conductor action (default 60000)')
   console.error('  -u, --auth KEY                    authorization KEY')
   console.error('  -v, --version                     output the composer version')
   console.error('  -w, --overwrite                   overwrite actions if already defined')
@@ -94,7 +96,13 @@ try {
 if (typeof argv.timeout !== 'undefined' && typeof argv.timeout !== 'number') {
   throw Error('Timeout must be a number')
 }
-client(options).compositions.deploy(composition, argv.overwrite, argv.debug, argv.kind, argv.timeout)
+if (typeof argv.memory !== 'undefined' && typeof argv.memory !== 'number') {
+  throw Error('Maximum memory must be a number')
+}
+if (typeof argv.logsize !== 'undefined' && typeof argv.logsize !== 'number') {
+  throw Error('Maximum log size must be a number')
+}
+client(options).compositions.deploy(composition, argv.overwrite, argv.debug, argv.kind, argv.timeout, argv.memory, argv.logsize)
   .then(actions => {
     const names = actions.map(action => action.name)
     console.log(`ok: created action${actions.length > 1 ? 's' : ''} ${names}`)
diff --git a/client.js b/client.js
index 27fc471..2d53776 100644
--- a/client.js
+++ b/client.js
@@ -63,8 +63,8 @@ class Compositions {
     this.actions = wsk.actions
   }
 
-  deploy (composition, overwrite, debug, kind, timeout) {
-    const actions = (composition.actions || []).concat(conductor.generate(composition, debug, kind, timeout))
+  deploy (composition, overwrite, debug, kind, timeout, memory, logs) {
+    const actions = (composition.actions || []).concat(conductor.generate(composition, debug, kind, timeout, memory, logs))
     return actions.reduce((promise, action) => promise.then(() => overwrite && this.actions.delete(action).catch(() => { }))
       .then(() => this.actions.create(action)), Promise.resolve())
       .then(() => actions)
diff --git a/composer.js b/composer.js
index 66f500f..76b1965 100644
--- a/composer.js
+++ b/composer.js
@@ -358,7 +358,10 @@ Object.assign(composer, {
       exec = { kind: 'nodejs:default', code: exec }
     }
     const composition = { type: 'action', name, '.combinator': () => combinators.action }
-    if (exec) composition.action = { exec }
+    if (exec) {
+      composition.action = { exec }
+      if (isObject(options.limits)) composition.action.limits = options.limits
+    }
     return new Composition(composition)
   },
 
diff --git a/conductor.js b/conductor.js
index 7d163b9..f72f501 100644
--- a/conductor.js
+++ b/conductor.js
@@ -25,7 +25,7 @@ const { minify } = require('terser')
 const version = require('./package.json').version
 
 // synthesize conductor action code from composition
-function generate ({ name, composition, ast, version: composer, annotations = [] }, debug, kind = 'nodejs:default', timeout = 60000) {
+function generate ({ name, composition, ast, version: composer, annotations = [] }, debug, kind = 'nodejs:default', timeout = 60000, memory = 256, logs = 10) {
   let code = `// generated by composer v${composer} and conductor v${version}\n\nconst composition = ${JSON.stringify(composition, null, 4)}\n\n// do not edit below this point\n\n` +
     minify(`const main=(${main})(composition)`, { output: { max_line_len: 127 } }).code
   if (debug) code = `process.env.DEBUG='${debug}'\n\n` + code
@@ -34,7 +34,7 @@ function generate ({ name, composition, ast, version: composer, annotations = []
     { key: 'composerVersion', value: composer },
     { key: 'conductorVersion', value: version },
     { key: 'provide-api-key', value: true }])
-  return { name, action: { exec: { kind, code }, annotations, limits: { timeout } } }
+  return { name, action: { exec: { kind, code }, annotations, limits: { timeout, memory, logs } } }
 }
 
 module.exports = { generate }
diff --git a/docs/COMBINATORS.md b/docs/COMBINATORS.md
index 336d7cc..1294944 100644
--- a/docs/COMBINATORS.md
+++ b/docs/COMBINATORS.md
@@ -73,6 +73,9 @@ composer.action('hello')
 composer.action('myPackage/myAction')
 composer.action('/whisk.system/utils/echo')
 ```
+
+### Action definition
+
 The optional `options` dictionary makes it possible to provide a definition for
 the action being composed.
 ```javascript
@@ -88,7 +91,6 @@ composer.action('hello', { action: hello })
 // specify the code for the action as a string
 composer.action('hello', { action: "const message = 'hello'; function main() { return { message } }" })
 
-
 // specify the code and runtime for the action
 composer.action('hello', {
     action: {
@@ -108,6 +110,18 @@ Javascript function, or as a file name. Alternatively, a sequence action may be
 defined by providing the list of sequenced actions. The code (specified as a
 string) may be annotated with the kind of the action runtime.
 
+### Limits
+
+If a definition is provided for the action, the `options` dictionary may also
+specify `limits`, for instance:
+```javascript
+composer.action('hello', { filename: 'hello.js', limits: { logs: 1, memory: 128, timeout: 10000 } })
+```
+The `limits` object optionally specifies any combination of:
+- the maximum log size LIMIT in MB for the action,
+- the maximum memory LIMIT in MB for the action,
+- the timeout LIMIT in milliseconds for the action.
+
 ### Environment capture in actions
 
 Javascript functions used to define actions cannot capture any part of their
diff --git a/docs/COMMANDS.md b/docs/COMMANDS.md
index a096aad..7b64e15 100644
--- a/docs/COMMANDS.md
+++ b/docs/COMMANDS.md
@@ -77,7 +77,9 @@ Flags:
   --apihost HOST                    API HOST
   -i, --insecure                    bypass certificate checking
   --kind KIND                       the KIND of the conductor action runtime
-  -t, --timeout LIMIT               the timeout LIMIT in milliseconds for the conductor action
+  -l, --logsize LIMIT               the maximum log size LIMIT in MB for the conductor action (default 10)
+  -m, --memory LIMIT                the maximum memory LIMIT in MB for the conductor action (default 256)
+  -t, --timeout LIMIT               the timeout LIMIT in milliseconds for the conductor action (default 60000)
   -u, --auth KEY                    authorization KEY
   -v, --version                     output the composer version
   -w, --overwrite                   overwrite actions if already defined
@@ -103,6 +105,8 @@ definitions. More precisely, it deletes the deployed actions before recreating
 them. As a result, default parameters, limits, and annotations on preexisting
 actions are lost.
 
+The `--logsize` option specifies the maximum log size for the conductor action.
+The `--memory` option specifies the maximum memory for the conductor action.
 The `--timeout` option specifies the timeout for the conductor action.
 
 The `--kind` option specifies the kind for the conductor action runtime. By