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

Add LastOk to Event (#1034) #1062

Merged
merged 1 commit into from
Feb 23, 2018
Merged

Add LastOk to Event (#1034) #1062

merged 1 commit into from
Feb 23, 2018

Conversation

zbintliff
Copy link
Contributor

@zbintliff zbintliff commented Feb 21, 2018

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 type

Why 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?

  1. First time working with protobuf would appreciate guidance there and if anything looks off
  2. Making sure I merged new and old event correctly so that LastOk lasts properly persists.
  3. The more I look at my testing the more I think it doesn't do anything. So some guidance on how to test would be great.

Were there any complications while making this change?

Following instructions on updating

Copy link
Contributor

@echlebek echlebek left a 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)

@@ -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;
Copy link
Contributor

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)

Copy link
Contributor Author

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

@grepory
Copy link
Contributor

grepory commented Feb 21, 2018

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).

@zbintliff zbintliff force-pushed the feature/lastOk branch 2 times, most recently from b5b6198 to 21fb439 Compare February 21, 2018 23:57
@zbintliff
Copy link
Contributor Author

Updated, not too happy about the test I added as I still don't think it does anything.

Copy link
Contributor

@grepory grepory left a 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.

@@ -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"];
Copy link
Contributor

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.

@@ -158,6 +158,7 @@ func (e *Eventd) handleMessage(msg interface{}) error {
}

event.Check.MergeWith(prevEvent.Check)
event.LastOK = prevEvent.LastOK
Copy link
Contributor

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.

Copy link
Contributor Author

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()

@@ -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)
Copy link
Contributor

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.

@zbintliff
Copy link
Contributor Author

zbintliff commented Feb 22, 2018

We can definitely move the LastOK into the Check, but that will be a departure from where it is in the 1.X version and what the #1034 asked for.

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 Check for better representation.

@@ -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)
Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Figured it out!

@zbintliff zbintliff force-pushed the feature/lastOk branch 3 times, most recently from 4bd3afd to d9b1ca5 Compare February 23, 2018 00:37
@zbintliff
Copy link
Contributor Author

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
Copy link
Contributor

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).
Copy link
Contributor

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"?

@grepory grepory dismissed echlebek’s stale review February 23, 2018 00:57

Changes satisfied.

@grepory
Copy link
Contributor

grepory commented Feb 23, 2018

Looking into the build failure.

@zbintliff
Copy link
Contributor Author

Great, I'll make that change in the README.md. Do you want me to squash my commits down?

@grepory
Copy link
Contributor

grepory commented Feb 23, 2018

@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>
@grepory
Copy link
Contributor

grepory commented Feb 23, 2018

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!

@grepory grepory merged commit 23c0728 into sensu:master Feb 23, 2018
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

Successfully merging this pull request may close these issues.

None yet

5 participants