| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
fix: updates for tsdb blocks handling (#1928) * fix(api): correct TSDB blocks result shape, align types with upstream I forgot the implementation for `*apiClientImpl.Do()` already extracts the response content from the enveloped `data` field in the response, so the wrapper struct isn't needed here. Aligns with the upstream `tsdb.BlockMeta` types, while also adding fields missed in the initial implementation and match upstream JSON tags exactly (notably `omitempty` on all stats fields and on sources) so re-marshaling these types produces the same wire format Prometheus emits. Note: This changes the public API surface and is a breaking change, now that 1.24.0 has been officially cut, so changelog has been updated as well. Signed-off-by: TJ Hoplock <t.hoplock@gmail.com> * test(api): expand test coverage for tsdb blocks endpoint Cover the edge cases that let the original implementation gaps slip through, per review feedback on #1928. To keep CI time down, the quirks share a single success case rather than one case each: - an empty `blocks` list - a fully populated block with every optional stats/compaction field, including `parents` lineage and the `from-out-of-order` compaction hint (the literal upstream's CompactionHintFromOutOfOrder constant emits), with stats values past 2^32 so narrowing any uint64 stats field fails the test - a minimal uncompacted block with no `stats` field, deserializing to zero values - unknown block-level and stats-level fields, which the decoder must ignore All `inRes` payloads model the post-envelope body, matching what `apiClientImpl.Do()` actually hands to `TSDBBlocks()`. Signed-off-by: TJ Hoplock <t.hoplock@gmail.com> * test(api): add reflection-based TSDB block type parity test The v1 API TSDB block types are hand-copied from prometheus/prometheus (importing it from the main module would be near-circular, since Prometheus imports client_golang), so nothing ties them to upstream at compile time. Add a standalone test module, api/prometheus/v1/paritytest, that imports both and diffs the struct definitions field by field via reflection: JSON names, full tags (including omitempty), and field types, with the client's deliberate ulid.ULID-to-string mapping canonicalized away. Per review feedback on exported type definitions, so upstream refactors of TSDB internals can't break it. Mutation-tested: renaming a client json tag or narrowing a stats field to uint32 fails with a field-level diff. The separate module keeps prometheus/prometheus out of client_golang's module graph; it is a leaf, so consumers are unaffected. It replaces client_golang with the in-tree checkout and pins a prometheus release that dependabot bumps, so upstream type changes fail the parity test in the bump PR. test-parity is deliberately not part of `make test`: compiling the pinned Prometheus against the in-tree client_golang on every PR would couple all of CI to the pin, with incompatibilities surfacing as compile errors in third-party code on unrelated jobs. Signed-off-by: TJ Hoplock <t.hoplock@gmail.com> * Update CHANGELOG.md Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> Signed-off-by: TJ Hoplock <t.hoplock@gmail.com> * chore(api): suppress modernize omitzero check on TSDBBlockMeta.Stats We have modernize enabled upstream now. The `omitzero` analyzer flags omitempty on nested struct fields as a no-op, but we're doing it explicitly to match upstream, so just skip it. Signed-off-by: TJ Hoplock <t.hoplock@gmail.com> * chore(api): update tsdb blocks benchmarks The apiResponse decode benchmark added on main (#2118) builds its TSDBBlocksResult case against the pre-fix types, which this branch flattens and renames to match upstream tsdb.BlockMeta. The branch compiled on its own, but CI builds the merge ref, where the benchmark failed to compile: api_bench_test.go:227:3: unknown field Status in struct literal of type TSDBBlocksResult api_bench_test.go:228:9: undefined: TSDBBlocksData api_bench_test.go:229:14: undefined: TSDBBlocksBlockMetadata api_bench_test.go:233:12: undefined: TSDBBlocksStats api_bench_test.go:238:17: undefined: TSDBBlocksCompaction Rewrite the case with TSDBBlockMeta, TSDBBlockStats and TSDBBlockMetaCompaction, dropping the Status/Data envelope that the client already strips before decoding. Signed-off-by: TJ Hoplock <t.hoplock@gmail.com> * chore: go fmt updates for tutorials Signed-off-by: TJ Hoplock <t.hoplock@gmail.com> --------- Signed-off-by: TJ Hoplock <t.hoplock@gmail.com> Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com> | 1 天前 |