tsdb: Expose total number of label pairs in head in TSDB stats page (#8343)

* tsdb: Expose total number of label pairs in head

Signed-off-by: Nguyen Le Vu Long <vulongvn98@gmail.com>

* fix: add comment for NumLabelPairs

Signed-off-by: Nguyen Le Vu Long <vulongvn98@gmail.com>

* fix: remove comment

Signed-off-by: Nguyen Le Vu Long <vulongvn98@gmail.com>
This commit is contained in:
Nguyen Le Vu Long 2021-01-07 13:41:32 +07:00 committed by GitHub
parent 0954026b9a
commit cd1dafc2fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 10 deletions

View file

@ -115,6 +115,7 @@ type PostingsStats struct {
CardinalityLabelStats []Stat CardinalityLabelStats []Stat
LabelValueStats []Stat LabelValueStats []Stat
LabelValuePairsStats []Stat LabelValuePairsStats []Stat
NumLabelPairs int
} }
// Stats calculates the cardinality statistics from postings. // Stats calculates the cardinality statistics from postings.
@ -128,6 +129,7 @@ func (p *MemPostings) Stats(label string) *PostingsStats {
labels := &maxHeap{} labels := &maxHeap{}
labelValueLength := &maxHeap{} labelValueLength := &maxHeap{}
labelValuePairs := &maxHeap{} labelValuePairs := &maxHeap{}
numLabelPairs := 0
metrics.init(maxNumOfRecords) metrics.init(maxNumOfRecords)
labels.init(maxNumOfRecords) labels.init(maxNumOfRecords)
@ -139,6 +141,7 @@ func (p *MemPostings) Stats(label string) *PostingsStats {
continue continue
} }
labels.push(Stat{Name: n, Count: uint64(len(e))}) labels.push(Stat{Name: n, Count: uint64(len(e))})
numLabelPairs += len(e)
size = 0 size = 0
for name, values := range e { for name, values := range e {
if n == label { if n == label {
@ -157,6 +160,7 @@ func (p *MemPostings) Stats(label string) *PostingsStats {
CardinalityLabelStats: labels.get(), CardinalityLabelStats: labels.get(),
LabelValueStats: labelValueLength.get(), LabelValueStats: labelValueLength.get(),
LabelValuePairsStats: labelValuePairs.get(), LabelValuePairsStats: labelValuePairs.get(),
NumLabelPairs: numLabelPairs,
} }
} }

View file

@ -1236,10 +1236,11 @@ type stat struct {
// HeadStats has information about the TSDB head. // HeadStats has information about the TSDB head.
type HeadStats struct { type HeadStats struct {
NumSeries uint64 `json:"numSeries"` NumSeries uint64 `json:"numSeries"`
ChunkCount int64 `json:"chunkCount"` NumLabelPairs int `json:"numLabelPairs"`
MinTime int64 `json:"minTime"` ChunkCount int64 `json:"chunkCount"`
MaxTime int64 `json:"maxTime"` MinTime int64 `json:"minTime"`
MaxTime int64 `json:"maxTime"`
} }
// tsdbStatus has information of cardinality statistics from postings. // tsdbStatus has information of cardinality statistics from postings.
@ -1281,10 +1282,11 @@ 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,
MinTime: s.MinTime, MinTime: s.MinTime,
MaxTime: s.MaxTime, MaxTime: s.MaxTime,
NumLabelPairs: s.IndexPostingStats.NumLabelPairs,
}, },
SeriesCountByMetricName: convertStats(s.IndexPostingStats.CardinalityMetricsStats), SeriesCountByMetricName: convertStats(s.IndexPostingStats.CardinalityMetricsStats),
LabelValueCountByLabelName: convertStats(s.IndexPostingStats.CardinalityLabelStats), LabelValueCountByLabelName: convertStats(s.IndexPostingStats.CardinalityLabelStats),

View file

@ -15,6 +15,7 @@ const fakeTSDBStatusResponse: {
data: { data: {
headStats: { headStats: {
numSeries: 508, numSeries: 508,
numLabelPairs: 1234,
chunkCount: 937, chunkCount: 937,
minTime: 1591516800000, minTime: 1591516800000,
maxTime: 1598896800143, maxTime: 1598896800143,
@ -85,7 +86,7 @@ describe('TSDB Stats', () => {
.at(0) .at(0)
.find('tbody') .find('tbody')
.find('td'); .find('td');
['508', '937', '2020-06-07T08:00:00.000Z (1591516800000)', '2020-08-31T18:00:00.143Z (1598896800143)'].forEach( ['508', '937', '1234', '2020-06-07T08:00:00.000Z (1591516800000)', '2020-08-31T18:00:00.143Z (1598896800143)'].forEach(
(value, i) => { (value, i) => {
expect(headStats.at(i).text()).toEqual(value); expect(headStats.at(i).text()).toEqual(value);
} }

View file

@ -14,6 +14,7 @@ interface Stats {
interface HeadStats { interface HeadStats {
numSeries: number; numSeries: number;
numLabelPairs: number;
chunkCount: number; chunkCount: number;
minTime: number; minTime: number;
maxTime: number; maxTime: number;
@ -35,10 +36,11 @@ export const TSDBStatusContent: FC<TSDBMap> = ({
seriesCountByLabelValuePair, seriesCountByLabelValuePair,
}) => { }) => {
const unixToTime = (unix: number): string => new Date(unix).toISOString(); const unixToTime = (unix: number): string => new Date(unix).toISOString();
const { chunkCount, numSeries, minTime, maxTime } = headStats; const { chunkCount, numSeries, numLabelPairs, minTime, maxTime } = headStats;
const stats = [ const stats = [
{ header: 'Number of Series', value: numSeries }, { header: 'Number of Series', value: numSeries },
{ header: 'Number of Chunks', value: chunkCount }, { header: 'Number of Chunks', value: chunkCount },
{ header: 'Number of Label Pairs', value: numLabelPairs },
{ header: 'Current Min Time', value: `${unixToTime(minTime)} (${minTime})` }, { header: 'Current Min Time', value: `${unixToTime(minTime)} (${minTime})` },
{ header: 'Current Max Time', value: `${unixToTime(maxTime)} (${maxTime})` }, { header: 'Current Max Time', value: `${unixToTime(maxTime)} (${maxTime})` },
]; ];