-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved observability into operations (#36)
* Add support for OP_UPDATE, OP_INSERT, OP_DELETE, OP_KILL_CURSORS * Add support for parsing commands/collections from operations * Make operations implement stringer interface for simpler debugging * Move commands to separate file * Add command and collection to error logs and metrics * Add request debugging * Pass tags down * Fix tests * Linting * Fix no response in unacknowledged queries * Fix var naming * Re-add response_op_code tag * Formatting
- Loading branch information
Showing
7 changed files
with
521 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package mongo | ||
|
||
import ( | ||
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore" | ||
) | ||
|
||
type Command string | ||
|
||
const ( | ||
Unknown Command = "unknown" | ||
AbortTransaction Command = "abortTransaction" | ||
Aggregate Command = "aggregate" | ||
CommitTransaction Command = "commandTransaction" | ||
Count Command = "count" | ||
CreateIndexes Command = "createIndexes" | ||
Delete Command = "delete" | ||
Distinct Command = "distinct" | ||
Drop Command = "drop" | ||
DropDatabase Command = "dropDatabase" | ||
DropIndexes Command = "dropIndexes" | ||
EndSessions Command = "endSessions" | ||
Find Command = "find" | ||
FindAndModify Command = "findAndModify" | ||
GetMore Command = "getMore" | ||
Insert Command = "insert" | ||
IsMaster Command = "isMaster" | ||
Ismaster Command = "ismaster" | ||
ListCollections Command = "listCollections" | ||
ListIndexes Command = "listIndexes" | ||
ListDatabases Command = "listDatabases" | ||
MapReduce Command = "mapReduce" | ||
Update Command = "update" | ||
) | ||
|
||
var collectionCommands = []Command{Aggregate, Count, CreateIndexes, Delete, Distinct, Drop, DropIndexes, Find, FindAndModify, Insert, ListIndexes, MapReduce, Update} | ||
var int32Commands = []Command{AbortTransaction, Aggregate, CommitTransaction, DropDatabase, IsMaster, Ismaster, ListCollections, ListDatabases} | ||
var int64Commands = []Command{GetMore} | ||
var arrayCommands = []Command{EndSessions} | ||
|
||
func IsWrite(command Command) bool { | ||
switch command { | ||
case CommitTransaction, CreateIndexes, Delete, Drop, DropIndexes, DropDatabase, FindAndModify, Insert, Update: | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func CommandAndCollection(msg bsoncore.Document) (Command, string) { | ||
for _, s := range collectionCommands { | ||
if coll, ok := msg.Lookup(string(s)).StringValueOK(); ok { | ||
return s, coll | ||
} | ||
} | ||
for _, s := range int32Commands { | ||
value := msg.Lookup(string(s)) | ||
if value.Data != nil { | ||
return s, "" | ||
} | ||
} | ||
for _, s := range int64Commands { | ||
value := msg.Lookup(string(s)) | ||
if value.Data != nil { | ||
return s, "" | ||
} | ||
} | ||
for _, s := range arrayCommands { | ||
value := msg.Lookup(string(s)) | ||
if value.Data != nil { | ||
return s, "" | ||
} | ||
} | ||
return Unknown, "" | ||
} | ||
|
||
func IsIsMasterDoc(doc bsoncore.Document) bool { | ||
isMaster, _ := doc.Lookup(string(IsMaster)).Int32OK() | ||
ismaster, _ := doc.Lookup(string(Ismaster)).Int32OK() | ||
return ismaster+isMaster > 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.