Skip to content

perf(spanner): hoist AFE timing check to skip AFE metrics - #9313

Open
olavloite wants to merge 2 commits into
mainfrom
spanner-hoist-afe-timer-check
Open

olavloite wants to merge 2 commits into
mainfrom
spanner-hoist-afe-timer-check

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Hoist isAFEServerTimingEnabled check to MetricInterceptor to completely bypass AFE header parsing and metric recording when AFE server-timing is disabled. Also guard MetricsTracer record methods to avoid attribute allocation when instruments are uninitialized.

@olavloite
olavloite requested a review from a team as a code owner September 13, 2026 13:40
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Sep 13, 2026

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

Copy link
Copy Markdown
Contributor

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 AFE server timing checks into standalone helper functions in common.ts and updates the Spanner client and metrics tracer to use them. It also ensures that 0ms latency values are correctly recorded by checking for numeric types instead of truthiness. The review feedback identifies critical potential TypeError crashes in MetricInterceptor when metricsTracer is undefined (e.g., when metrics are disabled) and suggests guarding the metadata and status handling blocks to prevent runtime errors.

Comment thread handwritten/spanner/src/metrics/interceptor.ts
Comment thread handwritten/spanner/src/metrics/interceptor.ts
@olavloite
olavloite force-pushed the spanner-hoist-afe-timer-check branch from f9df8a2 to e48d6fc Compare September 13, 2026 13:53
@olavloite

Copy link
Copy Markdown
Contributor Author

/gemini review

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

Copy link
Copy Markdown
Contributor

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 AFE server timing check functions out of the Spanner class into common.ts and updates the metrics interceptor and tracer to use them. It also refines how GFE and AFE latency metrics are recorded, including handling cases where latency is 0ms and adding safety checks when the metrics tracer is null. The review feedback highlights two critical issues in MetricsTracer where recordGfeLatency and recordAfeLatency log an error when latency is null or undefined but still proceed to record the invalid value, suggesting early returns to prevent potential runtime exceptions.

Comment thread handwritten/spanner/src/metrics/metrics-tracer.ts
Comment thread handwritten/spanner/src/metrics/metrics-tracer.ts
Hoist isAFEServerTimingEnabled check to MetricInterceptor to completely
bypass AFE header parsing and metric recording when AFE server-timing is
disabled. Also guard MetricsTracer record methods to avoid attribute
allocation when instruments are uninitialized.
@olavloite
olavloite force-pushed the spanner-hoist-afe-timer-check branch from e48d6fc to c04bb43 Compare September 13, 2026 14:03
@olavloite

Copy link
Copy Markdown
Contributor Author

/gemini review

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

Copy link
Copy Markdown
Contributor

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 AFE server timing check by moving isAFEServerTimingEnabled from the Spanner class to a standalone function in common.ts and updates the metrics interceptor and tracer to respect this setting. It also improves robustness by checking for null/undefined tracers and allowing 0 as a valid latency value, backed by new unit tests. The review feedback correctly identifies that recordGfeLatency and recordAfeLatency in MetricsTracer should return early when their respective latency values are null or undefined to prevent passing invalid arguments to the recording instruments.

Comment thread handwritten/spanner/src/metrics/metrics-tracer.ts
Comment thread handwritten/spanner/src/metrics/metrics-tracer.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant