-
Notifications
You must be signed in to change notification settings - Fork 177
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
Add LastOk to Event (#1034) #1062
Conversation
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.
Hi, thanks for the PR! You are the first community member to submit a PR to sensu-go! 🥂 🥇
The PR looks good to me, but please add a gogoproto tag to the proto definition so that the field name would be LastOK
. (See below)
types/event.proto
Outdated
@@ -35,4 +35,7 @@ message Event { | |||
|
|||
// Hooks describes the results of multiple hooks; if event is associated to hook execution. | |||
repeated Hook hooks = 6 [(gogoproto.nullable) = true]; | |||
|
|||
// LastOk displays last time this check was ok; if event status is 0 this is set to timestamp | |||
int64 last_ok = 7; |
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.
Let's add [(gogoproto.customname) = "LastOK"]
to this field, so that we can get something that fits the Go coding standards. (https://github.com/golang/go/wiki/CodeReviewComments#initialisms)
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.
Yeah I wasn't sure if this follows the ruby name standard last_ok
but went with that since the issue specifies. And the Ok
vs OK
got me too. Thanks
The test failure in travis is unrelated to this change, I'm comfortable with merging instead until we fix the tests. (After addressing PR feedback). |
b5b6198
to
21fb439
Compare
Updated, not too happy about the test I added as I still don't think it does anything. |
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.
Sorry about the confusion. After looking at this, I realized that LastOK was a little out of place.
types/event.proto
Outdated
@@ -35,4 +35,7 @@ message Event { | |||
|
|||
// Hooks describes the results of multiple hooks; if event is associated to hook execution. | |||
repeated Hook hooks = 6 [(gogoproto.nullable) = true]; | |||
|
|||
// LastOK displays last time this check was ok; if event status is 0 this is set to timestamp | |||
int64 last_ok = 7 [(gogoproto.customname) = "LastOK"]; |
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.
In this case, we're looking at the Check's status. We'll want to throw LastOK in here.
backend/eventd/eventd.go
Outdated
@@ -158,6 +158,7 @@ func (e *Eventd) handleMessage(msg interface{}) error { | |||
} | |||
|
|||
event.Check.MergeWith(prevEvent.Check) | |||
event.LastOK = prevEvent.LastOK |
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.
Given that we move LastOK from Event to Check, this will have to change. Also, this isn't the only desired effect we want. If the current event's status is OK, we want to use this event's timestamp as LastOK.
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 part was just the merge from prevEvent
. The current event's LastOK is set in flapping.go
here if status is OK.
This will be the same if we move LastOK
into the check as well. Except this line will go into the MergeWith()
backend/eventd/eventd_test.go
Outdated
@@ -69,6 +69,7 @@ func TestEventHandling(t *testing.T) { | |||
|
|||
// Make sure the event has been marked with the proper state | |||
assert.Equal(t, types.EventPassingState, event.Check.State) | |||
assert.Equal(t, badEvent.Timestamp, event.LastOK) |
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.
We'll want to assert that event.Check.LastOK is equal to event.Timestamp.
Publishing a bad event seems out of place in this test, but I can look into that another time. Line 63 is where we're publishing our event. We want to make sure that eventd is correctly updating the LastOK field with the current timestamp.
We can definitely move the I'm also not familiar with the new architecture so not sure if Event in this project is 1:1 with event in the 1.X version. Thanks for any insight. Edit: After discussion via slack we are moving it into the |
backend/eventd/eventd_test.go
Outdated
@@ -69,6 +70,10 @@ func TestEventHandling(t *testing.T) { | |||
|
|||
// Make sure the event has been marked with the proper state | |||
assert.Equal(t, types.EventPassingState, event.Check.State) | |||
fmt.Printf("Event Timestamp: %d\n", event.Timestamp) | |||
fmt.Printf("Check's LastOK: %d\n", event.Check.LastOK) | |||
fmt.Printf("badEvent Timestamp: %d\n", badEvent.Timestamp) |
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.
@grepory its my understanding that badEvent
should have an older timestamp but it doesn't. IF you pull down this branch and run $ go test ./... -run=TestEventHandling -v
you'll see they are all the same. Even with modifying FixtureCheck
to sleep 5 and print UnixNano()
. Am I missing some mutations somewhere?
This was just extra code I was writing to check if my test was valid or not.
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.
Figured it out!
4bd3afd
to
d9b1ca5
Compare
This should be ready for review again whenever you have time. |
CHANGELOG.md
Outdated
@@ -20,6 +20,7 @@ set when importing legacy settings. | |||
- Configured and enabled etcd autocompaction. | |||
- Add event metrics type, implementing the Sensu Metrics Format. | |||
- Added non-functional selections for resolving and silencing to web ui | |||
- Add LastOk to event type. This will be updated to reflect the last timestamp of a succesful event |
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.
"to check type"
README.md
Outdated
@@ -32,7 +32,7 @@ Otherwise, see the **for non-C++ users** [instructions here.](https://github.com | |||
|
|||
### Quick Start | |||
|
|||
Once you make a change to any `*.proto` file within the **types** package, you will need regenerate the associated `*.pb.go` file. To do so, simply run the [genproto.sh](https://github.com/sensu/sensu-go/blob/master/scripts/genproto.sh) script, which will install all required dependencies and launch the code generation. | |||
Once you make a change to any `*.proto` file within the **types** package, you will need regenerate the associated `*.pb.go` file. To do so, simply run the [genproto.sh](https://github.com/sensu/sensu-go/blob/master/scripts/genproto.sh) script, which will install all required dependencies and launch the code generation (be sure to run the below `./build.sh deps` first though). |
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.
While you're in there. Can you make it "you will need to regenerate the associated"?
Looking into the build failure. |
Great, I'll make that change in the README.md. Do you want me to squash my commits down? |
@zbintliff Yes, please, if you wouldn't mind. I don't mind doing it for you, but I'd appreciate it. :) We only squash-merge. (I should put that in the contributing doc). If you would be so kind as to reword your initial commit message to be "Add LastOK to Check (#1034)" that would also be preferable. |
When a Check's status is 0 set LastOk to the timestamp of the event Signed-off-by: Zach Bintliff <zbintliff@gmail.com>
ca41d12
to
646af2b
Compare
I may have to rebase your branch and re-push, but I'll get this merged for you tonight. I really appreciate your help with this! |
When Event's status is 0 set LastOk to the timestamp of the event
Signed-off-by: Zach Bintliff zbintliff@gmail.com
What is this change?
Add
LastOk
to Event typeWhy is this change necessary?
Provides feature parity with 1.X sensu.
Closes #1034
Does your change need a Changelog entry?
Yes
Do you need clarification on anything?
LastOk
lasts properly persists.Were there any complications while making this change?
Following instructions on updating