Skip to content

Commit 3099975

Browse files
committed
Make event.CommandMetadata private
GODRIVER-683 Change-Id: Ib6c60388cc76aee5b638aa99b5f0274c9b7b99ef
1 parent 120742f commit 3099975

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

event/monitoring.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,10 @@ package event
88

99
import (
1010
"context"
11-
"time"
1211

1312
"github.com/mongodb/mongo-go-driver/x/bsonx"
1413
)
1514

16-
// CommandMetadata contains metadata about a command sent to the server.
17-
type CommandMetadata struct {
18-
Name string
19-
Time time.Time
20-
}
21-
22-
// CreateMetadata creates metadata for a command.
23-
func CreateMetadata(name string) *CommandMetadata {
24-
return &CommandMetadata{
25-
Name: name,
26-
Time: time.Now(),
27-
}
28-
}
29-
30-
// TimeDifference returns the difference between now and the time a command was sent in nanoseconds.
31-
func (cm *CommandMetadata) TimeDifference() int64 {
32-
t := time.Now()
33-
duration := t.Sub(cm.Time)
34-
return duration.Nanoseconds()
35-
}
36-
3715
// CommandStartedEvent represents an event generated when a command is sent to a server.
3816
type CommandStartedEvent struct {
3917
Command bsonx.Doc
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package connection
2+
3+
import "time"
4+
5+
// commandMetadata contains metadata about a command sent to the server.
6+
type commandMetadata struct {
7+
Name string
8+
Time time.Time
9+
}
10+
11+
// createMetadata creates metadata for a command.
12+
func createMetadata(name string) *commandMetadata {
13+
return &commandMetadata{
14+
Name: name,
15+
Time: time.Now(),
16+
}
17+
}
18+
19+
// TimeDifference returns the difference between now and the time a command was sent in nanoseconds.
20+
func (cm *commandMetadata) TimeDifference() int64 {
21+
t := time.Now()
22+
duration := t.Sub(cm.Time)
23+
return duration.Nanoseconds()
24+
}

x/network/connection/connection.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ type connection struct {
9393
compressor compressor.Compressor // use for compressing messages
9494
// server can compress response with any compressor supported by driver
9595
compressorMap map[wiremessage.CompressorID]compressor.Compressor
96-
commandMap map[int64]*event.CommandMetadata // map for monitoring commands sent to server
96+
commandMap map[int64]*commandMetadata // map for monitoring commands sent to server
9797
dead bool
9898
idleTimeout time.Duration
9999
idleDeadline time.Time
@@ -146,7 +146,7 @@ func New(ctx context.Context, addr address.Address, opts ...Option) (Connection,
146146
conn: nc,
147147
compressBuf: make([]byte, 256),
148148
compressorMap: compressorMap,
149-
commandMap: make(map[int64]*event.CommandMetadata),
149+
commandMap: make(map[int64]*commandMetadata),
150150
addr: addr,
151151
idleTimeout: cfg.idleTimeout,
152152
lifetimeDeadline: lifetimeDeadline,
@@ -441,7 +441,7 @@ func (c *connection) commandStartedEvent(ctx context.Context, wm wiremessage.Wir
441441
return nil
442442
}
443443

444-
c.commandMap[startedEvent.RequestID] = event.CreateMetadata(startedEvent.CommandName)
444+
c.commandMap[startedEvent.RequestID] = createMetadata(startedEvent.CommandName)
445445
return nil
446446
}
447447

0 commit comments

Comments
 (0)