Skip to content

GODRIVER-2085 Add serverConnectionId to command monitoring events #724

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

Merged
merged 7 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions data/command-monitoring/unified/pre-42-server-connection-id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"description": "pre-42-server-connection-id",
"schemaVersion": "1.6",
"runOnRequirements": [
{
"maxServerVersion": "4.0.99"
}
],
"createEntities": [
{
"client": {
"id": "client",
"observeEvents": [
"commandStartedEvent",
"commandSucceededEvent",
"commandFailedEvent"
]
}
},
{
"database": {
"id": "database",
"client": "client",
"databaseName": "server-connection-id-tests"
}
},
{
"collection": {
"id": "collection",
"database": "database",
"collectionName": "coll"
}
}
],
"initialData": [
{
"databaseName": "server-connection-id-tests",
"collectionName": "coll",
"documents": []
}
],
"tests": [
{
"description": "command events do not include server connection id",
"operations": [
{
"name": "insertOne",
"object": "collection",
"arguments": {
"document": {
"x": 1
}
}
},
{
"name": "find",
"object": "collection",
"arguments": {
"filter": {
"$or": true
}
},
"expectError": {
"isError": true
}
}
],
"expectEvents": [
{
"client": "client",
"events": [
{
"commandStartedEvent": {
"commandName": "insert",
"hasServerConnectionId": false
}
},
{
"commandSucceededEvent": {
"commandName": "insert",
"hasServerConnectionId": false
}
},
{
"commandStartedEvent": {
"commandName": "find",
"hasServerConnectionId": false
}
},
{
"commandFailedEvent": {
"commandName": "find",
"hasServerConnectionId": false
}
}
]
}
]
}
]
}
56 changes: 56 additions & 0 deletions data/command-monitoring/unified/pre-42-server-connection-id.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
description: "pre-42-server-connection-id"

schemaVersion: "1.6"

runOnRequirements:
- maxServerVersion: "4.0.99"

createEntities:
- client:
id: &client client
observeEvents:
- commandStartedEvent
- commandSucceededEvent
- commandFailedEvent
- database:
id: &database database
client: *client
databaseName: &databaseName server-connection-id-tests
- collection:
id: &collection collection
database: *database
collectionName: &collectionName coll

initialData:
- databaseName: *databaseName
collectionName: *collectionName
documents: []

tests:
- description: "command events do not include server connection id"
operations:
- name: insertOne
object: *collection
arguments:
document: { x: 1 }
- name: find
object: *collection
arguments:
filter: { $or: true }
expectError:
isError: true
expectEvents:
- client: *client
events:
- commandStartedEvent:
commandName: insert
hasServerConnectionId: false
- commandSucceededEvent:
commandName: insert
hasServerConnectionId: false
- commandStartedEvent:
commandName: find
hasServerConnectionId: false
- commandFailedEvent:
commandName: find
hasServerConnectionId: false
101 changes: 101 additions & 0 deletions data/command-monitoring/unified/server-connection-id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"description": "server-connection-id",
"schemaVersion": "1.6",
"runOnRequirements": [
{
"minServerVersion": "4.2"
}
],
"createEntities": [
{
"client": {
"id": "client",
"observeEvents": [
"commandStartedEvent",
"commandSucceededEvent",
"commandFailedEvent"
]
}
},
{
"database": {
"id": "database",
"client": "client",
"databaseName": "server-connection-id-tests"
}
},
{
"collection": {
"id": "collection",
"database": "database",
"collectionName": "coll"
}
}
],
"initialData": [
{
"databaseName": "server-connection-id-tests",
"collectionName": "coll",
"documents": []
}
],
"tests": [
{
"description": "command events include server connection id",
"operations": [
{
"name": "insertOne",
"object": "collection",
"arguments": {
"document": {
"x": 1
}
}
},
{
"name": "find",
"object": "collection",
"arguments": {
"filter": {
"$or": true
}
},
"expectError": {
"isError": true
}
}
],
"expectEvents": [
{
"client": "client",
"events": [
{
"commandStartedEvent": {
"commandName": "insert",
"hasServerConnectionId": true
}
},
{
"commandSucceededEvent": {
"commandName": "insert",
"hasServerConnectionId": true
}
},
{
"commandStartedEvent": {
"commandName": "find",
"hasServerConnectionId": true
}
},
{
"commandFailedEvent": {
"commandName": "find",
"hasServerConnectionId": true
}
}
]
}
]
}
]
}
56 changes: 56 additions & 0 deletions data/command-monitoring/unified/server-connection-id.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
description: "server-connection-id"

schemaVersion: "1.6"

runOnRequirements:
- minServerVersion: "4.2"

createEntities:
- client:
id: &client client
observeEvents:
- commandStartedEvent
- commandSucceededEvent
- commandFailedEvent
- database:
id: &database database
client: *client
databaseName: &databaseName server-connection-id-tests
- collection:
id: &collection collection
database: *database
collectionName: &collectionName coll

initialData:
- databaseName: *databaseName
collectionName: *collectionName
documents: []

tests:
- description: "command events include server connection id"
operations:
- name: insertOne
object: *collection
arguments:
document: { x: 1 }
- name: find
object: *collection
arguments:
filter: { $or: true }
expectError:
isError: true
expectEvents:
- client: *client
events:
- commandStartedEvent:
commandName: insert
hasServerConnectionId: true
- commandSucceededEvent:
commandName: insert
hasServerConnectionId: true
- commandStartedEvent:
commandName: find
hasServerConnectionId: true
- commandFailedEvent:
commandName: find
hasServerConnectionId: true
6 changes: 6 additions & 0 deletions event/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ type CommandStartedEvent struct {
CommandName string
RequestID int64
ConnectionID string
// ServerConnectionID contains the connection ID from the server of the operation. If the server does not return
// this value (e.g. on MDB < 4.2), it is unset.
ServerConnectionID *int32
// ServiceID contains the ID of the server to which the command was sent if it is running behind a load balancer.
// Otherwise, it is unset.
ServiceID *primitive.ObjectID
Expand All @@ -33,6 +36,9 @@ type CommandFinishedEvent struct {
CommandName string
RequestID int64
ConnectionID string
// ServerConnectionID contains the connection ID from the server of the operation. If the server does not return
// this value (e.g. on MDB < 4.2), it is unset.
ServerConnectionID *int32
// ServiceID contains the ID of the server to which the command was sent if it is running behind a load balancer.
// Otherwise, it is unset.
ServiceID *primitive.ObjectID
Expand Down
6 changes: 6 additions & 0 deletions mongo/integration/mtest/opmsg_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ func (*connection) ID() string {
return "<mock_connection>"
}

// ServerConnectionID returns a fixed identifier for the server connection.
func (*connection) ServerConnectionID() *int32 {
serverConnectionID := int32(42)
return &serverConnectionID
}

// Address returns a fixed address for the connection.
func (*connection) Address() address.Address {
return serverAddress
Expand Down
Loading