Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mutianf committed Aug 10, 2021
1 parent 87934b2 commit adecc91
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
Expand Up @@ -71,6 +71,8 @@
import com.google.cloud.bigtable.data.v2.models.RowMutation;
import com.google.cloud.bigtable.data.v2.models.RowMutationEntry;
import com.google.cloud.bigtable.data.v2.stub.metrics.BigtableTracerFactory;
import com.google.cloud.bigtable.data.v2.stub.metrics.ExtraHeadersSeverStreamingCallable;
import com.google.cloud.bigtable.data.v2.stub.metrics.ExtraHeadersUnaryCallable;
import com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerStreamingCallable;
import com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerUnaryCallable;
import com.google.cloud.bigtable.data.v2.stub.metrics.MetricsTracerFactory;
Expand Down
Expand Up @@ -15,7 +15,6 @@
*/
package com.google.cloud.bigtable.data.v2.stub.metrics;

import com.google.api.core.InternalApi;
import com.google.api.gax.rpc.ApiCallContext;
import com.google.api.gax.tracing.ApiTracer;
import com.google.api.gax.tracing.BaseApiTracer;
Expand All @@ -30,8 +29,7 @@
* will ensure that operation lifecycle events are plumbed through while maintaining user configured
* functionalities.
*/
@InternalApi("For internal use only")
public class BigtableTracer extends BaseApiTracer {
class BigtableTracer extends BaseApiTracer {
private final List<ApiTracer> children;
private int attempt = 0;

Expand Down Expand Up @@ -166,7 +164,7 @@ public void batchRequestSent(long elementCount, long requestSize) {
/**
* Get the attempt number of the current call. Attempt number for the current call is passed in
* and recorded in {@link #attemptStarted(int)}. With the getter we can access it from {@link
* ApiCallContext}.
* ApiCallContext}. Attempt number starts from 0.
*/
public int getAttempt() {
return attempt;
Expand Down
Expand Up @@ -14,22 +14,23 @@
* limitations under the License.
*/

package com.google.cloud.bigtable.data.v2.stub;
package com.google.cloud.bigtable.data.v2.stub.metrics;

import com.google.api.core.InternalApi;
import com.google.api.gax.rpc.ApiCallContext;
import com.google.api.gax.rpc.ResponseObserver;
import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.cloud.bigtable.data.v2.stub.metrics.Util;

/**
* A callable that injects client timestamp and current attempt number to request headers. Attempt
* number starts from 0.
*/
final class ExtraHeadersSeverStreamingCallable<RequestT, ResponseT>
@InternalApi("For internal use only")
public final class ExtraHeadersSeverStreamingCallable<RequestT, ResponseT>
extends ServerStreamingCallable<RequestT, ResponseT> {
private final ServerStreamingCallable innerCallable;

ExtraHeadersSeverStreamingCallable(ServerStreamingCallable innerCallable) {
public ExtraHeadersSeverStreamingCallable(ServerStreamingCallable innerCallable) {
this.innerCallable = innerCallable;
}

Expand Down
Expand Up @@ -14,18 +14,19 @@
* limitations under the License.
*/

package com.google.cloud.bigtable.data.v2.stub;
package com.google.cloud.bigtable.data.v2.stub.metrics;

import com.google.api.core.ApiFuture;
import com.google.api.core.InternalApi;
import com.google.api.gax.rpc.ApiCallContext;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.bigtable.data.v2.stub.metrics.Util;

/**
* A callable that injects client timestamp and current attempt number to request headers. Attempt
* number starts from 0.
*/
final class ExtraHeadersUnaryCallable<RequestT, ResponseT>
@InternalApi("For internal use only")
public final class ExtraHeadersUnaryCallable<RequestT, ResponseT>
extends UnaryCallable<RequestT, ResponseT> {
private final UnaryCallable innerCallable;

Expand All @@ -34,7 +35,6 @@ public ExtraHeadersUnaryCallable(UnaryCallable innerCallable) {
}

@Override
@SuppressWarnings("unchecked")
public ApiFuture futureCall(RequestT request, ApiCallContext apiCallContext) {
ApiCallContext newCallContext =
apiCallContext.withExtraHeaders(Util.createExtraHeaders(apiCallContext));
Expand Down
Expand Up @@ -15,7 +15,6 @@
*/
package com.google.cloud.bigtable.data.v2.stub.metrics;

import com.google.api.core.InternalApi;
import com.google.api.gax.rpc.ApiCallContext;
import com.google.api.gax.rpc.ApiException;
import com.google.api.gax.rpc.StatusCode;
Expand All @@ -35,11 +34,10 @@
import javax.annotation.Nullable;

/** Utilities to help integrating with OpenCensus. */
@InternalApi("For internal use only")
public class Util {
public static final Metadata.Key<String> ATTEMPT_HEADER_KEY =
class Util {
static final Metadata.Key<String> ATTEMPT_HEADER_KEY =
Metadata.Key.of("attempt", Metadata.ASCII_STRING_MARSHALLER);
public static final Metadata.Key<String> TIMESTAMP_HEADER_KEY =
static final Metadata.Key<String> TIMESTAMP_HEADER_KEY =
Metadata.Key.of("client-timing", Metadata.ASCII_STRING_MARSHALLER);

private static final TagValue OK_STATUS = TagValue.create(StatusCode.Code.OK.toString());
Expand Down Expand Up @@ -89,7 +87,7 @@ static TagValue extractStatus(Future<?> future) {
* Create extra headers with attempt number and client timestamp from api call context. Attempt
* number starts from 0.
*/
public static Map<String, List<String>> createExtraHeaders(ApiCallContext apiCallContext) {
static Map<String, List<String>> createExtraHeaders(ApiCallContext apiCallContext) {
int attemptCount = -1;
if (apiCallContext.getTracer() instanceof BigtableTracer) {
attemptCount = ((BigtableTracer) apiCallContext.getTracer()).getAttempt();
Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.google.cloud.bigtable.data.v2.stub;
package com.google.cloud.bigtable.data.v2.stub.metrics;

import static com.google.common.truth.Truth.assertThat;

Expand All @@ -40,7 +40,8 @@
import com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow;
import com.google.cloud.bigtable.data.v2.models.RowMutation;
import com.google.cloud.bigtable.data.v2.models.RowMutationEntry;
import com.google.cloud.bigtable.data.v2.stub.metrics.Util;
import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub;
import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings;
import com.google.common.collect.Queues;
import com.google.protobuf.ByteString;
import com.google.protobuf.BytesValue;
Expand Down

0 comments on commit adecc91

Please sign in to comment.