Search in sources :

Example 11 with Builder

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable by googleapis.

the class BigtableBatchingCallSettingsTest method testEmptyBuilder.

@Test
public void testEmptyBuilder() {
    BigtableBatchingCallSettings.Builder builder = BigtableBatchingCallSettings.newBuilder(new MutateRowsBatchingDescriptor());
    assertThat(builder.getBatchingSettings()).isNull();
    assertThat(builder.getRetryableCodes()).isEmpty();
    assertThat(builder.getRetrySettings()).isNotNull();
    assertThat(builder.isLatencyBasedThrottlingEnabled()).isFalse();
    assertThat(builder.getTargetRpcLatencyMs()).isNull();
    assertThat(builder.getDynamicFlowControlSettings()).isNull();
}
Also used : MutateRowsBatchingDescriptor(com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor) Test(org.junit.Test)

Example 12 with Builder

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable by googleapis.

the class BigtableBatchingCallSettingsTest method testBuilder.

@Test
public void testBuilder() {
    BigtableBatchingCallSettings.Builder builder = BigtableBatchingCallSettings.newBuilder(new MutateRowsBatchingDescriptor());
    Set<StatusCode.Code> retryCodes = ImmutableSet.of(StatusCode.Code.UNAVAILABLE);
    RetrySettings retrySettings = RetrySettings.newBuilder().build();
    builder.setBatchingSettings(BATCHING_SETTINGS).setRetryableCodes(retryCodes).setRetrySettings(retrySettings);
    BigtableBatchingCallSettings settings = builder.build();
    assertThat(settings.getBatchingSettings()).isEqualTo(BATCHING_SETTINGS);
    assertThat(settings.getRetryableCodes()).isEqualTo(retryCodes);
    assertThat(settings.getRetrySettings()).isEqualTo(retrySettings);
    assertThat(settings.isLatencyBasedThrottlingEnabled()).isFalse();
    assertThat(settings.getTargetRpcLatencyMs()).isNull();
    assertThat(settings.getDynamicFlowControlSettings()).isNotNull();
    verifyFlowControlSettingWhenLatencyBasedThrottlingDisabled(settings.getDynamicFlowControlSettings());
    builder.enableLatencyBasedThrottling(10L);
    settings = builder.build();
    assertThat(settings.isLatencyBasedThrottlingEnabled()).isTrue();
    assertThat(settings.getTargetRpcLatencyMs()).isEqualTo(10);
    assertThat(settings.getDynamicFlowControlSettings()).isNotNull();
    verifyFlowControlSettingWhenLatencyBasedThrottlingEnabled(settings.getDynamicFlowControlSettings());
    builder.disableLatencyBasedThrottling();
    settings = builder.build();
    assertThat(settings.isLatencyBasedThrottlingEnabled()).isFalse();
    assertThat(settings.getTargetRpcLatencyMs()).isNull();
    assertThat(settings.getDynamicFlowControlSettings()).isNotNull();
    verifyFlowControlSettingWhenLatencyBasedThrottlingDisabled(settings.getDynamicFlowControlSettings());
}
Also used : RetrySettings(com.google.api.gax.retrying.RetrySettings) StatusCode(com.google.api.gax.rpc.StatusCode) MutateRowsBatchingDescriptor(com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor) Test(org.junit.Test)

Example 13 with Builder

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable by googleapis.

the class DirectPathFallbackIT method setup.

@Before
public void setup() throws IOException {
    Set<ConnectionMode> validModes = ImmutableSet.of(ConnectionMode.REQUIRE_DIRECT_PATH, ConnectionMode.REQUIRE_DIRECT_PATH_IPV4);
    assume().withMessage("DirectPathFallbackIT can only return when explicitly requested").that(validModes.contains(testEnvRule.env().getConnectionMode())).isTrue();
    BigtableDataSettings defaultSettings = testEnvRule.env().getDataClientSettings();
    InstantiatingGrpcChannelProvider defaultTransportProvider = (InstantiatingGrpcChannelProvider) defaultSettings.getStubSettings().getTransportChannelProvider();
    InstantiatingGrpcChannelProvider instrumentedTransportChannelProvider = defaultTransportProvider.toBuilder().setAttemptDirectPath(true).setPoolSize(1).setChannelConfigurator(new ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder>() {

        @Override
        public ManagedChannelBuilder apply(ManagedChannelBuilder builder) {
            injectNettyChannelHandler(builder);
            // Fail fast when blackhole is active
            builder.keepAliveTime(1, TimeUnit.SECONDS);
            builder.keepAliveTimeout(1, TimeUnit.SECONDS);
            return builder;
        }
    }).build();
    // Inject the instrumented transport provider into a new client
    BigtableDataSettings.Builder settingsBuilder = testEnvRule.env().getDataClientSettings().toBuilder();
    settingsBuilder.stubSettings().setTransportChannelProvider(instrumentedTransportChannelProvider).setCredentialsProvider(FixedCredentialsProvider.create(ComputeEngineCredentials.create()));
    instrumentedClient = BigtableDataClient.create(settingsBuilder.build());
}
Also used : InstantiatingGrpcChannelProvider(com.google.api.gax.grpc.InstantiatingGrpcChannelProvider) ConnectionMode(com.google.cloud.bigtable.test_helpers.env.AbstractTestEnv.ConnectionMode) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) ApiFunction(com.google.api.core.ApiFunction) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) Before(org.junit.Before)

Example 14 with Builder

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable by googleapis.

the class BulkMutateIT method test.

@Test(timeout = 60 * 1000)
public void test() throws IOException, InterruptedException {
    BigtableDataSettings settings = testEnvRule.env().getDataClientSettings();
    String rowPrefix = UUID.randomUUID().toString();
    // Set target latency really low so it'll trigger adjusting thresholds
    BigtableDataSettings.Builder builder = settings.toBuilder().enableBatchMutationLatencyBasedThrottling(2L);
    try (BigtableDataClient client = BigtableDataClient.create(builder.build());
        BatcherImpl<RowMutationEntry, Void, BulkMutation, Void> batcher = (BatcherImpl<RowMutationEntry, Void, BulkMutation, Void>) client.newBulkMutationBatcher(testEnvRule.env().getTableId())) {
        FlowControlEventStats events = batcher.getFlowController().getFlowControlEventStats();
        long initialThreashold = Objects.requireNonNull(batcher.getFlowController().getCurrentElementCountLimit());
        assertThat(batcher.getFlowController().getCurrentElementCountLimit()).isNotEqualTo(batcher.getFlowController().getMinElementCountLimit());
        assertThat(batcher.getFlowController().getCurrentElementCountLimit()).isNotEqualTo(batcher.getFlowController().getMaxElementCountLimit());
        String familyId = testEnvRule.env().getFamilyId();
        long initial = batcher.getFlowController().getCurrentElementCountLimit();
        for (long i = 0; i < initial * 3; i++) {
            String key = rowPrefix + "test-key" + i;
            batcher.add(RowMutationEntry.create(key).setCell(familyId, "qualifier", i));
        }
        batcher.flush();
        assertThat(events.getLastFlowControlEvent()).isNotNull();
        // Verify that the threshold is adjusted
        assertThat(batcher.getFlowController().getCurrentElementCountLimit()).isNotEqualTo(initialThreashold);
        // Query a key to make sure the write succeeded
        Row row = testEnvRule.env().getDataClient().readRowsCallable().first().call(Query.create(testEnvRule.env().getTableId()).rowKey(rowPrefix + "test-key" + initial));
        assertThat(row.getCells()).hasSize(1);
    }
}
Also used : BulkMutation(com.google.cloud.bigtable.data.v2.models.BulkMutation) FlowControlEventStats(com.google.api.gax.batching.FlowControlEventStats) RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry) Row(com.google.cloud.bigtable.data.v2.models.Row) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) BatcherImpl(com.google.api.gax.batching.BatcherImpl) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) Test(org.junit.Test)

Example 15 with Builder

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable by googleapis.

the class EnhancedBigtableStub method finalizeSettings.

public static EnhancedBigtableStubSettings finalizeSettings(EnhancedBigtableStubSettings settings, Tagger tagger, StatsRecorder stats) throws IOException {
    EnhancedBigtableStubSettings.Builder builder = settings.toBuilder();
    // TODO: this implementation is on the cusp of unwieldy, if we end up adding more features
    // consider splitting it up by feature.
    // workaround JWT audience issues
    patchCredentials(builder);
    // Inject channel priming
    if (settings.isRefreshingChannel()) {
        // Fix the credentials so that they can be shared
        Credentials credentials = null;
        if (settings.getCredentialsProvider() != null) {
            credentials = settings.getCredentialsProvider().getCredentials();
        }
        builder.setCredentialsProvider(FixedCredentialsProvider.create(credentials));
        // Inject the primer
        InstantiatingGrpcChannelProvider transportProvider = (InstantiatingGrpcChannelProvider) settings.getTransportChannelProvider();
        builder.setTransportChannelProvider(transportProvider.toBuilder().setChannelPrimer(BigtableChannelPrimer.create(credentials, settings.getProjectId(), settings.getInstanceId(), settings.getAppProfileId(), settings.getPrimedTableIds())).build());
    }
    ImmutableMap<TagKey, TagValue> attributes = ImmutableMap.<TagKey, TagValue>builder().put(RpcMeasureConstants.BIGTABLE_PROJECT_ID, TagValue.create(settings.getProjectId())).put(RpcMeasureConstants.BIGTABLE_INSTANCE_ID, TagValue.create(settings.getInstanceId())).put(RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID, TagValue.create(settings.getAppProfileId())).build();
    // Inject Opencensus instrumentation
    builder.setTracerFactory(new CompositeTracerFactory(ImmutableList.of(// Add OpenCensus Tracing
    new OpencensusTracerFactory(ImmutableMap.<String, String>builder().put(RpcMeasureConstants.BIGTABLE_PROJECT_ID.getName(), settings.getProjectId()).put(RpcMeasureConstants.BIGTABLE_INSTANCE_ID.getName(), settings.getInstanceId()).put(RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID.getName(), settings.getAppProfileId()).put("gax", GaxGrpcProperties.getGaxGrpcVersion()).put("grpc", GaxGrpcProperties.getGrpcVersion()).put("gapic", Version.VERSION).build()), // Add OpenCensus Metrics
    MetricsTracerFactory.create(tagger, stats, attributes), // Add user configured tracer
    settings.getTracerFactory())));
    return builder.build();
}
Also used : InstantiatingGrpcChannelProvider(com.google.api.gax.grpc.InstantiatingGrpcChannelProvider) CompositeTracerFactory(com.google.cloud.bigtable.data.v2.stub.metrics.CompositeTracerFactory) TagKey(io.opencensus.tags.TagKey) TagValue(io.opencensus.tags.TagValue) OpencensusTracerFactory(com.google.api.gax.tracing.OpencensusTracerFactory) ServiceAccountJwtAccessCredentials(com.google.auth.oauth2.ServiceAccountJwtAccessCredentials) Credentials(com.google.auth.Credentials)

Aggregations

Test (org.junit.Test)9 RetrySettings (com.google.api.gax.retrying.RetrySettings)4 BigtableDataSettings (com.google.cloud.bigtable.data.v2.BigtableDataSettings)3 MutateRowsBatchingDescriptor (com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor)3 ReadRowsBatchingDescriptor (com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsBatchingDescriptor)3 InstantiatingGrpcChannelProvider (com.google.api.gax.grpc.InstantiatingGrpcChannelProvider)2 StatusCode (com.google.api.gax.rpc.StatusCode)2 MutateRowsRequest (com.google.bigtable.v2.MutateRowsRequest)2 Builder (com.google.bigtable.v2.MutateRowsRequest.Builder)2 Filters (com.google.cloud.bigtable.data.v2.models.Filters)2 MutateRowsException (com.google.cloud.bigtable.data.v2.models.MutateRowsException)2 FailedMutation (com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation)2 ApiFunction (com.google.api.core.ApiFunction)1 BatcherImpl (com.google.api.gax.batching.BatcherImpl)1 FlowControlEventStats (com.google.api.gax.batching.FlowControlEventStats)1 ApiException (com.google.api.gax.rpc.ApiException)1 ClientContext (com.google.api.gax.rpc.ClientContext)1 OpencensusTracerFactory (com.google.api.gax.tracing.OpencensusTracerFactory)1 Credentials (com.google.auth.Credentials)1 ServiceAccountJwtAccessCredentials (com.google.auth.oauth2.ServiceAccountJwtAccessCredentials)1