mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Export TSDB status structs (#10783)
We would like to implement the tsdb/status API in certain Thanos components. In order to match the Prometheus API and avoid duplicating code, this commit makes the structs used in the status API public. Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
This commit is contained in:
parent
2e2c014d52
commit
a56731126d
|
@ -1317,8 +1317,8 @@ func (api *API) serveFlags(_ *http.Request) apiFuncResult {
|
||||||
return apiFuncResult{api.flagsMap, nil, nil, nil}
|
return apiFuncResult{api.flagsMap, nil, nil, nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
// stat holds the information about individual cardinality.
|
// TSDBStat holds the information about individual cardinality.
|
||||||
type stat struct {
|
type TSDBStat struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Value uint64 `json:"value"`
|
Value uint64 `json:"value"`
|
||||||
}
|
}
|
||||||
|
@ -1332,26 +1332,27 @@ type HeadStats struct {
|
||||||
MaxTime int64 `json:"maxTime"`
|
MaxTime int64 `json:"maxTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// tsdbStatus has information of cardinality statistics from postings.
|
// TSDBStatus has information of cardinality statistics from postings.
|
||||||
type tsdbStatus struct {
|
type TSDBStatus struct {
|
||||||
HeadStats HeadStats `json:"headStats"`
|
HeadStats HeadStats `json:"headStats"`
|
||||||
SeriesCountByMetricName []stat `json:"seriesCountByMetricName"`
|
SeriesCountByMetricName []TSDBStat `json:"seriesCountByMetricName"`
|
||||||
LabelValueCountByLabelName []stat `json:"labelValueCountByLabelName"`
|
LabelValueCountByLabelName []TSDBStat `json:"labelValueCountByLabelName"`
|
||||||
MemoryInBytesByLabelName []stat `json:"memoryInBytesByLabelName"`
|
MemoryInBytesByLabelName []TSDBStat `json:"memoryInBytesByLabelName"`
|
||||||
SeriesCountByLabelValuePair []stat `json:"seriesCountByLabelValuePair"`
|
SeriesCountByLabelValuePair []TSDBStat `json:"seriesCountByLabelValuePair"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertStats(stats []index.Stat) []stat {
|
// TSDBStatsFromIndexStats converts a index.Stat slice to a TSDBStat slice.
|
||||||
result := make([]stat, 0, len(stats))
|
func TSDBStatsFromIndexStats(stats []index.Stat) []TSDBStat {
|
||||||
|
result := make([]TSDBStat, 0, len(stats))
|
||||||
for _, item := range stats {
|
for _, item := range stats {
|
||||||
item := stat{Name: item.Name, Value: item.Count}
|
item := TSDBStat{Name: item.Name, Value: item.Count}
|
||||||
result = append(result, item)
|
result = append(result, item)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) serveTSDBStatus(*http.Request) apiFuncResult {
|
func (api *API) serveTSDBStatus(*http.Request) apiFuncResult {
|
||||||
s, err := api.db.Stats("__name__")
|
s, err := api.db.Stats(labels.MetricName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return apiFuncResult{nil, &apiError{errorInternal, err}, nil, nil}
|
return apiFuncResult{nil, &apiError{errorInternal, err}, nil, nil}
|
||||||
}
|
}
|
||||||
|
@ -1369,7 +1370,7 @@ func (api *API) serveTSDBStatus(*http.Request) apiFuncResult {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return apiFuncResult{tsdbStatus{
|
return apiFuncResult{TSDBStatus{
|
||||||
HeadStats: HeadStats{
|
HeadStats: HeadStats{
|
||||||
NumSeries: s.NumSeries,
|
NumSeries: s.NumSeries,
|
||||||
ChunkCount: chunkCount,
|
ChunkCount: chunkCount,
|
||||||
|
@ -1377,10 +1378,10 @@ func (api *API) serveTSDBStatus(*http.Request) apiFuncResult {
|
||||||
MaxTime: s.MaxTime,
|
MaxTime: s.MaxTime,
|
||||||
NumLabelPairs: s.IndexPostingStats.NumLabelPairs,
|
NumLabelPairs: s.IndexPostingStats.NumLabelPairs,
|
||||||
},
|
},
|
||||||
SeriesCountByMetricName: convertStats(s.IndexPostingStats.CardinalityMetricsStats),
|
SeriesCountByMetricName: TSDBStatsFromIndexStats(s.IndexPostingStats.CardinalityMetricsStats),
|
||||||
LabelValueCountByLabelName: convertStats(s.IndexPostingStats.CardinalityLabelStats),
|
LabelValueCountByLabelName: TSDBStatsFromIndexStats(s.IndexPostingStats.CardinalityLabelStats),
|
||||||
MemoryInBytesByLabelName: convertStats(s.IndexPostingStats.LabelValueStats),
|
MemoryInBytesByLabelName: TSDBStatsFromIndexStats(s.IndexPostingStats.LabelValueStats),
|
||||||
SeriesCountByLabelValuePair: convertStats(s.IndexPostingStats.LabelValuePairsStats),
|
SeriesCountByLabelValuePair: TSDBStatsFromIndexStats(s.IndexPostingStats.LabelValuePairsStats),
|
||||||
}, nil, nil, nil}
|
}, nil, nil, nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue