Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Tap Pipeline & Dump Context for Debugging #61

Merged
merged 16 commits into from
Oct 8, 2018
Merged

Tap Pipeline & Dump Context for Debugging #61

merged 16 commits into from
Oct 8, 2018

Conversation

trieloff
Copy link
Contributor

@trieloff trieloff commented Oct 2, 2018

This fixes #14 and provides an alternative to #19:

when running in development-mode (i.e. no OpenWhisk in sight), every step of pipeline processing will be dumped in the debug directory. This allows for very fine-grained inspection of the pipeline processing.

The new Pipeline.tap helper function allows the registration of effect-less observers or validators.

@codecov
Copy link

codecov bot commented Oct 2, 2018

Codecov Report

Merging #61 into master will increase coverage by 0.15%.
The diff coverage is 97.95%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #61      +/-   ##
==========================================
+ Coverage   98.08%   98.23%   +0.15%     
==========================================
  Files          23       25       +2     
  Lines         469      509      +40     
  Branches       73       73              
==========================================
+ Hits          460      500      +40     
  Misses          9        9
Impacted Files Coverage Δ
src/defaults/json.pipe.js 100% <100%> (ø) ⬆️
src/defaults/html.pipe.js 100% <100%> (ø) ⬆️
src/utils/is-production.js 100% <100%> (ø)
src/utils/dump-context.js 100% <100%> (ø)
src/pipeline.js 91.17% <92.85%> (+0.85%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0e3e51c...e46b969. Read the comment docs.

README.md Outdated

When run in non-production, i.e. outside an OpenWhisk action, for example in `hlx up`, Pipeline Dumping is enabled. Pipeline Dumping allows developers to easily inspect the `Context` object of each step of the pipeline and can be used to debug pipeline functions and to generate realistic test cases.

Each stage of the pipeline processing will create a file like `$PWD/debug/context_dump_34161BE5KuR0nuFDp/context-2018-9-2-14-18-5.635-step-2.json` inside the `debug` directory. These dumps will be removed when the `node` process ends, so that after stopping `hlx up` the `debug` directory will be clean again. The `-step-n` in the filename indicates the step in the pipeline that has been logged.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pad days,months, and hours. hint: String.padStart(num, char)

@@ -31,8 +33,10 @@ const htmlpipe = (cont, payload, action) => {
action.logger.log('debug', 'Constructing HTML Pipeline');
const pipe = new Pipeline(action);
pipe
.tap(dump).when(() => !production())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have pre, once, post, why not call it each or every ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tap was the name suggested in https://www.amazon.com/dp/B0777JHD5M

const fs = require('fs-extra');

fs.mkdirpSync(path.resolve(process.cwd(), 'debug'));
const dumpdir = tmp.dir({ prefix: 'context_dump_', dir: path.resolve(process.cwd(), 'debug'), unsafeCleanup: true }).then(o => o.path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not put it in logs/debug ?

function dump(context, _, index) {
return Promise.resolve(dumpdir).then((dir) => {
const now = new Date();
const dumppath = path.resolve(dir, `context-${now.getUTCFullYear()}-${now.getUTCMonth()}-${now.getUTCDay()}-${now.getUTCHours()}-${now.getUTCMinutes()}-${now.getUTCSeconds()}.${now.getUTCMilliseconds()}-step-${index}.json`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • pad with 0s.
  • i would make it more compact. remove - inside date/time, eg: 20180923-1434-123

return Promise.resolve(dumpdir).then((dir) => {
const now = new Date();
const dumppath = path.resolve(dir, `context-${now.getUTCFullYear()}-${now.getUTCMonth()}-${now.getUTCDay()}-${now.getUTCHours()}-${now.getUTCMinutes()}-${now.getUTCSeconds()}.${now.getUTCMilliseconds()}-step-${index}.json`);
fs.writeJsonSync(dumppath, context, { spaces: 2 });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use async

*/
function production() {
// eslint-disable-next-line no-underscore-dangle
return !!process.env.__OW_ACTIVATION_ID;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use NODE_ENV ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, what is the purpose of those dumps, if you cannot debug your deployed actions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure NODE_ENV is different in OpenWhisk and Petridish?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, what is the purpose of those dumps, if you cannot debug your deployed actions?

See #61 (diff) the tap is only used when !production, i.e. in Petridish

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to this post (http://heidloff.net/article/how-to-create-docker-actions-openwhisk-bluemix) NODE_ENV isn't forced to production in OpenWhisk, and not reliable.

test/testHTML.js Outdated
assert.equal(res.headers['Surrogate-Key'], 'foobar');

dump({}, {}, -1).then((dir) => {
const outdir = path.resolve(dir, '..');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use path.basename()

@@ -52,6 +52,7 @@
"retext": "^5.0.0",
"retext-smartypants": "^3.0.1",
"snyk": "^1.88.1",
"tmp-promise": "^1.0.5",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tmp-promise is not available on the docker image. suggest to use tmp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docker image will pull in pipeline and its transitive dependencies, so that won't be an issue.

@trieloff trieloff dismissed tripodsan’s stale review October 8, 2018 12:19

All issues addressed, questions answered.

@trieloff trieloff merged commit ca27533 into master Oct 8, 2018
@tripodsan tripodsan deleted the pipeline-tap branch October 9, 2018 00:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide tap function in the pipeline builder to enable in-progress inspection
2 participants