Skip to content

chore(Datastore): Refactor Datastore Metric classes to inherit from Gax#12361

Open
lqiu96 wants to merge 11 commits intomainfrom
datastore-csm-impl-1
Open

chore(Datastore): Refactor Datastore Metric classes to inherit from Gax#12361
lqiu96 wants to merge 11 commits intomainfrom
datastore-csm-impl-1

Conversation

@lqiu96
Copy link
Copy Markdown
Member

@lqiu96 lqiu96 commented Apr 1, 2026

Changes

  1. Rename MetricsRecorder to DatastoreMetricsRecorder to clarify the package specific implementation (not to confuse with Spanner's or Gax's variant)
  2. DatastoreMetricsRecorder inherits from Gax's MetricsRecorder to keep the existing attempt and operation data
  3. Remove gRPC's ApiTracerFactory so that Datastore can natively record gRPC and HttpJson metrics together. Internally, the some metric names have some variantions (e.g. latencies vs latency) and would require a view to update the discrepancies (future PR). Additionally, any new metrics recorded in Gax would only apply to gRPC and would still require a native HttpJson implementation in the client library.
  4. The only attributes recorded for a metric are service, status, and method name. This aligns with the internal labels that are set on the metrics.

lqiu96 added 6 commits March 31, 2026 23:41
Update DatastoreAdminStubSettings and DatastoreStubSettings to include
the library version via Version.VERSION. Add the two new Version.java
files that hold the library version constant. Update native image
reflect-config.json for both the admin and core stub packages.
…gRPC transport coverage

Replace the old MetricsRecorder / OpenTelemetryMetricsRecorder /
NoOpMetricsRecorder types with the new DatastoreMetricsRecorder family,
which extends GAX's MetricsRecorder interface for a unified recording
contract.

Key changes:
- Delete MetricsRecorder.java, OpenTelemetryMetricsRecorder.java,
  NoOpMetricsRecorder.java and their tests
- Add DatastoreMetricsRecorder interface (with simple getInstance() that
  returns an OTel recorder when metrics are enabled, NoOp otherwise)
- Add NoOpDatastoreMetricsRecorder, OpenTelemetryDatastoreMetricsRecorder,
  and DatastoreMetricsRecorderTest
- Remove the !GRPC transport guard from TelemetryUtils.recordOperationMetrics()
  and attemptMetricsCallable() so all transports record metrics uniformly
- Remove the isHttpTransport field from RetryAndTraceDatastoreRpcDecorator
  and DatastoreImpl; remove buildMetricsTracerFactory() from GrpcDatastoreRpc
- Update TelemetryConstants with the new METRIC_PREFIX, DATASTORE_METER_NAME,
  and typed AttributeKey constants needed by the new recorder classes
- Update DatastoreOptions to pass the full DatastoreOptions to getInstance()
  so the recorder factory can inspect credentials and project at creation time
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the Datastore metrics implementation to align with the GAX library's telemetry framework. It introduces the DatastoreMetricsRecorder interface, which extends GAX's MetricsRecorder, and updates the SDK to record metrics for both gRPC and HTTP transports. Key changes include the removal of transport-specific metric logic, updates to TelemetryConstants for standardized metric naming, and the addition of a MetricsSample class. A review comment correctly identified a copy-paste error in the new sample file where Firestore-specific metric names were used instead of the correct Datastore prefixes.

@lqiu96
Copy link
Copy Markdown
Member Author

lqiu96 commented Apr 1, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the Datastore metrics implementation to align with the GAX library's telemetry framework. It introduces DatastoreMetricsRecorder, which extends the GAX MetricsRecorder, and updates DatastoreImpl and related classes to record metrics for both gRPC and HTTP transports. Key changes include the addition of new telemetry constants, the implementation of an OpenTelemetry-based recorder, and the removal of transport-specific logic that previously skipped metrics for gRPC. Feedback includes addressing a compilation error caused by a missing constant in TelemetryConstants.java, removing redundant attribute keys, and unifying OpenTelemetry meter names for better consistency.

@lqiu96
Copy link
Copy Markdown
Member Author

lqiu96 commented Apr 2, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the Datastore telemetry metrics infrastructure by introducing a new DatastoreMetricsRecorder interface and its corresponding implementations. It replaces the previous MetricsRecorder with DatastoreMetricsRecorder, updates the metric recording logic to support both gRPC and HTTP transports, and aligns metric naming and attribute handling with internal Cloud Monitoring requirements. I have reviewed the changes and identified a stale comment in TelemetryConstants.java that references a removed constant, which should be updated for clarity.

@lqiu96 lqiu96 changed the title refactor(Datastore): Extend Datastore Metric classes to inherit from Gax chore(Datastore): Refactor Datastore Metric classes to inherit from Gax Apr 2, 2026
@lqiu96 lqiu96 requested a review from jinseopkim0 April 2, 2026 15:16
@lqiu96 lqiu96 marked this pull request as ready for review April 2, 2026 15:22
@lqiu96 lqiu96 requested a review from a team as a code owner April 2, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant