Skip to content

Commit

Permalink
Expose gRPC client on high level client (#27)
Browse files Browse the repository at this point in the history
This commit exposes the low-level gRPC client on the
high level client, for two purposes:

- Allow access to the underlying gRPC channel. This may be useful for capturing properties
  about the channel e.g. the channel authority, for metrics.
- Allow access to the gRPC client to make requests using the low-level gRPC
  client in cases where functionality may not yet be exposed by the higher level client.
  • Loading branch information
russcam authored Apr 15, 2024
1 parent 68729a5 commit 9b202e4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/io/qdrant/client/QdrantClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ public QdrantClient(QdrantGrpcClient grpcClient) {
this.grpcClient = grpcClient;
}

/**
* Gets the low-level gRPC client. This is exposed to
* <ul>
* <li>Allow access to the underlying gRPC channel</li>
* <li>Allow access to the gRPC client to make requests using the low-level gRPC client in cases
* where functionality may not yet be exposed by the higher level client.</li>
* </ul>
* @return The low-level gRPC client
*/
public QdrantGrpcClient grpcClient() {
return grpcClient;
}

/**
* Gets detailed information about the qdrant cluster.
*
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/io/qdrant/client/QdrantGrpcClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ public static Builder newBuilder(String host, int port, boolean useTransportLaye
return new Builder(host, port, useTransportLayerSecurity);
}

/**
* Gets the channel
* @return the channel
*/
public ManagedChannel channel() {
return channel;
}

/**
* Gets the client for qdrant services
* @return a new instance of {@link QdrantFutureStub}
Expand Down
40 changes: 40 additions & 0 deletions src/test/java/io/qdrant/client/QdrantClientTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.qdrant.client;

import io.grpc.Grpc;
import io.grpc.InsecureChannelCredentials;
import io.grpc.ManagedChannel;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.qdrant.QdrantContainer;

@Testcontainers
class QdrantClientTest {

@Container
private static final QdrantContainer QDRANT_CONTAINER = new QdrantContainer(DockerImage.QDRANT_IMAGE);
private QdrantClient client;

@BeforeEach
public void setup() {
ManagedChannel channel = Grpc.newChannelBuilder(
QDRANT_CONTAINER.getGrpcHostAddress(),
InsecureChannelCredentials.create())
.build();
QdrantGrpcClient grpcClient = QdrantGrpcClient.newBuilder(channel, true).build();
client = new QdrantClient(grpcClient);
}

@AfterEach
public void teardown() {
client.close();
}

@Test
void canAccessChannelOnGrpcClient() {
Assertions.assertTrue(client.grpcClient().channel().authority().startsWith("localhost"));
}
}

0 comments on commit 9b202e4

Please sign in to comment.