From 39c1fe617b549fdf45d0a35198782723ce278515 Mon Sep 17 00:00:00 2001 From: TJ Hoplock Date: Mon, 15 Dec 2025 02:08:09 -0500 Subject: [PATCH] fix: updates for tsdb blocks handling Two small fixes: - 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. - The `compaction` section of a block has an optional `parents` field for tracking block lineage in deeper compaction levels. This slipped my mind during implementation because I was looking at the example API response on the API docs, which use a mock response with a single block that is uncompacted. I noticed these while working on tjhop/prometheus-mcp-server#77 Signed-off-by: TJ Hoplock --- api/prometheus/v1/api.go | 20 ++++++----- api/prometheus/v1/api_test.go | 66 ++++++++++++++++------------------- 2 files changed, 41 insertions(+), 45 deletions(-) diff --git a/api/prometheus/v1/api.go b/api/prometheus/v1/api.go index 8e5e6a390..b48c7fef6 100644 --- a/api/prometheus/v1/api.go +++ b/api/prometheus/v1/api.go @@ -696,14 +696,8 @@ type TSDBHeadStats struct { MaxTime int `json:"maxTime"` } -// TSDBBlocksResult contains the results from querying the tsdb blocks endpoint. -type TSDBBlocksResult struct { - Status string `json:"status"` - Data TSDBBlocksData `json:"data"` -} - // TSDBBlocksData contains the metadata for the tsdb blocks. -type TSDBBlocksData struct { +type TSDBBlocksResult struct { Blocks []TSDBBlocksBlockMetadata `json:"blocks"` } @@ -724,10 +718,18 @@ type TSDBBlocksStats struct { NumChunks int `json:"numChunks"` } +// TSDBBlocksCompactionParent contains details on parent blocks for a single tsdb block. +type TSDBBlocksCompactionParent struct { + Ulid string `json:"ulid"` + MinTime int64 `json:"minTime"` + MaxTime int64 `json:"maxTime"` +} + // TSDBBlocksCompaction contains block compaction details for a single block. type TSDBBlocksCompaction struct { - Level int `json:"level"` - Sources []string `json:"sources"` + Level int `json:"level"` + Sources []string `json:"sources"` + Parents []TSDBBlocksCompactionParent `json:"parents,omitempty"` } // WalReplayStatus represents the wal replay status. diff --git a/api/prometheus/v1/api_test.go b/api/prometheus/v1/api_test.go index aa26cba8d..7a3b12f90 100644 --- a/api/prometheus/v1/api_test.go +++ b/api/prometheus/v1/api_test.go @@ -1206,48 +1206,42 @@ func TestAPIs(t *testing.T) { reqMethod: "GET", reqPath: "/api/v1/status/tsdb/blocks", inRes: map[string]interface{}{ - "status": "success", - "data": map[string]interface{}{ - "blocks": []interface{}{ - map[string]interface{}{ - "ulid": "01JZ8JKZY6XSK3PTDP9ZKRWT60", - "minTime": 1750860620060, - "maxTime": 1750867200000, - "stats": map[string]interface{}{ - "numSamples": 13701, - "numSeries": 716, - "numChunks": 716, - }, - "compaction": map[string]interface{}{ - "level": 1, - "sources": []interface{}{ - "01JZ8JKZY6XSK3PTDP9ZKRWT60", - }, + "blocks": []interface{}{ + map[string]interface{}{ + "ulid": "01JZ8JKZY6XSK3PTDP9ZKRWT60", + "minTime": 1750860620060, + "maxTime": 1750867200000, + "stats": map[string]interface{}{ + "numSamples": 13701, + "numSeries": 716, + "numChunks": 716, + }, + "compaction": map[string]interface{}{ + "level": 1, + "sources": []interface{}{ + "01JZ8JKZY6XSK3PTDP9ZKRWT60", }, - "version": 1, }, + "version": 1, }, }, }, res: TSDBBlocksResult{ - Status: "success", - Data: TSDBBlocksData{ - Blocks: []TSDBBlocksBlockMetadata{{ - Ulid: "01JZ8JKZY6XSK3PTDP9ZKRWT60", - MinTime: 1750860620060, - MaxTime: 1750867200000, - Version: 1, - Stats: TSDBBlocksStats{ - NumSamples: 13701, - NumSeries: 716, - NumChunks: 716, - }, - Compaction: TSDBBlocksCompaction{ - Level: 1, - Sources: []string{"01JZ8JKZY6XSK3PTDP9ZKRWT60"}, - }, - }}, - }, + Blocks: []TSDBBlocksBlockMetadata{{ + Ulid: "01JZ8JKZY6XSK3PTDP9ZKRWT60", + MinTime: 1750860620060, + MaxTime: 1750867200000, + Version: 1, + Stats: TSDBBlocksStats{ + NumSamples: 13701, + NumSeries: 716, + NumChunks: 716, + }, + Compaction: TSDBBlocksCompaction{ + Level: 1, + Sources: []string{"01JZ8JKZY6XSK3PTDP9ZKRWT60"}, + }, + }}, }, },