Commit 81e8e8e
fix: improve transaction metrics correctness and coverage
- Fix ReadWriteTransactionCallable.call() to use transaction.isActive()
as the sole rollback guard in both the catch and finally blocks,
removing the redundant `committed` boolean flag. isActive() returns
false after both a successful commit and a completed rollback, making
it sufficient to prevent double-rollback or rollback-after-commit.
Move recordAttempt() to the finally block so it always runs exactly
once regardless of how the attempt exits.
- Remove transaction metrics from AggregationQueryExecutor. Per-query
metrics were recorded outside the runInTransaction() scope and used
the misleading transaction_latency name for a single RPC latency.
Metrics are now scoped exclusively to runInTransaction() flows.
- Differentiate method attributes: transaction_latency uses
Transaction.Run (overall operation) and transaction_attempt_count
uses Transaction.Commit (per-attempt), reflecting their different
scopes.
- Add project_id and database_id attributes to both metrics for
multi-project and multi-database observability.
- Move Stopwatch start to just before RetryHelper.runWithRetries() to
exclude callable construction overhead from latency measurements.
- Fix transaction_latency description from "successful transaction
operations" to "transaction operations" since the metric is recorded
for both successful and failed transactions.
- Add Javadoc note to extractStatusCode() about the null-reason edge
case where UNKNOWN is returned.
- Add latency-on-failure assertion to DatastoreImplMetricsTest and
extend attribute checks to cover project_id and database_id.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent c060233 commit 81e8e8e
File tree
8 files changed
+57
-47
lines changed- java-datastore/google-cloud-datastore/src
- main/java/com/google/cloud/datastore
- execution
- telemetry
- test/java/com/google/cloud/datastore
- execution
- telemetry
8 files changed
+57
-47
lines changedLines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
171 | 176 | | |
172 | 177 | | |
173 | 178 | | |
| |||
Lines changed: 23 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
116 | | - | |
| 115 | + | |
117 | 116 | | |
118 | 117 | | |
119 | 118 | | |
| |||
213 | 212 | | |
214 | 213 | | |
215 | 214 | | |
| 215 | + | |
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
220 | | - | |
| 220 | + | |
221 | 221 | | |
222 | 222 | | |
223 | | - | |
224 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
225 | 231 | | |
226 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
227 | 237 | | |
228 | 238 | | |
229 | 239 | | |
| |||
243 | 253 | | |
244 | 254 | | |
245 | 255 | | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
246 | 260 | | |
247 | 261 | | |
248 | 262 | | |
| |||
256 | 270 | | |
257 | 271 | | |
258 | 272 | | |
259 | | - | |
260 | 273 | | |
261 | 274 | | |
262 | 275 | | |
| |||
267 | 280 | | |
268 | 281 | | |
269 | 282 | | |
| 283 | + | |
270 | 284 | | |
271 | 285 | | |
272 | 286 | | |
| |||
282 | 296 | | |
283 | 297 | | |
284 | 298 | | |
285 | | - | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
286 | 302 | | |
287 | 303 | | |
288 | 304 | | |
| |||
Lines changed: 4 additions & 34 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | | - | |
23 | 21 | | |
24 | 22 | | |
25 | 23 | | |
26 | 24 | | |
27 | 25 | | |
28 | 26 | | |
29 | 27 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | 28 | | |
34 | 29 | | |
35 | 30 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | 31 | | |
40 | 32 | | |
41 | 33 | | |
| |||
48 | 40 | | |
49 | 41 | | |
50 | 42 | | |
51 | | - | |
52 | 43 | | |
53 | 44 | | |
54 | 45 | | |
55 | | - | |
56 | | - | |
| 46 | + | |
57 | 47 | | |
58 | 48 | | |
59 | 49 | | |
60 | | - | |
61 | 50 | | |
62 | 51 | | |
63 | 52 | | |
| |||
66 | 55 | | |
67 | 56 | | |
68 | 57 | | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
91 | 61 | | |
92 | 62 | | |
93 | 63 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
42 | 48 | | |
43 | 49 | | |
44 | 50 | | |
| |||
Lines changed: 16 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
117 | 120 | | |
118 | 121 | | |
119 | 122 | | |
| |||
279 | 282 | | |
280 | 283 | | |
281 | 284 | | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
282 | 297 | | |
283 | 298 | | |
284 | 299 | | |
| |||
Lines changed: 1 addition & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | 40 | | |
42 | 41 | | |
43 | 42 | | |
| |||
67 | 66 | | |
68 | 67 | | |
69 | 68 | | |
70 | | - | |
71 | | - | |
| 69 | + | |
72 | 70 | | |
73 | 71 | | |
74 | 72 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| |||
0 commit comments