Commit f0487d1
authored
Enable telemetry by default with DSN-controlled priority and full event correctness tests (#349)
## Summary
This PR extends the telemetry implementation across two areas.
### 1. DSN / config changes (original scope)
- `EnableTelemetry *bool` tristate in `telemetry.Config`: `nil` = defer
to server flag, `&true` = client opt-in, `&false` = client opt-out.
- Two-level enable priority: DSN `enableTelemetry=true` → always on;
otherwise use server feature flag.
- Two new DSN params: `telemetry_retry_count` and
`telemetry_retry_delay`.
### 2. Telemetry gap fixes (new in this PR)
Four correctness bugs found during end-to-end testing against a real
warehouse:
**EXECUTE_STATEMENT / CLOSE_STATEMENT silently lost on shutdown**
Root cause: `agg.cancel()` fired while a worker was mid-HTTP-export.
Fix: added `inFlight sync.WaitGroup`; `close()` calls `inFlight.Wait()`
before `cancel()`.
**`total_chunks_present: null` for paginated CloudFetch**
Root cause: server reports 1 link per `FetchResults` call; grand total
never in a single response.
Fix: pass `r.chunkCount` through `closeCallback`; `connection.go` sets
`chunk_total_present` if the server never reported it.
**`operation_latency_ms: null` for CLOSE_STATEMENT**
Root cause: `CloseOperation` RPC completes in <1ms → rounds to 0;
`omitempty` drops 0.
Fix: removed `omitempty` from `OperationLatencyMs`.
**CloudFetch S3 timing fields not populated**
Root cause: per-S3-file download time was not measured.
Fix: added `onFileDownloaded func(downloadMs int64)` callback to
`cloudIPCStreamIterator`; `connection.go` aggregates initial/slowest/sum
timings.
### 3. DSN parameters (full set)
| Parameter | Type | Default | Description |
|---|---|---|---|
| `enableTelemetry` | bool | unset | Overrides server flag when set |
| `telemetry_batch_size` | int | 100 | Events per batch |
| `telemetry_flush_interval` | duration | 5s | Periodic flush interval |
| `telemetry_retry_count` | int | 3 | Max retry attempts on export
failure |
| `telemetry_retry_delay` | duration | 100ms | Base delay between
retries (exponential backoff) |
## Key files changed
- `telemetry/aggregator.go` — `inFlight` WaitGroup; 5-step `close()`
ordering
- `telemetry/interceptor.go` — `RecordOperation` takes `statementID` so
CLOSE_STATEMENT carries `sql_statement_id`
- `telemetry/request.go` — removed `omitempty` from `OperationLatencyMs`
- `connection.go` — `closeCallback(latencyMs, chunkCount, err)` +
`cloudFetchCallback` wiring
- `internal/rows/rows.go` — `closeCallback` passes `r.chunkCount`;
`cloudFetchCallback` threaded through
- `internal/rows/arrowbased/batchloader.go` — `onFileDownloaded`
callback per S3 file download
## Test plan
- [x] `go build ./...` — clean compile
- [x] `go test ./telemetry/... -count=1` — all pass
- [x] `go test ./internal/rows/... -count=1` — all pass
- [x] `go test ./... -short -count=1` — full suite passes
### New correctness tests
**`telemetry/aggregator_test.go`** (new file, 5 tests):
- `WaitsForInFlightWorkerExports` — `close()` blocks until all HTTP
exports finish, even if workers picked up jobs before the drain step ran
- `DrainsPendingQueueJobsBeforeCancel` — jobs sitting in `exportQueue`
are exported synchronously during drain
- `InFlightAddBeforeSend` — `inFlight.Add(1)` precedes the channel send
so no job is invisible to `Wait()`
- `SafeToCallMultipleTimes` — concurrent `close()` calls do not deadlock
(`sync.Once`)
- `DropWhenQueueFull` — drop path calls `inFlight.Done()` so `Wait()` is
never permanently blocked
**`telemetry/integration_test.go`** (2 new tests):
- `OperationLatencyMs_ZeroNotOmitted` — raw JSON contains
`"operation_latency_ms":0`, not absent
- `ChunkTotalPresent_DerivedFromChunkCount` — `chunk_total_present` tag
propagates to `ChunkDetails`
**`internal/rows/arrowbased/batchloader_test.go`** (2 new tests):
- `OnFileDownloaded` callback invoked once per file with positive
`downloadMs`
- Nil callback is safe on non-telemetry paths (no panic)
**`internal/rows/rows_test.go`** (2 new tests):
- `CloseCallback_ReceivesChunkCount` — callback gets correct total pages
after multi-page iteration
- `CloseCallback_NilDoesNotPanic` — nil `closeCallback` is safe on
`rows.Close()`
This pull request was AI-assisted by Isaac.1 parent 4faa786 commit f0487d1
27 files changed
Lines changed: 2020 additions & 1100 deletions
File tree
- internal
- config
- rows
- arrowbased
- telemetry
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
134 | 133 | | |
135 | | - | |
| 134 | + | |
| 135 | + | |
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
141 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
142 | 147 | | |
143 | 148 | | |
144 | 149 | | |
| |||
163 | 168 | | |
164 | 169 | | |
165 | 170 | | |
166 | | - | |
| 171 | + | |
167 | 172 | | |
168 | 173 | | |
169 | 174 | | |
| |||
179 | 184 | | |
180 | 185 | | |
181 | 186 | | |
182 | | - | |
| 187 | + | |
183 | 188 | | |
184 | 189 | | |
185 | 190 | | |
186 | 191 | | |
187 | 192 | | |
188 | 193 | | |
189 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
190 | 236 | | |
191 | 237 | | |
192 | 238 | | |
| |||
206 | 252 | | |
207 | 253 | | |
208 | 254 | | |
209 | | - | |
| 255 | + | |
| 256 | + | |
210 | 257 | | |
211 | 258 | | |
212 | 259 | | |
213 | | - | |
214 | 260 | | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
| 261 | + | |
219 | 262 | | |
220 | 263 | | |
221 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
222 | 271 | | |
223 | 272 | | |
224 | 273 | | |
225 | 274 | | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
231 | 357 | | |
232 | 358 | | |
233 | 359 | | |
234 | | - | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
235 | 365 | | |
236 | 366 | | |
237 | 367 | | |
| |||
396 | 526 | | |
397 | 527 | | |
398 | 528 | | |
399 | | - | |
400 | 529 | | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | 530 | | |
408 | 531 | | |
409 | 532 | | |
| |||
668 | 791 | | |
669 | 792 | | |
670 | 793 | | |
671 | | - | |
672 | | - | |
| 794 | + | |
| 795 | + | |
673 | 796 | | |
674 | | - | |
675 | | - | |
| 797 | + | |
| 798 | + | |
676 | 799 | | |
677 | 800 | | |
678 | | - | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
679 | 804 | | |
680 | 805 | | |
681 | 806 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1975 | 1975 | | |
1976 | 1976 | | |
1977 | 1977 | | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
1978 | 2031 | | |
1979 | 2032 | | |
1980 | 2033 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
93 | 94 | | |
94 | 95 | | |
95 | | - | |
| 96 | + | |
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
| |||
0 commit comments