-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The address resolver is missing the notion of endpoint which is an in…
…termediary between the resolved address and the socket address the client eventually uses. This forces address resolver implementation to determine which internal endpoint was selected based on the socket address the resolver choose, specially when the client report usage statistics to the resolver. Introduce endpoint in the address resolver, the resolver now does select an endpoint for which a socket address can be determined, metrics can now use the endpoint type to properly report usage statistics.
- Loading branch information
Showing
8 changed files
with
148 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,28 +21,22 @@ | |
import io.vertx.core.http.HttpVersion; | ||
import io.vertx.core.http.StreamPriority; | ||
import io.vertx.core.impl.ContextInternal; | ||
import io.vertx.core.net.SocketAddress; | ||
import io.vertx.core.spi.net.AddressResolver; | ||
import io.vertx.core.net.impl.pool.ConnectionLookup; | ||
import io.vertx.core.streams.WriteStream; | ||
|
||
/** | ||
* Decorates an {@link HttpClientStream} that gathers usage statistics. | ||
* | ||
* @author <a href="mailto:[email protected]">Julien Viet</a> | ||
*/ | ||
class StatisticsGatheringHttpClientStream<S, M> implements HttpClientStream { | ||
class StatisticsGatheringHttpClientStream<M, E> implements HttpClientStream { | ||
|
||
private final HttpClientStream delegate; | ||
private final AddressResolver<S, ?, M> resolver; | ||
private final S state; | ||
private final SocketAddress server; | ||
private M metric; | ||
private final ConnectionLookup<?, E, M> lookup; | ||
|
||
StatisticsGatheringHttpClientStream(HttpClientStream delegate, AddressResolver<S, ?, M> resolver, S state, SocketAddress server) { | ||
StatisticsGatheringHttpClientStream(HttpClientStream delegate, ConnectionLookup<?, E, M> lookup) { | ||
this.delegate = delegate; | ||
this.resolver = resolver; | ||
this.state = state; | ||
this.server = server; | ||
this.lookup = lookup; | ||
} | ||
|
||
@Override | ||
|
@@ -77,17 +71,17 @@ public ContextInternal getContext() { | |
|
||
@Override | ||
public Future<Void> writeHead(HttpRequestHead request, boolean chunked, ByteBuf buf, boolean end, StreamPriority priority, boolean connect) { | ||
metric = resolver.requestBegin(state, server); | ||
lookup.beginRequest(); | ||
if (end) { | ||
resolver.requestEnd(metric); | ||
lookup.endRequest(); | ||
} | ||
return delegate.writeHead(request, chunked, buf, end, priority, connect); | ||
} | ||
|
||
@Override | ||
public Future<Void> writeBuffer(ByteBuf buf, boolean end) { | ||
if (end) { | ||
resolver.requestEnd(metric); | ||
lookup.endRequest(); | ||
} | ||
return delegate.writeBuffer(buf, end); | ||
} | ||
|
@@ -121,7 +115,7 @@ public void unknownFrameHandler(Handler<HttpFrame> handler) { | |
public void headHandler(Handler<HttpResponseHead> handler) { | ||
if (handler != null) { | ||
delegate.headHandler(multimap -> { | ||
resolver.responseBegin(metric); | ||
lookup.beginResponse(); | ||
handler.handle(multimap); | ||
}); | ||
} else { | ||
|
@@ -138,7 +132,7 @@ public void chunkHandler(Handler<Buffer> handler) { | |
public void endHandler(Handler<MultiMap> handler) { | ||
if (handler != null) { | ||
delegate.endHandler(multimap -> { | ||
resolver.responseEnd(metric); | ||
lookup.endResponse(); | ||
handler.handle(multimap); | ||
}); | ||
} else { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/io/vertx/core/net/impl/pool/ConnectionLookup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2011-2023 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
package io.vertx.core.net.impl.pool; | ||
|
||
import io.vertx.core.spi.net.AddressResolver; | ||
|
||
/** | ||
* A connection lookup to the endpoint resolver, provides additional information. | ||
*/ | ||
public class ConnectionLookup<C, E, M> { | ||
|
||
private final AddressResolver<?, ?, M, E> resolver; | ||
private final C connection; | ||
private final E endpoint; | ||
private M metric; | ||
|
||
public ConnectionLookup(C connection, AddressResolver<?, ?, M, E> resolver, E endpoint) { | ||
this.connection = connection; | ||
this.endpoint = endpoint; | ||
this.resolver = resolver; | ||
} | ||
|
||
public C connection() { | ||
return connection; | ||
} | ||
|
||
public void beginRequest() { | ||
metric = resolver.requestBegin(endpoint); | ||
} | ||
|
||
public void endRequest() { | ||
resolver.requestEnd(metric); | ||
} | ||
|
||
public void beginResponse() { | ||
resolver.responseBegin(metric); | ||
} | ||
|
||
public void endResponse() { | ||
resolver.responseEnd(metric); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.