From 8d4a5be8fae17663572ffe00dbaa415833a31766 Mon Sep 17 00:00:00 2001 From: tellet-q Date: Tue, 10 Dec 2024 10:39:49 +0100 Subject: [PATCH 1/3] 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(); } } From 1f55480b6539ef829b53afe5fc991355cd245c10 Mon Sep 17 00:00:00 2001 From: tellet-q Date: Tue, 10 Dec 2024 11:14:35 +0100 Subject: [PATCH 2/3] Set and read X-Client-Version --- build.gradle | 1 + src/main/java/io/qdrant/client/QdrantGrpcClient.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index c7e5fab..6f3ff29 100644 --- a/build.gradle +++ b/build.gradle @@ -74,6 +74,7 @@ jar { // add git revision and commit time to jar manifest jar.manifest.attributes['X-Git-Revision'] = git.head().id jar.manifest.attributes['X-Git-Commit-Time'] = git.head().dateTime.withZoneSameLocal(ZoneOffset.UTC) + jar.manifest.attributes['X-Client-Version'] = project.version git.close() } } diff --git a/src/main/java/io/qdrant/client/QdrantGrpcClient.java b/src/main/java/io/qdrant/client/QdrantGrpcClient.java index 44160f8..7c11f19 100644 --- a/src/main/java/io/qdrant/client/QdrantGrpcClient.java +++ b/src/main/java/io/qdrant/client/QdrantGrpcClient.java @@ -190,7 +190,7 @@ private String getClientVersion() { Manifest manifest = new Manifest(Builder.class.getResourceAsStream("/META-INF/MANIFEST.MF")); Attributes attributes = manifest.getMainAttributes(); - clientVersion = attributes.getValue("X-Qdrant-Version"); + clientVersion = attributes.getValue("X-Client-Version"); } catch (IOException e) { logger.warn("Failed to read client version from manifest", e); } From 4d29575bfc0f94bc5f891aa85b6b0c84e6b7f4b2 Mon Sep 17 00:00:00 2001 From: tellet-q Date: Tue, 10 Dec 2024 12:37:17 +0100 Subject: [PATCH 3/3] Replace with ImplementationVersion --- build.gradle | 2 +- .../io/qdrant/client/QdrantGrpcClient.java | 18 +----------------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index 6f3ff29..46ba1f7 100644 --- a/build.gradle +++ b/build.gradle @@ -74,7 +74,7 @@ jar { // add git revision and commit time to jar manifest jar.manifest.attributes['X-Git-Revision'] = git.head().id jar.manifest.attributes['X-Git-Commit-Time'] = git.head().dateTime.withZoneSameLocal(ZoneOffset.UTC) - jar.manifest.attributes['X-Client-Version'] = project.version + jar.manifest.attributes['Implementation-Version'] = packageVersion git.close() } } diff --git a/src/main/java/io/qdrant/client/QdrantGrpcClient.java b/src/main/java/io/qdrant/client/QdrantGrpcClient.java index 7c11f19..17c3aef 100644 --- a/src/main/java/io/qdrant/client/QdrantGrpcClient.java +++ b/src/main/java/io/qdrant/client/QdrantGrpcClient.java @@ -12,11 +12,8 @@ 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; @@ -177,26 +174,13 @@ public static class Builder { } Builder(String host, int port, boolean useTransportLayerSecurity) { - String clientVersion = getClientVersion(); + String clientVersion = Builder.class.getPackage().getImplementationVersion(); 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-Client-Version"); - } catch (IOException e) { - logger.warn("Failed to read client version from manifest", e); - } - return clientVersion; - } - /** * Sets the API key to use for authentication *