From 8d4a5be8fae17663572ffe00dbaa415833a31766 Mon Sep 17 00:00:00 2001 From: tellet-q Date: Tue, 10 Dec 2024 10:39:49 +0100 Subject: [PATCH] Send client and java version to server --- .gitignore | 1 + .../io/qdrant/client/QdrantGrpcClient.java | 25 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 761f16b..c6509f6 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ build/ .idea/uiDesigner.xml .idea/codeStyles/codeStyleConfig.xml .idea/codeStyles/Project.xml +.idea/inspectionProfiles/Project_Default.xml *.iws *.iml *.ipr diff --git a/src/main/java/io/qdrant/client/QdrantGrpcClient.java b/src/main/java/io/qdrant/client/QdrantGrpcClient.java index bc24a29..44160f8 100644 --- a/src/main/java/io/qdrant/client/QdrantGrpcClient.java +++ b/src/main/java/io/qdrant/client/QdrantGrpcClient.java @@ -12,8 +12,11 @@ import io.qdrant.client.grpc.QdrantGrpc.QdrantFutureStub; import io.qdrant.client.grpc.SnapshotsGrpc; import io.qdrant.client.grpc.SnapshotsGrpc.SnapshotsFutureStub; +import java.io.IOException; import java.time.Duration; import java.util.concurrent.TimeUnit; +import java.util.jar.Attributes; +import java.util.jar.Manifest; import javax.annotation.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -174,10 +177,26 @@ public static class Builder { } Builder(String host, int port, boolean useTransportLayerSecurity) { - this.channel = createChannel(host, port, useTransportLayerSecurity); + String clientVersion = getClientVersion(); + String javaVersion = System.getProperty("java.version"); + String userAgent = "java-client/" + clientVersion + " java/" + javaVersion; + this.channel = createChannel(host, port, useTransportLayerSecurity, userAgent); this.shutdownChannelOnClose = true; } + private String getClientVersion() { + String clientVersion = "Unknown"; + try { + Manifest manifest = + new Manifest(Builder.class.getResourceAsStream("/META-INF/MANIFEST.MF")); + Attributes attributes = manifest.getMainAttributes(); + clientVersion = attributes.getValue("X-Qdrant-Version"); + } catch (IOException e) { + logger.warn("Failed to read client version from manifest", e); + } + return clientVersion; + } + /** * Sets the API key to use for authentication * @@ -222,7 +241,7 @@ public QdrantGrpcClient build() { } private static ManagedChannel createChannel( - String host, int port, boolean useTransportLayerSecurity) { + String host, int port, boolean useTransportLayerSecurity, String userAgent) { ManagedChannelBuilder channelBuilder = ManagedChannelBuilder.forAddress(host, port); if (useTransportLayerSecurity) { @@ -231,6 +250,8 @@ private static ManagedChannel createChannel( channelBuilder.usePlaintext(); } + channelBuilder.userAgent(userAgent); + return channelBuilder.build(); } }