Skip to content

Commit a5da0d6

Browse files
feat(NODE-4687): Add logging to server selection
1 parent 82a5e60 commit a5da0d6

File tree

1 file changed

+0
-142
lines changed

1 file changed

+0
-142
lines changed

src/sdam/server_selection_events.ts

Lines changed: 0 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +0,0 @@
1-
import { HostAddress } from '.././utils';
2-
import {
3-
SERVER_SELECTION_FAILED,
4-
SERVER_SELECTION_STARTED,
5-
SERVER_SELECTION_SUCCEEDED,
6-
WAITING_FOR_SUITABLE_SERVER
7-
} from '../constants';
8-
import { type ReadPreference } from '../read_preference';
9-
import { type ServerSelector } from './server_selection';
10-
import type { TopologyDescription } from './topology_description';
11-
12-
/**
13-
* The base export class for all logs published from server selection
14-
* @internal
15-
* @category Log Type
16-
*/
17-
export abstract class ServerSelectionEvent {
18-
/** String representation of the selector being used to select the server.
19-
* Defaults to 'custom selector' for application-provided custom selector case.
20-
*/
21-
selector: string | ReadPreference | ServerSelector;
22-
/** The name of the operation for which a server is being selected. */
23-
operation: string;
24-
/** The current topology description. */
25-
topologyDescription: TopologyDescription;
26-
27-
/** @internal */
28-
abstract name:
29-
| typeof SERVER_SELECTION_STARTED
30-
| typeof SERVER_SELECTION_SUCCEEDED
31-
| typeof SERVER_SELECTION_FAILED
32-
| typeof WAITING_FOR_SUITABLE_SERVER;
33-
34-
abstract message: string;
35-
36-
/** @internal */
37-
constructor(
38-
selector: string | ReadPreference | ServerSelector,
39-
topologyDescription: TopologyDescription,
40-
operation: string
41-
) {
42-
this.selector = selector;
43-
this.operation = operation;
44-
this.topologyDescription = topologyDescription;
45-
}
46-
}
47-
48-
/**
49-
* An event published when server selection starts
50-
* @internal
51-
* @category Event
52-
*/
53-
export class ServerSelectionStartedEvent extends ServerSelectionEvent {
54-
/** @internal */
55-
name = SERVER_SELECTION_STARTED;
56-
message = 'Server selection started';
57-
58-
/** @internal */
59-
constructor(
60-
selector: string | ReadPreference | ServerSelector,
61-
topologyDescription: TopologyDescription,
62-
operation: string
63-
) {
64-
super(selector, topologyDescription, operation);
65-
}
66-
}
67-
68-
/**
69-
* An event published when a server selection fails
70-
* @internal
71-
* @category Event
72-
*/
73-
export class ServerSelectionFailedEvent extends ServerSelectionEvent {
74-
/** @internal */
75-
name = SERVER_SELECTION_FAILED;
76-
message = 'Server selection failed';
77-
/** Representation of the error the driver will throw regarding server selection failing. */
78-
failure: Error;
79-
80-
/** @internal */
81-
constructor(
82-
selector: string | ReadPreference | ServerSelector,
83-
topologyDescription: TopologyDescription,
84-
error: Error,
85-
operation: string
86-
) {
87-
super(selector, topologyDescription, operation);
88-
this.failure = error;
89-
}
90-
}
91-
92-
/**
93-
* An event published when server selection succeeds
94-
* @internal
95-
* @category Event
96-
*/
97-
export class ServerSelectionSucceededEvent extends ServerSelectionEvent {
98-
/** @internal */
99-
name = SERVER_SELECTION_SUCCEEDED;
100-
message = 'Server selection succeeded';
101-
/** The hostname, IP address, or Unix domain socket path for the selected server. */
102-
serverHost: string;
103-
/** The port for the selected server. Optional; not present for Unix domain sockets. When the user does not specify a port and the default (27017) is used, the driver SHOULD include it here. */
104-
serverPort: number | undefined;
105-
106-
/** @internal */
107-
constructor(
108-
selector: string | ReadPreference | ServerSelector,
109-
topologyDescription: TopologyDescription,
110-
address: string,
111-
operation: string
112-
) {
113-
super(selector, topologyDescription, operation);
114-
const { host, port } = HostAddress.fromString(address).toHostPort();
115-
this.serverHost = host;
116-
this.serverPort = port;
117-
}
118-
}
119-
120-
/**
121-
* An event published when server selection is waiting for a suitable server to become available
122-
* @internal
123-
* @category Event
124-
*/
125-
export class WaitingForSuitableServerEvent extends ServerSelectionEvent {
126-
/** @internal */
127-
name = WAITING_FOR_SUITABLE_SERVER;
128-
message = 'Waiting for suitable server to become available';
129-
/** The remaining time left until server selection will time out. */
130-
remainingTimeMS: number;
131-
132-
/** @internal */
133-
constructor(
134-
selector: string | ReadPreference | ServerSelector,
135-
topologyDescription: TopologyDescription,
136-
remainingTimeMS: number,
137-
operation: string
138-
) {
139-
super(selector, topologyDescription, operation);
140-
this.remainingTimeMS = remainingTimeMS;
141-
}
142-
}

0 commit comments

Comments
 (0)