Skip to content

Commit

Permalink
feat: client metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
surbhigarg92 committed Jun 10, 2024
1 parent 869a364 commit d1b47e4
Show file tree
Hide file tree
Showing 9 changed files with 1,161 additions and 7 deletions.
57 changes: 51 additions & 6 deletions google-cloud-spanner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<site.installationModule>google-cloud-spanner</site.installationModule>
<opencensus.version>0.31.1</opencensus.version>
<spanner.testenv.config.class>com.google.cloud.spanner.GceTestEnvConfig</spanner.testenv.config.class>
<spanner.testenv.instance>projects/gcloud-devel/instances/spanner-testing-east1</spanner.testenv.instance>
<spanner.gce.config.project_id>gcloud-devel</spanner.gce.config.project_id>
<spanner.testenv.kms_key.name>projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key</spanner.testenv.kms_key.name>
<spanner.testenv.instance>projects/span-cloud-testing/instances/surbhi-testing</spanner.testenv.instance>
<spanner.gce.config.project_id>span-cloud-testing</spanner.gce.config.project_id>
<spanner.testenv.kms_key.name>projects/span-cloud-testing/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key</spanner.testenv.kms_key.name>
</properties>


Expand Down Expand Up @@ -413,17 +413,14 @@
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-metrics</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
Expand All @@ -435,6 +432,54 @@
<artifactId>opentelemetry-sdk-testing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-monitoring</artifactId>
<version>3.38.0</version>
<exclusions>
<exclusion>
<!-- using the perfmark version in opencensus -->
<groupId>io.perfmark</groupId>
<artifactId>perfmark-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-monitoring-v3</artifactId>
<version>3.38.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>com.google.cloud.opentelemetry</groupId>
<artifactId>shared-resourcemapping</artifactId>
<version>0.27.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud.opentelemetry</groupId>
<artifactId>exporter-trace</artifactId>
<version>0.25.2</version>
</dependency>
<dependency>
<groupId>com.google.cloud.opentelemetry</groupId>
<artifactId>exporter-metrics</artifactId>
<version>0.27.0</version>
</dependency>
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-contrib-grpc-metrics</artifactId>
<version>0.30.0</version>
</dependency>
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-exporter-stats-stackdriver</artifactId>
<version>0.30.0</version>
</dependency>

</dependencies>
<profiles>
<profile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* Copyright 2024 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
*
* http://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.spanner;

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;

public class CompositeTracer implements ApiTracer {
private final List<ApiTracer> children;

public 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(null, attemptNumber);
}
}

@Override
public void attemptStarted(Object request, int attemptNumber) {
for (ApiTracer child : children) {
child.attemptStarted(request, 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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2024 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
*
* http://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.spanner;

import com.google.api.gax.tracing.ApiTracer;
import com.google.api.gax.tracing.ApiTracerFactory;
import com.google.api.gax.tracing.BaseApiTracerFactory;
import com.google.api.gax.tracing.SpanName;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;

public class CompositeTracerFactory extends BaseApiTracerFactory {

private final List<ApiTracerFactory> apiTracerFactories;

public CompositeTracerFactory(List<ApiTracerFactory> apiTracerFactories) {
this.apiTracerFactories = ImmutableList.copyOf(apiTracerFactories);
}

@Override
public ApiTracer newTracer(ApiTracer parent, SpanName spanName, OperationType operationType) {
List<ApiTracer> children = new ArrayList<>(apiTracerFactories.size());

for (ApiTracerFactory factory : apiTracerFactories) {
children.add(factory.newTracer(parent, spanName, operationType));
}
return new CompositeTracer(children);
}
}
Loading

0 comments on commit d1b47e4

Please sign in to comment.