Skip to content

Commit

Permalink
feat: Update opencensus metrics to include bigtable resource ids and …
Browse files Browse the repository at this point in the history
…rpc level metrics

This PR refactors opencensus metrics integration to use gax's ApiTracers.
Which allows this client to instrument individual attempts and tag everything
with bigtable resource ids
  • Loading branch information
igorbernstein2 committed Apr 1, 2020
1 parent a204102 commit c383131
Showing 1 changed file with 154 additions and 0 deletions.
@@ -0,0 +1,154 @@
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.bigtable.data.v2.stub.metrics;

import com.google.api.gax.tracing.ApiTracer;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import org.threeten.bp.Duration;

/** Combines multiple {@link ApiTracer}s into a single {@link ApiTracer}. */
class CompositeTracer implements ApiTracer {
private final List<ApiTracer> children;

CompositeTracer(List<ApiTracer> children) {
this.children = ImmutableList.copyOf(children);
}

@Override
public Scope inScope() {
final List<Scope> childScopes = new ArrayList<>(children.size());

for (ApiTracer child : children) {
childScopes.add(child.inScope());
}

return new Scope() {
@Override
public void close() {
for (Scope childScope : childScopes) {
childScope.close();
}
}
};
}

@Override
public void operationSucceeded() {
for (ApiTracer child : children) {
child.operationSucceeded();
}
}

@Override
public void operationCancelled() {
for (ApiTracer child : children) {
child.operationCancelled();
}
}

@Override
public void operationFailed(Throwable error) {
for (ApiTracer child : children) {
child.operationFailed(error);
}
}

@Override
public void connectionSelected(String id) {
for (ApiTracer child : children) {
child.connectionSelected(id);
}
}

@Override
public void attemptStarted(int attemptNumber) {
for (ApiTracer child : children) {
child.attemptStarted(attemptNumber);
}
}

@Override
public void attemptSucceeded() {
for (ApiTracer child : children) {
child.attemptSucceeded();
}
}

@Override
public void attemptCancelled() {
for (ApiTracer child : children) {
child.attemptCancelled();
}
}

@Override
public void attemptFailed(Throwable error, Duration delay) {
for (ApiTracer child : children) {
child.attemptFailed(error, delay);
}
}

@Override
public void attemptFailedRetriesExhausted(Throwable error) {
for (ApiTracer child : children) {
child.attemptFailedRetriesExhausted(error);
}
}

@Override
public void attemptPermanentFailure(Throwable error) {
for (ApiTracer child : children) {
child.attemptPermanentFailure(error);
}
}

@Override
public void lroStartFailed(Throwable error) {
for (ApiTracer child : children) {
child.lroStartFailed(error);
}
}

@Override
public void lroStartSucceeded() {
for (ApiTracer child : children) {
child.lroStartSucceeded();
}
}

@Override
public void responseReceived() {
for (ApiTracer child : children) {
child.responseReceived();
}
}

@Override
public void requestSent() {
for (ApiTracer child : children) {
child.requestSent();
}
}

@Override
public void batchRequestSent(long elementCount, long requestSize) {
for (ApiTracer child : children) {
child.batchRequestSent(elementCount, requestSize);
}
}
}

0 comments on commit c383131

Please sign in to comment.