Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dogwrap: Trim output #91

Closed
gnarf opened this issue Oct 15, 2015 · 4 comments
Closed

dogwrap: Trim output #91

gnarf opened this issue Oct 15, 2015 · 4 comments

Comments

@gnarf
Copy link
Contributor

gnarf commented Oct 15, 2015

When a command has output that makes the message exceed the 4000 character limit for events, the formating gets completely lost and so does the notifications that are appended ( #88 )

There should probably be a strategy in place to trim the output to something that fits in an event. I'd suggest it be configurable.

Total size of the event can not be > 4000 characters, so a few different strategies make sense to me

  • tail - Show only the last ~3500 characters (4k - however many bytes are used in headers/notifications/etc), for when the commands output really only matters what comes at the end
  • head - show only the first ~3500 characters (^^^), for when the start of the command is really all that matters
  • both (default?)- Take ~1000 from the top and ~2500 from the bottom with a ...trimmed... in the middle, the first 1/3rd of the budget on the top, and the other 2 thirds on the bottom.

screenshot 2015-10-15 11 47 32

@yannmh
Copy link
Member

yannmh commented Oct 19, 2015

Thanks a lot for the detailed explanations @gnarf !

I like the idea of making the 'trim' strategy configurable. I reckon 'head' should probably be the default behavior.

We'll work on it for the next version 🚀

@gnarf
Copy link
Contributor Author

gnarf commented Oct 20, 2015

Considering the errors are USUALLY at the bottom when there are errors, I
like the one that mixes a bit of head and a bit of tail best

On Mon, Oct 19, 2015 at 6:55 PM, Yann notifications@github.com wrote:

Thanks a lot for the detailed explanations @gnarf
https://github.com/gnarf !

I like the idea of making the 'trim' strategy configurable. I reckon
'head' should probably be the default behavior.

We'll work on it for the next version [image: 🚀]


Reply to this email directly or view it on GitHub
#91 (comment).

@yannmh
Copy link
Member

yannmh commented Oct 20, 2015

You make a point, the third option sounds more reasonable.
Thanks again @gnarf.

@gnarf
Copy link
Contributor Author

gnarf commented Oct 20, 2015

This code is like really quick and dirty, but this is what I implemented in my own node.js script (if it helps at all)

Note: output contains stderr + stdout

module.exports = function(err, event) {
  var text = "%%%\nExit Code: " + event.exit + " Time: " + (event.time/1000).toFixed(3) + "s\n";

  var payload_text_limit = 4000;

  if (event.output.length > (payload_text_limit - text.length - 100) ) {
    text += 'Start:\n```\n';
    var lines = event.output.split('\n');
    while (text.length < (payload_text_limit / 3)) {
      text += lines.shift() + '\n';
    }
    text += '```\n';
    text += '...trimmed...\n';
    text += '```\n';

    var ending = '```\n';
    while ((ending.length + text.length + lines[lines.length-1].length + 1) < payload_text_limit) {
      ending = lines.pop() + '\n' + ending;
    }
    text += ending;
  } else {
    text += 'Output:\n```\n' + event.output + '\n```\n';
  }

  var properties = {
    tags: [ '#deploy:' + event.eventData.owner + '/' + event.eventData.repo, '#env:{{ deploy_env }}' ],
    host: os.hostname(),
    alert_type: event.exit ? 'error' : 'success',
    date_happened: event.start,
    source_type_name: 'deploy',
  };
  dogapi.event.create("[" + os.hostname() + "] deploy " + event.filename, text, properties);
};

I'm not proud of the readability or methods this thing uses, but hey - it works ;)

yannmh added a commit that referenced this issue Nov 17, 2015
**Changes**
* New event body format:
```
	>>>> CMD <<<<
	>>>> EXIT CODE <<<<
	>>>> STDOUT <<<<
	>>>> STDERR <<<<
	>>>> NOTIFICATIONS <<<<
```
* Trim output to not exceed `MAX_EVENT_BODY_LENGTH` size
  * Keep the first 1/3rd of the budget on the top,
    and the other 2 thirds on the bottom.

Fix #91
Thanks @gnarf !
yannmh added a commit that referenced this issue Nov 17, 2015
**Changes**
* New event body format:
```
	>>>> CMD <<<<
	>>>> EXIT CODE <<<<
	>>>> STDOUT <<<<
	>>>> STDERR <<<<
	>>>> NOTIFICATIONS <<<<
```
* Trim output to not exceed `MAX_EVENT_BODY_LENGTH` size
  * Keep the first 1/3rd of the budget on the top,
    and the other 2 thirds on the bottom.

Fix #91
Thanks @gnarf !
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants