Skip to content

Commit

Permalink
Send client and java version to server
Browse files Browse the repository at this point in the history
  • Loading branch information
tellet-q committed Dec 10, 2024
1 parent d71b260 commit 8d4a5be
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ build/
.idea/uiDesigner.xml
.idea/codeStyles/codeStyleConfig.xml
.idea/codeStyles/Project.xml
.idea/inspectionProfiles/Project_Default.xml
*.iws
*.iml
*.ipr
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/io/qdrant/client/QdrantGrpcClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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) {
Expand All @@ -231,6 +250,8 @@ private static ManagedChannel createChannel(
channelBuilder.usePlaintext();
}

channelBuilder.userAgent(userAgent);

return channelBuilder.build();
}
}
Expand Down

0 comments on commit 8d4a5be

Please sign in to comment.