Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
30a7011
enable 4 metrics from GAX
milaGGL Aug 14, 2024
ed85413
format
milaGGL Aug 16, 2024
57084c4
add default otel
milaGGL Aug 21, 2024
571c095
format
milaGGL Aug 21, 2024
f4b8416
move constants out
milaGGL Aug 22, 2024
da0fe82
format
milaGGL Aug 23, 2024
61432eb
add additional attributes
milaGGL Aug 26, 2024
b5bfe5c
Merge branch 'main' into mila/client-side-metrics-demo
milaGGL Aug 26, 2024
f0a029d
add attributes to gax metrics
milaGGL Aug 27, 2024
5456038
Update BuiltinMetricsConstants.java
milaGGL Sep 4, 2024
5efaba6
remove current metrics implementation
milaGGL Sep 9, 2024
c0b4cc1
add custom exporter, add latency recorder
milaGGL Sep 11, 2024
3979331
use 2 otel instances
milaGGL Sep 18, 2024
a9d08b5
set custom apiTracerFactory to gax
milaGGL Sep 20, 2024
029bd8c
Merge branch 'main' into mila/client-side-metrics-demo2
milaGGL Sep 23, 2024
50e05fb
fix opentelemtry dependency version conflict issue
milaGGL Sep 23, 2024
53cd48a
use enabled/disabled style
milaGGL Sep 24, 2024
7adb9d6
modify access modifiers
milaGGL Sep 24, 2024
690e4ee
format
milaGGL Sep 24, 2024
e6f8ba6
rename boolean
milaGGL Sep 26, 2024
c4ca4ae
Merge branch 'main' into mila/client-side-metrics-demo2
milaGGL Sep 27, 2024
887221d
chore: generate libraries at Fri Sep 27 19:25:02 UTC 2024
cloud-java-bot Sep 27, 2024
a2c715a
Update pom.xml
milaGGL Sep 27, 2024
ed78182
resolve comments from proto
milaGGL Oct 1, 2024
e0d46be
e2E latency for runTransaction
milaGGL Oct 3, 2024
a72a685
Merge branch 'main' into mila/client-side-metrics-demo2
milaGGL Oct 4, 2024
92c83c1
chore: generate libraries at Fri Oct 4 14:44:19 UTC 2024
cloud-java-bot Oct 4, 2024
c5137c1
remove noise
milaGGL Oct 4, 2024
63b5bd3
reformat code
milaGGL Oct 4, 2024
ac424a6
re-format code
milaGGL Oct 7, 2024
52f428f
add documentations/comments
milaGGL Oct 8, 2024
c06b2cb
remove logger.info
milaGGL Oct 8, 2024
daf9fbe
record AggregationQuery firstResponseLatency
milaGGL Oct 10, 2024
1999ff7
Update BuiltinMetricsProvider.java
milaGGL Oct 10, 2024
81e349b
Merge branch 'main' into mila/client-side-metrics-demo2
milaGGL Oct 16, 2024
f4e36d9
resolve comments
milaGGL Oct 16, 2024
05e8efb
Update pom.xml
milaGGL Oct 16, 2024
b0b1687
remove duplicated tracing dependency
milaGGL Oct 16, 2024
4abbcf0
add opentelemetry-sdk-metrics dependency
milaGGL Oct 17, 2024
328855d
adjust end-to-end latency in streaming queries
milaGGL Oct 19, 2024
5e1fb4b
fix clirr error
milaGGL Oct 21, 2024
4fa8874
add exportBuiltinMetricsToGoogleCloudMonitoring flag
milaGGL Oct 23, 2024
7deb0d6
Merge branch 'main' into mila/client-side-metrics-demo2
milaGGL Oct 29, 2024
637f878
Merge branch 'main' into mila/client-side-metrics-demo2
milaGGL Nov 4, 2024
8480fa8
Update clirr-ignored-differences.xml
milaGGL Nov 4, 2024
ef9baa8
add internalStream clirr change back
milaGGL Nov 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move constants out
  • Loading branch information
milaGGL committed Aug 22, 2024
commit f4b8416aed326d3290aaf6db01cd6cda920440c6
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package com.google.cloud.firestore.telemetry;

import com.google.api.gax.tracing.OpenTelemetryMetricsRecorder;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.sdk.metrics.InstrumentSelector;
import io.opentelemetry.sdk.metrics.View;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public class BuiltinMetricsConstants {

static final String FIRESTORE_METER_NAME = "firestore_java";

// TODO: change to firestore.googleapis.com
public static final String METER_NAME = "custom.googleapis.com/internal/client";
Copy link
Contributor Author

@milaGGL milaGGL Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opentelemetry uses dot separation in metrics naming, while monarch uses slash separation. exporting the built-in metrics to other backends might raise naming conflict.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could have named the metrics with dot seperation, use view to reformat it with slash separation in the default OTEL instance for monarch. But the metrics from Gax uses slash already, using dot separation inside firestore doesn't solves the problem.

public static final String GAX_METER_NAME = OpenTelemetryMetricsRecorder.GAX_METER_NAME;

// Metric attribute keys for monitored resource
static final AttributeKey<String> PROJECT_ID_KEY = AttributeKey.stringKey("project_id");
// public static final AttributeKey<String> INSTANCE_ID_KEY = AttributeKey.stringKey("instance");

// Metric attribute keys for labels
// static final AttributeKey<String> LANGUAGE_KEY = AttributeKey.stringKey("language");
static final AttributeKey<String> METHOD_NAME_KEY = AttributeKey.stringKey("method_name");
static final AttributeKey<String> STATUS_KEY = AttributeKey.stringKey("status");
public static final AttributeKey<String> DATABASE_ID_KEY = AttributeKey.stringKey("database_id");
static final AttributeKey<String> CLIENT_LIBRARY_KEY = AttributeKey.stringKey("client_library");
static final AttributeKey<String> LIBRARY_VERSION_KEY = AttributeKey.stringKey("library_version");
static final AttributeKey<String> CLIENT_UID_KEY = AttributeKey.stringKey("client_uid");

static final AttributeKey<String> Language_KEY = AttributeKey.stringKey("language");
public static final AttributeKey<String> SERVICE_NAME = AttributeKey.stringKey("service.name");
// Metric
static final String OPERATION_LATENCY_NAME = "operation_latency";
static final String OPERATION_COUNT_NAME = "operation_count";
static final String ATTEMPT_LATENCY_NAME = "attempt_latency";
static final String ATTEMPT_COUNT_NAME = "attempt_count";
static final String FIRST_RESPONSE_LATENCY_NAME = "first_response_latency";
static final String END_TO_END_LATENCY_NAME = "end_to_end_latency";
static final String TRANSACTION_LATENCY_NAME = "transaction_latency";
static final String TRANSACTION_ATTEMPT_COUNT_NAME = "transaction_attempt_count";

static final String MILLISECOND_UNIT = "ms";

public static final String ENABLE_METRICS_ENV_VAR = "FIRESTORE_ENABLE_TRACING";

public static final Set<AttributeKey> COMMON_ATTRIBUTES =
ImmutableSet.of(
PROJECT_ID_KEY,
DATABASE_ID_KEY,
CLIENT_UID_KEY,
CLIENT_LIBRARY_KEY,
LIBRARY_VERSION_KEY,
STATUS_KEY);

public static final Set<String> BUILTIN_METRICS =
ImmutableSet.of(
OPERATION_LATENCY_NAME,
ATTEMPT_LATENCY_NAME,
OPERATION_COUNT_NAME,
ATTEMPT_COUNT_NAME,
FIRST_RESPONSE_LATENCY_NAME,
END_TO_END_LATENCY_NAME,
TRANSACTION_LATENCY_NAME,
TRANSACTION_ATTEMPT_COUNT_NAME)
.stream()
.map(m -> METER_NAME + '/' + m)
.collect(Collectors.toSet());

static void defineView(
ImmutableMap.Builder<InstrumentSelector, View> viewMap,
String id,
Set<AttributeKey> attributes) {
InstrumentSelector selector =
InstrumentSelector.builder().setName(METER_NAME + "/" + id).build();
Set<String> attributesFilter =
ImmutableSet.<String>builder()
.addAll(attributes.stream().map(AttributeKey::getKey).collect(Collectors.toSet()))
.build();
View view = View.builder().setAttributeFilter(attributesFilter).build();

viewMap.put(selector, view);
}

public static Map<InstrumentSelector, View> getAllViews() {
ImmutableMap.Builder<InstrumentSelector, View> views = ImmutableMap.builder();

defineView(
views,
OPERATION_LATENCY_NAME,
ImmutableSet.<AttributeKey>builder()
.addAll(COMMON_ATTRIBUTES)
.add(METHOD_NAME_KEY)
.build());
defineView(
views,
ATTEMPT_LATENCY_NAME,
ImmutableSet.<AttributeKey>builder()
.addAll(COMMON_ATTRIBUTES)
.add(METHOD_NAME_KEY)
.build());

defineView(
views,
OPERATION_COUNT_NAME,
ImmutableSet.<AttributeKey>builder()
.addAll(COMMON_ATTRIBUTES)
.add(METHOD_NAME_KEY)
.build());

defineView(
views,
ATTEMPT_COUNT_NAME,
ImmutableSet.<AttributeKey>builder()
.addAll(COMMON_ATTRIBUTES)
.add(METHOD_NAME_KEY)
.build());

defineView(
views,
FIRST_RESPONSE_LATENCY_NAME,
ImmutableSet.<AttributeKey>builder()
.addAll(COMMON_ATTRIBUTES)
.add(METHOD_NAME_KEY)
.build());

defineView(
views,
END_TO_END_LATENCY_NAME,
ImmutableSet.<AttributeKey>builder()
.addAll(COMMON_ATTRIBUTES)
.add(METHOD_NAME_KEY)
.build());
return views.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.google.cloud.firestore.telemetry;

/*
* Copyright 2023 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.
*/

import static com.google.cloud.firestore.telemetry.BuiltinMetricsConstants.*;

import com.google.cloud.opentelemetry.metric.GoogleCloudMetricExporter;
import com.google.cloud.opentelemetry.metric.MetricConfiguration;
import io.opentelemetry.sdk.metrics.InstrumentSelector;
import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder;
import io.opentelemetry.sdk.metrics.View;
import io.opentelemetry.sdk.metrics.export.MetricExporter;
import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader;
import java.io.IOException;
import java.util.Map;

public class BuiltinMetricsView {

private BuiltinMetricsView() {}

/** Register built-in metrics on the {@link SdkMeterProviderBuilder} with credentials. */
public static void registerBuiltinMetrics(String projectId, SdkMeterProviderBuilder builder)
throws IOException {

// Attach built-in exporter
MetricExporter metricExporter =
GoogleCloudMetricExporter.createWithConfiguration(
MetricConfiguration.builder().setProjectId(projectId).build());

builder.registerMetricReader(PeriodicMetricReader.builder(metricExporter).build());

// Add static attributes to resource
// Package pkg = this.getClass().getPackage();

// Filter out attributes that are not defined
for (Map.Entry<InstrumentSelector, View> entry : getAllViews().entrySet()) {
builder.registerView(entry.getKey(), entry.getValue());
}

builder.registerMetricReader(PeriodicMetricReader.create(metricExporter));
}
}
Loading