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

user event payload not visible by handler? #54

Closed
justinclayton opened this Issue Nov 1, 2013 · 8 comments

Comments

Projects
None yet
3 participants
@justinclayton
Contributor

justinclayton commented Nov 1, 2013

I feel like I must be doing something wrong, but user event data isn't showing up for me. I am testing in Vagrant with 2 VMs called source and target.

Source looks like this:

[vagrant@source ~]$ serf version
Serf v0.1.1
[vagrant@source ~]$ serf agent -role=source -log-level=debug -bind=192.168.50.100

Target is identical except I'm specifying an event handler:

[vagrant@target ~]$ serf version
Serf v0.1.1
[vagrant@target ~]$ serf agent -event-handler="/vagrant/event.sh" -role=target -log-level=debug -bind=192.168.50.200 

The handler script itself is trivial:

#!/bin/bash

echo
echo "$0 triggered!"
echo
echo "SERF_EVENT is ${SERF_EVENT}"
echo "SERF_SELF_NAME is ${SERF_SELF_NAME}"
echo "SERF_SELF_ROLE is ${SERF_SELF_ROLE}"
echo "SERF_USER_EVENT is ${SERF_USER_EVENT}"
echo
echo "BEGIN event data"
while read line; do
  echo $line
done
echo "END event data"
echo "$0 finished!"
echo

I know the script is reading stdin correctly because I can see the data from the member-join event:

2013/11/01 04:46:45 [INFO] serf: EventMemberJoin: source.serf.dev 192.168.50.100
2013/11/01 04:46:45 [INFO] agent: Received event: member-join
2013/11/01 04:46:45 [DEBUG] Event 'member-join' script output:
/vagrant/event.sh triggered!

SERF_EVENT is member-join
SERF_SELF_NAME is target.serf.dev
SERF_SELF_ROLE is target
SERF_USER_EVENT is

BEGIN event data
source.serf.dev 192.168.50.100 source
END event data
/vagrant/event.sh finished!

But when I fire off my own event:

[vagrant@source vagrant]$ serf event foo bar
...
2013/11/01 04:49:27 Requesting user event send: foo "bar"

I don't see the event data:

2013/11/01 04:49:27 [DEBUG] serf-delegate: messageUserEventType: foo
2013/11/01 04:49:27 [INFO] agent: Received event: user-event: foo
2013/11/01 04:49:27 [DEBUG] Event 'user' script output:
/vagrant/event.sh triggered!

SERF_EVENT is user
SERF_SELF_NAME is target.serf.dev
SERF_SELF_ROLE is target
SERF_USER_EVENT is foo

BEGIN event data
END event data
/vagrant/event.sh finished!

I'm on CentOS 6 x86_64 if it matters. Thanks!

@mitchellh

This comment has been minimized.

Show comment
Hide comment
@mitchellh

mitchellh Nov 1, 2013

Member

I think this is because there is no newline on the end of the payload and the bash read built-in splits on newlines by default.

Member

mitchellh commented Nov 1, 2013

I think this is because there is no newline on the end of the payload and the bash read built-in splits on newlines by default.

@justinclayton

This comment has been minimized.

Show comment
Hide comment
@justinclayton

justinclayton Nov 1, 2013

Contributor

Looks like you're correct:

[vagrant@source vagrant]$ serf event foo "bar
> baz"
2013/11/01 05:06:28 [INFO] agent: Received event: user-event: foo
2013/11/01 05:06:28 [DEBUG] Event 'user' script output:
/vagrant/event.sh triggered!

SERF_EVENT is user
SERF_SELF_NAME is target.serf.dev
SERF_SELF_ROLE is target
SERF_USER_EVENT is foo

BEGIN event data
bar
END event data
/vagrant/event.sh finished!

Should have caught that myself, thanks. In my defense, however, I was pulling together the example event handler script from here and the example user event from here. Perhaps either serf should add a trailing newline for user events since all the other events seem to have them (though I could see scenarios where you may not want that), or the docs should flesh out this behavior a bit more with additional examples. Thoughts?

Contributor

justinclayton commented Nov 1, 2013

Looks like you're correct:

[vagrant@source vagrant]$ serf event foo "bar
> baz"
2013/11/01 05:06:28 [INFO] agent: Received event: user-event: foo
2013/11/01 05:06:28 [DEBUG] Event 'user' script output:
/vagrant/event.sh triggered!

SERF_EVENT is user
SERF_SELF_NAME is target.serf.dev
SERF_SELF_ROLE is target
SERF_USER_EVENT is foo

BEGIN event data
bar
END event data
/vagrant/event.sh finished!

Should have caught that myself, thanks. In my defense, however, I was pulling together the example event handler script from here and the example user event from here. Perhaps either serf should add a trailing newline for user events since all the other events seem to have them (though I could see scenarios where you may not want that), or the docs should flesh out this behavior a bit more with additional examples. Thoughts?

@mitchellh

This comment has been minimized.

Show comment
Hide comment
@mitchellh

mitchellh Nov 1, 2013

Member

I think I should make a note in the docs. Tagged. Thanks!

Member

mitchellh commented Nov 1, 2013

I think I should make a note in the docs. Tagged. Thanks!

@justinclayton

This comment has been minimized.

Show comment
Hide comment
@justinclayton

justinclayton Nov 1, 2013

Contributor

Thanks for your crazy quick response!

Contributor

justinclayton commented Nov 1, 2013

Thanks for your crazy quick response!

@armon

This comment has been minimized.

Show comment
Hide comment
@armon

armon Jan 8, 2014

Member

Fixed in abf697f

Member

armon commented Jan 8, 2014

Fixed in abf697f

@armon armon closed this Jan 8, 2014

@justinclayton

This comment has been minimized.

Show comment
Hide comment
@justinclayton

justinclayton Feb 12, 2014

Contributor

FYI this appears to still be happening in 0.4.1. Below is an example.

Triggering the event:

# serf version
Serf v0.4.1
Agent Protocol: 3 (Understands back to: 1)
# serf event myevent "foo
> bar"
Event 'myevent' dispatched! Coalescing enabled: true

And the output of serf monitor -log-level=debug:

2014/02/12 23:25:32 [INFO] agent: Received event: user-event: myevent
Event Info:
  Coalesce: true
  Event: "user"
  LTime: 9
  Name: "myevent"
  Payload: []byte{0x66, 0x6f, 0x6f, 0xa, 0x62, 0x61, 0x72}
2014/02/12 23:25:32 [DEBUG] Event 'user' script output:
/etc/serf/handlers/myevent.sh triggered!

SERF_EVENT is user
SERF_USER_EVENT is myevent
SERF_USER_LTIME is 9

BEGIN event data
foo
END event data
/etc/serf/handlers/myevent.sh finished!

And the handler script itself:

#!/bin/bash

echo
echo "$0 triggered!"
echo
echo "SERF_EVENT is ${SERF_EVENT}"
echo "SERF_USER_EVENT is ${SERF_USER_EVENT}"
echo "SERF_USER_LTIME is ${SERF_USER_LTIME}"
echo
echo "BEGIN event data"
while read line; do
  echo $line
done
echo "END event data"
echo "$0 finished!"
echo
Contributor

justinclayton commented Feb 12, 2014

FYI this appears to still be happening in 0.4.1. Below is an example.

Triggering the event:

# serf version
Serf v0.4.1
Agent Protocol: 3 (Understands back to: 1)
# serf event myevent "foo
> bar"
Event 'myevent' dispatched! Coalescing enabled: true

And the output of serf monitor -log-level=debug:

2014/02/12 23:25:32 [INFO] agent: Received event: user-event: myevent
Event Info:
  Coalesce: true
  Event: "user"
  LTime: 9
  Name: "myevent"
  Payload: []byte{0x66, 0x6f, 0x6f, 0xa, 0x62, 0x61, 0x72}
2014/02/12 23:25:32 [DEBUG] Event 'user' script output:
/etc/serf/handlers/myevent.sh triggered!

SERF_EVENT is user
SERF_USER_EVENT is myevent
SERF_USER_LTIME is 9

BEGIN event data
foo
END event data
/etc/serf/handlers/myevent.sh finished!

And the handler script itself:

#!/bin/bash

echo
echo "$0 triggered!"
echo
echo "SERF_EVENT is ${SERF_EVENT}"
echo "SERF_USER_EVENT is ${SERF_USER_EVENT}"
echo "SERF_USER_LTIME is ${SERF_USER_LTIME}"
echo
echo "BEGIN event data"
while read line; do
  echo $line
done
echo "END event data"
echo "$0 finished!"
echo
@armon

This comment has been minimized.

Show comment
Hide comment
@armon

armon Feb 13, 2014

Member

This was indeed a regression. Fixed in a07ad67.

Member

armon commented Feb 13, 2014

This was indeed a regression. Fixed in a07ad67.

@justinclayton

This comment has been minimized.

Show comment
Hide comment
@justinclayton

justinclayton Feb 13, 2014

Contributor

Thanks!

Contributor

justinclayton commented Feb 13, 2014

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment