Don Newton | 379ae25 | 2019-04-01 12:17:06 -0400 | [diff] [blame^] | 1 | // Copyright (C) MongoDB, Inc. 2017-present. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | // not use this file except in compliance with the License. You may obtain |
| 5 | // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | |
| 7 | package event |
| 8 | |
| 9 | import ( |
| 10 | "context" |
| 11 | |
| 12 | "github.com/mongodb/mongo-go-driver/bson" |
| 13 | ) |
| 14 | |
| 15 | // CommandStartedEvent represents an event generated when a command is sent to a server. |
| 16 | type CommandStartedEvent struct { |
| 17 | Command bson.Raw |
| 18 | DatabaseName string |
| 19 | CommandName string |
| 20 | RequestID int64 |
| 21 | ConnectionID string |
| 22 | } |
| 23 | |
| 24 | // CommandFinishedEvent represents a generic command finishing. |
| 25 | type CommandFinishedEvent struct { |
| 26 | DurationNanos int64 |
| 27 | CommandName string |
| 28 | RequestID int64 |
| 29 | ConnectionID string |
| 30 | } |
| 31 | |
| 32 | // CommandSucceededEvent represents an event generated when a command's execution succeeds. |
| 33 | type CommandSucceededEvent struct { |
| 34 | CommandFinishedEvent |
| 35 | Reply bson.Raw |
| 36 | } |
| 37 | |
| 38 | // CommandFailedEvent represents an event generated when a command's execution fails. |
| 39 | type CommandFailedEvent struct { |
| 40 | CommandFinishedEvent |
| 41 | Failure string |
| 42 | } |
| 43 | |
| 44 | // CommandMonitor represents a monitor that is triggered for different events. |
| 45 | type CommandMonitor struct { |
| 46 | Started func(context.Context, *CommandStartedEvent) |
| 47 | Succeeded func(context.Context, *CommandSucceededEvent) |
| 48 | Failed func(context.Context, *CommandFailedEvent) |
| 49 | } |