Skip to content

Commit

Permalink
add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
milaGGL committed Nov 13, 2024
1 parent 7b4fc14 commit f7ec3c0
Show file tree
Hide file tree
Showing 7 changed files with 362 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ final class ServerSideTransactionRunner<T> {
firestore
.getOptions()
.getMetricsUtil()
.createMetricsContext(TelemetryConstants.METHOD_NAME_TRANSACTION_RUN);
.createMetricsContext(TelemetryConstants.METHOD_NAME_RUN_TRANSACTION);
}

@Nonnull
Expand Down Expand Up @@ -150,6 +150,7 @@ ApiFuture<ServerSideTransaction> begin() {
serverSideTransaction.setTransactionTraceContext(runTransactionContext);
return serverSideTransaction;
});
metricsContext.recordLatencyAtFuture(MetricType.FIRST_RESPONSE_LATENCY, result);
span.endAtFuture(result);
return result;
} catch (Exception error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class BuiltinMetricsProvider {

private static final String MILLISECOND_UNIT = "ms";
private static final String INTEGER_UNIT = "1";
private static final String FIRESTORE_LIBRARY_NAME = "com.google.cloud.firestore";

public BuiltinMetricsProvider(OpenTelemetry openTelemetry) {
this.openTelemetry = openTelemetry;
Expand All @@ -81,7 +80,8 @@ OpenTelemetry getOpenTelemetry() {
private Map<String, String> createStaticAttributes() {
Map<String, String> staticAttributes = new HashMap<>();
staticAttributes.put(METRIC_ATTRIBUTE_KEY_CLIENT_UID.getKey(), ClientIdentifier.getClientUid());
staticAttributes.put(METRIC_ATTRIBUTE_KEY_LIBRARY_NAME.getKey(), FIRESTORE_LIBRARY_NAME);
staticAttributes.put(
METRIC_ATTRIBUTE_KEY_LIBRARY_NAME.getKey(), TelemetryConstants.FIRESTORE_LIBRARY_NAME);
String pkgVersion = this.getClass().getPackage().getImplementationVersion();
if (pkgVersion != null) {
staticAttributes.put(METRIC_ATTRIBUTE_KEY_LIBRARY_VERSION.getKey(), pkgVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import java.util.UUID;

/** A utility class for retrieving a unique client identifier (CLIENT_UID) */
final class ClientIdentifier {
@InternalApi
public final class ClientIdentifier {

private ClientIdentifier() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,8 @@ public void onSuccess(T result) {

private void recordCounter(MetricType metric, String status) {
Map<String, String> attributes = createAttributes(status, methodName);
defaultMetricsProvider.counterRecorder(
MetricType.TRANSACTION_ATTEMPT_COUNT, (long) counter, attributes);
customMetricsProvider.counterRecorder(
MetricType.TRANSACTION_ATTEMPT_COUNT, (long) counter, attributes);
defaultMetricsProvider.counterRecorder(metric, (long) counter, attributes);
customMetricsProvider.counterRecorder(metric, (long) counter, attributes);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public interface TelemetryConstants {
String METRIC_PREFIX = "custom.googleapis.com/internal/client";
String FIRESTORE_METER_NAME = "java_firestore";
String GAX_METER_NAME = OpenTelemetryMetricsRecorder.GAX_METER_NAME;
String FIRESTORE_LIBRARY_NAME = "com.google.cloud.firestore";

// Monitored resource keys for labels
String RESOURCE_KEY_RESOURCE_CONTAINER = "resource_container";
Expand Down
Loading

0 comments on commit f7ec3c0

Please sign in to comment.