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

Refactor/monitor #1699

Merged
merged 12 commits into from Jun 22, 2018
Merged

Refactor/monitor #1699

merged 12 commits into from Jun 22, 2018

Conversation

@mercul3s
Copy link
Contributor

@mercul3s mercul3s commented Jun 20, 2018

What is this change?

Adds an etcd backed monitor implementation.

Why is this change necessary?

Closes #1674

Does your change need a Changelog entry?

Maybe not yet? This code is not yet integrated and doesn't change any system behavior. Happy to add one if necessary, or can update the changelog when integrated.

Do you need clarification on anything?

Nope!

Were there any complications while making this change?

This refactor exists alongside the current implementation, and shares some naming. Due to that, there are a few long names for functions or variables that exist in both files that should be changed when we factor out the in-memory monitor.

Have you reviewed and updated the documentation for this change? Is new documentation required?

Nope!

@mercul3s mercul3s requested review from echlebek, cyphus and nikkictl Jun 20, 2018
@mercul3s mercul3s force-pushed the refactor/monitor branch from dd8768d to eca0362 Jun 20, 2018
Copy link
Contributor

@echlebek echlebek left a comment

Looking forward to seeing this replacing this our existing monitor. 💪

// Service is the monitors interface.
type Service interface {
// GetMonitor starts a new monitor.
GetMonitor(ctx context.Context, name string, entity *types.Entity, event *types.Event, ttl int64) error

This comment has been minimized.

@echlebek

echlebek Jun 20, 2018
Contributor

I think we could select a better name than GetMonitor. The method returns an error, so it doesn't actually get a monitor.

What about RefreshMonitor? It seems like the purpose of this method is actually to reset the TTL of a monitor, whether or not it exists.

This comment has been minimized.

@mercul3s

mercul3s Jun 20, 2018
Author Contributor

That sounds reasonable to me.

monitorKeyBuilder = store.NewKeyBuilder(monitorPathPrefix)
)

// EtcdGetter provides access to the etcd client.

This comment has been minimized.

@echlebek

echlebek Jun 20, 2018
Contributor

This appears to be unused

e(err)
}

// EtcdService is an etcd backend monitor service based on leased keys. Each key

This comment has been minimized.

@echlebek

echlebek Jun 20, 2018
Contributor

I think this sentence would be more clear if it were just:

EtcdService is an etcd backend monitor service based on leased keys. Each key
has a watcher that waits for a DELETE or PUT event and calls a handler.
require.NoError(t, err)
response, err := client.Get(context.Background(), monitorPath)
require.NoError(t, err)
fmt.Println("put response in test:", response)

This comment has been minimized.

@echlebek

echlebek Jun 20, 2018
Contributor

Stray Println

This comment has been minimized.

@mercul3s

mercul3s Jun 20, 2018
Author Contributor

🤦‍♀️

This comment has been minimized.

@nikkictl

nikkictl Jun 21, 2018

it happens 🤷‍♀️

assert.EqualValues(t, testMon.key, mon.key)
}

func TestWatchMonDelete(t *testing.T) {

This comment has been minimized.

@echlebek

echlebek Jun 20, 2018
Contributor

Given that these tests don't rely on assertions, they probably would benefit from some comments explaining them.

This comment has been minimized.

@mercul3s

mercul3s Jun 20, 2018
Author Contributor

I knew I was forgetting something.

Copy link

@nikkictl nikkictl left a comment

Excellent test cases.. great work 💯Just those 2 remaining comments and you're good to go 😎

require.NoError(t, err)
response, err := client.Get(context.Background(), monitorPath)
require.NoError(t, err)
fmt.Println("put response in test:", response)

This comment has been minimized.

@nikkictl

nikkictl Jun 21, 2018

it happens 🤷‍♀️

Copy link
Contributor

@echlebek echlebek left a comment

There's a few more doc changes I'd like to see, then SHIP IT 🚢 :shipit: 👍


// Service is the monitors interface.
type Service interface {
// RefreshMonitor starts a new monitor.

This comment has been minimized.

@echlebek

echlebek Jun 21, 2018
Contributor

// RefreshMonitor starts a new monitor or resets an existing monitor

Would that be more accurate?

RefreshMonitor(ctx context.Context, name string, entity *types.Entity, event *types.Event, ttl int64) error
}

// Factory takes an entity and returns a Monitor interface so the

This comment has been minimized.

@echlebek

echlebek Jun 21, 2018
Contributor

The docs should be a little more truthy here :)

HandleFailure(entity *types.Entity, event *types.Event) error
}

type ErrorHandler interface {

This comment has been minimized.

@echlebek

echlebek Jun 21, 2018
Contributor

Needs docs

HandleError(error)
}

// ErrorHandler provides a handler for errors from WatchMon.

This comment has been minimized.

@echlebek

echlebek Jun 21, 2018
Contributor

ErrorHandlerFunc implements ErrorHandler

@nikkictl
Copy link

@nikkictl nikkictl commented Jun 21, 2018

How did "Don't break the build" actually break the build 😆

go : # github.com/sensu/sensu-go/backend/monitor
166At C:\gopath\src\github.com\sensu\sensu-go\build.ps1:215 char:5
167+     go test -timeout=200s -tags=integration $(go list ./... | Select- ...
168+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
169    + CategoryInfo          : NotSpecified: (# github.com/se...backend/monitor:String) [], RemoteException
170    + FullyQualifiedErrorId : NativeCommandError
171 
172backend\monitor\monitors_test.go:98:9: no new variables on left side of :=
mercul3s added 12 commits Jun 13, 2018
Signed-off-by: Mercedes Coyle <mercedes@sensu.io>
Implementation is based on a leased key and watcher per monitor.
GetMonitor either creates a key or extends a ttl, and starts a watch
operation that is set to trigger a handler when a DELETE operation is
called in etcd.

Signed-off-by: Mercedes Coyle <mercedes@sensu.io>
Monitors are based on a leased key in etcd. A watcher waits for a DELETE
event and fires a failure handler when that event is seen. If a key has
a PUT event, its watcher is terminated to avoid multiple watchers on the
same key.

Co-authored by: Mercedes Coyle <mercedes@sensu.io>
Co-authored by: Eric Chlebek eric@sensu.io

Signed-off-by: Mercedes Coyle <mercedes@sensu.io>
Co-authored by: Mercedes Coyle <mercedes@sensu.io>
Co-authored by: Eric Chlebek eric@sensu.io

Signed-off-by: Mercedes Coyle <mercedes@sensu.io>
Tested getMonitor and GetMonitor. Removed TestMonitorsHandleUpdate as it
seemed ineffective.

Signed-off-by: Mercedes Coyle <mercedes@sensu.io>
Added tests to verify GetMonitor creates new monitors and extends TTLs.
Removed transaction for put since we are occasionally modifying the
keys.

Signed-off-by: Mercedes Coyle <mercedes@sensu.io>
Signed-off-by: Mercedes Coyle <mercedes@sensu.io>
Signed-off-by: Mercedes Coyle <mercedes@sensu.io>
Signed-off-by: Mercedes Coyle <mercedes@sensu.io>
Signed-off-by: Mercedes Coyle <mercedes@sensu.io>
Signed-off-by: Mercedes Coyle <mercedes@sensu.io>
Signed-off-by: Mercedes Coyle <mercedes@sensu.io>
@mercul3s mercul3s force-pushed the refactor/monitor branch from acf69de to e259aec Jun 21, 2018
@mercul3s mercul3s merged commit 20d5a39 into master Jun 22, 2018
3 checks passed
3 checks passed
DCO All commits have a DCO sign-off from the author
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@mercul3s mercul3s deleted the refactor/monitor branch Jun 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.