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

GODRIVER-2965 Internalize description package #1621

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 58 additions & 0 deletions event/description.go
@@ -0,0 +1,58 @@
// Copyright (C) MongoDB, Inc. 2024-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

package event

import (
"time"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/address"
"go.mongodb.org/mongo-driver/tag"
)

// ServerDescription contains information about a node in a cluster. This is
// created from hello command responses. If the value of the Kind field is
// LoadBalancer, only the Addr and Kind fields will be set. All other fields
// will be set to the zero value of the field's type.
type ServerDescription struct {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ServerDescription holds data from the handshake, parsed from driverutil.NewDescriptionServer.

Addr address.Address
Arbiters []string
Compression []string // compression methods returned by server
CanonicalAddr address.Address
ElectionID bson.ObjectID
IsCryptd bool
HelloOK bool
Hosts []string
Kind string
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return a string that can be compared to the the enumeration in the experimental description package. E.g:

if strings.ToLower(server.Kind) == strings.ToLower(description.ServerKindMongos.String()) {
    // Do something
}

LastWriteTime time.Time
MaxBatchCount uint32
MaxDocumentSize uint32
MaxMessageSize uint32
MaxWireVersion int32
MinWireVersion int32
Members []address.Address
Passives []string
Passive bool
Primary address.Address
ReadOnly bool
ServiceID *bson.ObjectID // Only set for servers that are deployed behind a load balancer.
SessionTimeoutMinutes *int64
SetName string
SetVersion uint32
Tags tag.Set
TopologyVersionProcessID bson.ObjectID
TopologyVersionCounter int64
}

// TopologyDescription contains information about a MongoDB cluster.
type TopologyDescription struct {
Servers []ServerDescription
SetName string
Kind string
SessionTimeoutMinutes *int64
CompatibilityErr error
}
11 changes: 5 additions & 6 deletions event/monitoring.go
Expand Up @@ -12,7 +12,6 @@ import (

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/address"
"go.mongodb.org/mongo-driver/mongo/description"
)

// CommandStartedEvent represents an event generated when a command is sent to a server.
Expand Down Expand Up @@ -120,8 +119,8 @@ type PoolMonitor struct {
type ServerDescriptionChangedEvent struct {
Address address.Address
TopologyID bson.ObjectID // A unique identifier for the topology this server is a part of
PreviousDescription description.Server
NewDescription description.Server
PreviousDescription ServerDescription
NewDescription ServerDescription
}

// ServerOpeningEvent is an event generated when the server is initialized.
Expand All @@ -139,8 +138,8 @@ type ServerClosedEvent struct {
// TopologyDescriptionChangedEvent represents a topology description change.
type TopologyDescriptionChangedEvent struct {
TopologyID bson.ObjectID // A unique identifier for the topology this server is a part of
PreviousDescription description.Topology
NewDescription description.Topology
PreviousDescription TopologyDescription
NewDescription TopologyDescription
}

// TopologyOpeningEvent is an event generated when the topology is initialized.
Expand All @@ -162,7 +161,7 @@ type ServerHeartbeatStartedEvent struct {
// ServerHeartbeatSucceededEvent is an event generated when the heartbeat succeeds.
type ServerHeartbeatSucceededEvent struct {
Duration time.Duration
Reply description.Server
Reply ServerDescription
ConnectionID string // The address this heartbeat was sent to with a unique identifier
Awaited bool // If this heartbeat was awaitable
}
Expand Down