openwhisk-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tard...@apache.org
Subject [openwhisk-composer] 01/01: Support setting all limits on conductor and composed actions
Date Wed, 13 Nov 2019 20:45:48 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 9b168c326190134f15e401fafe139c1e46449354
Author: Olivier Tardieu <tardieu@users.noreply.github.com>
AuthorDate: Wed Nov 13 15:45:06 2019 -0500

    Support setting all limits on conductor and composed actions
---
 bin/deploy.js       | 14 +++++++++++---
 client.js           |  4 ++--
 composer.js         |  5 ++++-
 conductor.js        |  4 ++--
 docs/COMBINATORS.md | 16 +++++++++++++++-
 docs/COMMANDS.md    |  8 ++++++--
 6 files changed, 40 insertions(+), 11 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 74c84bc..242e31a 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 673035c..8f985b9 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,7 +105,9 @@ 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 `--timeout` option specifies the timeout for the conductor action.
+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
 default, the `nodejs:default` OpenWhisk runtime is used. The chosen runtime must


Mime
View raw message