Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions core/src/main/java/tech/ydb/core/grpc/GrpcTransportBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public enum InitMode {
private final List<Consumer<? super ManagedChannelBuilder<?>>> channelInitializers = new ArrayList<>();
private Supplier<ScheduledExecutorService> schedulerFactory = YdbSchedulerFactory::createScheduler;
private String localDc;
private String buildInfo = Version.getVersion().map(version -> "ydb-java-sdk/" + version)
.orElse(Version.UNKNOWN_VERSION);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Этот orElse на ошибку getVersion()? Тогда, может, надо так?
.orElse("ydb-java-sdk/" + Version.UNKNOWN_VERSION);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну я оставил как было. Эта ветка по идее никогда не срабатывает, но можно и слетать проверку


private BalancingSettings balancingSettings;
private Executor callExecutor = MoreExecutors.directExecutor();
private AuthRpcProvider<? super GrpcAuthRpc> authProvider = NopAuthProvider.INSTANCE;
Expand Down Expand Up @@ -124,10 +127,13 @@ public String getDatabase() {
return database;
}

@Deprecated
public String getVersionString() {
return Version.getVersion()
.map(version -> "ydb-java-sdk/" + version)
.orElse(Version.UNKNOWN_VERSION);
Comment thread
alex268 marked this conversation as resolved.
return getBuildInfo();
}

public String getBuildInfo() {
return buildInfo;
}

public String getApplicationName() {
Expand Down Expand Up @@ -423,6 +429,21 @@ public GrpcTransportBuilder withTracer(Tracer tracer) {
return this;
}

/**
* Appends an extra build info string to the SDK build info reported to the server via the
* {@code x-ydb-sdk-build-info} header. The provided value is concatenated to the existing build info using
* a semicolon separator and is typically used to identify higher-level libraries or integrations built on top
* of the SDK (for example, {@code "ydb-jdbc-driver/2.4.0"}).
*
* @param extraBuildInfo additional build info to append to the SDK build info
* @return this builder instance
Comment thread
alex268 marked this conversation as resolved.
*/
public GrpcTransportBuilder withExtraBuildInfo(String extraBuildInfo) {
Objects.requireNonNull(extraBuildInfo, "extraBuildInfo is null");
this.buildInfo = this.buildInfo + ";" + extraBuildInfo;
return this;
}

/**
* use {@link GrpcTransportBuilder#withGrpcRetry(boolean) } instead
* @return this
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/tech/ydb/core/grpc/YdbHeaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private YdbHeaders() { }
public static ClientInterceptor createMetadataInterceptor(GrpcTransportBuilder builder) {
Metadata extraHeaders = new Metadata();
extraHeaders.put(YdbHeaders.DATABASE, builder.getDatabase());
extraHeaders.put(YdbHeaders.BUILD_INFO, builder.getVersionString());
extraHeaders.put(YdbHeaders.BUILD_INFO, builder.getBuildInfo());
String appName = builder.getApplicationName();
if (appName != null) {
extraHeaders.put(YdbHeaders.APPLICATION_NAME, appName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@ public void customHeadersTest() {
Assert.assertEquals("client-hostname", metadata.get(YdbHeaders.CLIENT_PROCESS_ID));
}

@Test
public void customBuildInfoTest() {
GrpcTransportBuilder builder = GrpcTransport.forHost(MOCKED_HOST, MOCKED_PORT, "/Root")
.withExtraBuildInfo("driver/1.0.0")
.withExtraBuildInfo("test-app/1.0.0");
ManagedChannelFactory factory = ChannelFactoryLoader.load().buildFactory(builder);

Assert.assertSame(channelMock, factory.newManagedChannel(MOCKED_HOST, MOCKED_PORT, null));
channelStaticMock.verify(FOR_ADDRESS, Mockito.times(1));

String version = "ydb-java-sdk/" + Version.getVersion().get();
Metadata metadata = metadataCapture.getValue();
Assert.assertEquals(version + ";driver/1.0.0;test-app/1.0.0", metadata.get(YdbHeaders.BUILD_INFO));
}

@Test
public void customChannelInitializer() {
GrpcTransportBuilder builder = GrpcTransport.forHost(MOCKED_HOST, MOCKED_PORT, "/Root")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import tech.ydb.core.UnexpectedResultException;
import tech.ydb.core.grpc.BalancingSettings;
import tech.ydb.core.grpc.GrpcRequestSettings;
import tech.ydb.core.timer.TestTicker;

/**
* @author Aleksandr Gorshenin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.junit.Test;

import tech.ydb.core.grpc.BalancingSettings;
import tech.ydb.core.timer.TestTicker;

/**
* @author Kirill
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.ydb.core.timer;
package tech.ydb.core.impl.pool;

import java.util.Arrays;
import java.util.Iterator;
Expand Down