Skip to content

Commit 7308dcb

Browse files
committed
Add an address() method to the builder
1 parent 19ec950 commit 7308dcb

4 files changed

Lines changed: 11 additions & 29 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CHANGELOG
22

3-
## 4.3.0 / 2023.XX.XX
3+
## 4.3.0 / 2024.XX.XX
44

55
* [FEATURE] Add support for `SOCK_STREAM` Unix sockets. See [#228][]
66

README.md

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,12 @@ The client jar is distributed via Maven central, and can be downloaded [from Mav
2323

2424
### Unix Domain Socket support
2525

26-
As an alternative to UDP, Agent v6 can receive metrics via a UNIX Socket (on Linux only). This library supports transmission via this protocol. To use it, pass the socket path as a hostname, and `0` as port
27-
or use the `socket()` method of the builder.
26+
As an alternative to UDP, Agent v6 can receive metrics via a UNIX Socket (on Linux only). This library supports transmission via this protocol. To use it
27+
use the `address()` method of the builder and pass the path to the socket with the `unix://` prefix:
2828

2929
```java
3030
StatsDClient client = new NonBlockingStatsDClientBuilder()
31-
.hostname("/var/run/datadog/dsd.socket")
32-
.port(0) // Necessary for unix socket
33-
.build();
34-
```
35-
36-
or
37-
38-
```java
39-
StatsDClient client = new NonBlockingStatsDClientBuilder()
40-
.socket("/var/run/datadog/dsd.socket")
31+
.address("unix:///var/run/datadog/dsd.socket")
4132
.build();
4233
```
4334

@@ -47,7 +38,7 @@ By default, all exceptions are ignored, mimicking UDP behaviour. When using Unix
4738
- If DogStatsD's reception buffer were to fill up and the non blocking client is used, the send times out after 100ms and throw either a `java.io.IOException: No buffer space available` or a `java.io.IOException: Resource temporarily unavailable`.
4839

4940
The default UDS transport is using `SOCK_DATAGRAM` sockets. We also have experimental support for `SOCK_STREAM` sockets which can
50-
be enabled by using the `socket()` method of the builder. This is not recommended for production use at this time.
41+
be enabled by using the `unixstream://` instead of `unix://`. This is not recommended for production use at this time.
5142

5243
## Configuration
5344

src/main/java/com/timgroup/statsd/NonBlockingStatsDClientBuilder.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,22 +133,13 @@ public NonBlockingStatsDClientBuilder namedPipe(String val) {
133133
return this;
134134
}
135135

136-
private Callable<SocketAddress> socketLookup(final String path, final UnixSocketAddressWithTransport.TransportType transport) {
137-
return new Callable<SocketAddress>() {
138-
@Override
139-
public SocketAddress call() throws Exception {
140-
return new UnixSocketAddressWithTransport(new UnixSocketAddress(path), transport);
141-
}
142-
};
143-
}
144-
145-
public NonBlockingStatsDClientBuilder socket(final String path, final UnixSocketAddressWithTransport.TransportType transport) {
146-
addressLookup = socketLookup(path, transport);
136+
public NonBlockingStatsDClientBuilder address(String address) {
137+
addressLookup = getAddressLookupFromUrl(address);
147138
return this;
148139
}
149140

150-
public NonBlockingStatsDClientBuilder telemetrySocket(final String path, final UnixSocketAddressWithTransport.TransportType transport) {
151-
telemetryAddressLookup = socketLookup(path, transport);
141+
public NonBlockingStatsDClientBuilder telemetryAddress(String address) {
142+
telemetryAddressLookup = getAddressLookupFromUrl(address);
152143
return this;
153144
}
154145

src/test/java/com/timgroup/statsd/UnixStreamSocketTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void start() throws IOException {
4949
server = new UnixStreamSocketDummyStatsDServer(socketFile.toString());
5050

5151
client = new NonBlockingStatsDClientBuilder().prefix("my.prefix")
52-
.socket(socketFile.getPath(), UnixSocketAddressWithTransport.TransportType.UDS_STREAM)
52+
.address("unixstream://" + socketFile.getPath())
5353
.port(0)
5454
.queueSize(1)
5555
.timeout(500) // non-zero timeout to ensure exception triggered if socket buffer full.
@@ -61,7 +61,7 @@ public void start() throws IOException {
6161
.build();
6262

6363
clientAggregate = new NonBlockingStatsDClientBuilder().prefix("my.prefix")
64-
.socket(socketFile.getPath(), UnixSocketAddressWithTransport.TransportType.UDS_STREAM)
64+
.address("unixstream://" + socketFile.getPath())
6565
.port(0)
6666
.queueSize(1)
6767
.timeout(500) // non-zero timeout to ensure exception triggered if socket buffer full.

0 commit comments

Comments
 (0)