-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Implement events logging feature #1256
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
783bb02
Implement events logging feature
e9a7344
Fix missing 'fi' in plugins/20_events/install
f5e213e
Add missing DOKKU_RSYSLOG_FILTER in install script
a858bc8
Double quote $@ array expansions
8e79161
Double quote $@ in plugins/20_events/install too
466670d
Quote `find' statement to prevent word splitting
da3b00a
Get rid of cruft leftover
fb5d3a0
Attempt to fix SC2046
16e4001
Restart rsyslog once installed
69aba06
Handle log rotation
alessio b380bde
Add small test suite for events logging
b24e782
Fix horrible typo
efc55bd
Attempt to fix circleci build failure
alessio 1d4b9a1
Fix test case expected output
alessio 172e71c
Merge branch 'master' into pr-dokku-events
alessio 91c691a
Create dokku's /var/log/dokku/ private namespace
alessio 54ed3c1
Fix double negative statement
alessio 89d1aca
Revert "Fix double negative statement"
alessio 0ed0201
Use d-neg condition to prevent unexpected failures
alessio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| #!/usr/bin/env bash | ||
| set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x | ||
| source "$(dirname $0)/../common/functions" | ||
|
|
||
| PLUGIN_DIR="$(dirname $0)" | ||
|
|
||
| case "$1" in | ||
| events) | ||
| if [[ -f $DOKKU_EVENTS_LOGFILE ]] ; then | ||
| if [[ $2 == "-t" ]]; then | ||
| tail -f $DOKKU_EVENTS_LOGFILE | ||
| else | ||
| tail -n 100 $DOKKU_EVENTS_LOGFILE | ||
| fi | ||
| fi | ||
| ;; | ||
|
|
||
| events:on) | ||
| echo "Enabling dokku events logger" | ||
| [[ -d $DOKKU_ROOT/.dokkurc ]] || mkdir -p $DOKKU_ROOT/.dokkurc | ||
| echo "export DOKKU_EVENTS=1" > $DOKKU_ROOT/.dokkurc/DOKKU_EVENTS | ||
| ;; | ||
|
|
||
| events:off) | ||
| echo "Disabling dokku events logger" | ||
| rm -f $DOKKU_ROOT/.dokkurc/DOKKU_EVENTS | ||
| ;; | ||
|
|
||
| events:list) | ||
| if [[ "$DOKKU_EVENTS" ]]; then | ||
| logged="$(find $PLUGIN_DIR -type l -printf '%f ' | sort)" | ||
| dokku_col_log_info2_quiet "Events currently logged" | ||
| for hook in $logged ; do | ||
| dokku_col_log_msg "$hook" | ||
| done | ||
| else | ||
| dokku_log_warn "Events logger disabled" | ||
| fi | ||
| ;; | ||
|
|
||
| help | events:help) | ||
| cat && cat<<EOF | ||
| events [-t] Show the last events (-t follows) | ||
| events:list List logged events | ||
| events:on Enable events logger | ||
| events:off Disable events logger | ||
| EOF | ||
| ;; | ||
|
|
||
| *) | ||
| exit $DOKKU_NOT_IMPLEMENTED_EXIT | ||
| ;; | ||
|
|
||
| esac | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/usr/bin/env bash | ||
| set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x | ||
| source "$(dirname $0)/../common/functions" | ||
|
|
||
| [[ ! "$DOKKU_EVENTS" ]] || dokku_log_pluginhook_call "$(basename $0)" "$@" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| #!/usr/bin/env bash | ||
| set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x | ||
| source "$(dirname $0)/../common/functions" | ||
|
|
||
| DOKKU_RSYSLOG_FILTER=/etc/rsyslog.d/99-dokku.conf | ||
| DOKKU_LOGROTATE_FILE=/etc/logrotate.d/dokku | ||
|
|
||
| flag_rsyslog_needs_restart=n | ||
|
|
||
| # This can be done unconditionally as mkdir -p | ||
| # exits gracefully if the path already exists | ||
| mkdir -m 775 -p "$DOKKU_LOGS_DIR" | ||
| chown syslog:dokku "$DOKKU_LOGS_DIR" | ||
|
|
||
| if [[ ! -f "$DOKKU_EVENTS_LOGFILE" ]]; then | ||
| touch "$DOKKU_EVENTS_LOGFILE" | ||
| # chown syslog:root might not work on SUSE | ||
| chown syslog:dokku "$DOKKU_EVENTS_LOGFILE" | ||
| chmod 664 "$DOKKU_EVENTS_LOGFILE" | ||
| fi | ||
|
|
||
| if [[ ! -f "$DOKKU_RSYSLOG_FILTER" ]]; then | ||
| cat >"$DOKKU_RSYSLOG_FILTER" <<EOF | ||
| :syslogtag, contains, "dokku" $DOKKU_EVENTS_LOGFILE | ||
| EOF | ||
| flag_rsyslog_needs_restart=y | ||
| fi | ||
|
|
||
| if [[ ! -f "$DOKKU_LOGROTATE_FILE" ]]; then | ||
| cat >"$DOKKU_LOGROTATE_FILE" <<EOF | ||
| $DOKKU_LOGS_DIR/*.log { | ||
| daily | ||
| rotate 7 | ||
| missingok | ||
| notifempty | ||
| su syslog dokku | ||
| compress | ||
| delaycompress | ||
| postrotate | ||
| reload rsyslog >/dev/null 2>&1 || true | ||
| endscript | ||
| create 664 syslog dokku | ||
| } | ||
| EOF | ||
| flag_rsyslog_needs_restart=y | ||
| fi | ||
|
|
||
| if [[ "$flag_rsyslog_needs_restart" == "y" ]]; then | ||
| service rsyslog restart | ||
| fi | ||
|
|
||
| [[ ! "$DOKKU_EVENTS" ]] || dokku_log_pluginhook_call "$(basename $0)" "$@" | ||
|
|
||
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #!/usr/bin/env bats | ||
|
|
||
| load test_helper | ||
|
|
||
| setup() { | ||
| create_app | ||
| } | ||
|
|
||
| teardown() { | ||
| destroy_app | ||
| } | ||
|
|
||
| @test "(events) check conffiles" { | ||
| run bash -c "test -f /etc/logrotate.d/dokku" | ||
| echo "output: "$output | ||
| echo "status: "$status | ||
| assert_success | ||
| run bash -c "test -f /etc/rsyslog.d/99-dokku.conf" | ||
| echo "output: "$output | ||
| echo "status: "$status | ||
| assert_success | ||
| run bash -c "stat -c '%U:%G:%a' /var/log/dokku/" | ||
| echo "output: "$output | ||
| echo "status: "$status | ||
| assert_output "syslog:dokku:775" | ||
| run bash -c "stat -c '%U:%G:%a' /var/log/dokku/events.log" | ||
| echo "output: "$output | ||
| echo "status: "$status | ||
| assert_output "syslog:dokku:664" | ||
| } | ||
|
|
||
| @test "(events) log commands" { | ||
| run dokku events:on | ||
| deploy_app | ||
| run dokku events | ||
| echo "output: "$output | ||
| echo "status: "$status | ||
| assert_success | ||
| run dokku events:off | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This question may be naive, but any reason we're doing a double negative here. More directly why not do this?
EDIT: This would also be consistent with
plugins/20_events/install.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Wed, Jul 1, 2015 at 6:50 PM, Michael Hobbs notifications@github.com wrote:
It's just my personal preference, but if that breaks the code style
I'm more than happy to fix it then.
Alessio Treglia | www.alessiotreglia.com
Debian Developer | alessio@debian.org
Ubuntu Core Developer | quadrispro@ubuntu.com
0416 0004 A827 6E40 BB98 90FB E8A4 8AE5 311D 765A
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, actually due
set -eif $DOKKU_EVENTS is unset the hook would return 1, and that would break the plugins chain, wouldn't it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes 😄