Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promtool: Add support for compaction analysis #8940

Merged
merged 2 commits into from
Jul 2, 2021

Conversation

fpetkovski
Copy link
Contributor

@fpetkovski fpetkovski commented Jun 15, 2021

This commit extends the promtool tsdb analyze command to help
troubleshoot high Prometheus disk usage. The command will now plot a distribution of
how full chunks are relative to the maximum capacity of 120 samples per chunk.

Here is a sample output:

$ promtool tsdb analyze

...

Fullness: Amount of chunks
     10%: #############
     20%: ######
     30%: 
     40%: 
     50%: #####################################
     60%: ######
     70%: 
     80%: 
     90%: 
    100%: ###################################

@@ -142,6 +142,10 @@ func main() {
dumpMinTime := tsdbDumpCmd.Flag("min-time", "Minimum timestamp to dump.").Default(strconv.FormatInt(math.MinInt64, 10)).Int64()
dumpMaxTime := tsdbDumpCmd.Flag("max-time", "Maximum timestamp to dump.").Default(strconv.FormatInt(math.MaxInt64, 10)).Int64()

tsdbAnalyzeCompaction := tsdbCmd.Command("analyze-compaction", "Plot a distribution of how full TSDB chunks are, relative to the maximum capacity of 120 samples.")
analyzeCompactionDB := tsdbAnalyzeCompaction.Arg("db path", "Database path (default is "+defaultDBPath+").").Default(defaultDBPath).String()
analyzeCompactionBlockID := tsdbAnalyzeCompaction.Arg("block ID", "The TSDB block to analyze").Default("").String()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also consider adding this analysis to the existing tsdb analyze command.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO it would be fit in the scope of tsdb analyze but lets see what others think :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgl do you have any thoughts on this one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense to include it to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 can we merge to tsdb analyze then? 🤗

@fpetkovski fpetkovski force-pushed the promtool-analyze-compaction branch 3 times, most recently from ecbac81 to ee54a9c Compare June 15, 2021 10:54
@simonpasquier simonpasquier requested a review from dgl June 22, 2021 15:14
@fpetkovski fpetkovski changed the title Extend promtool to support compaction analysis Promtool: Add support for compaction analysis Jun 24, 2021
@bwplotka
Copy link
Member

PTAL @codesome @cstyan , I will look in my free time too! 🙈

Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, LGTM when added to tsdb analyze (:

@@ -142,6 +142,10 @@ func main() {
dumpMinTime := tsdbDumpCmd.Flag("min-time", "Minimum timestamp to dump.").Default(strconv.FormatInt(math.MinInt64, 10)).Int64()
dumpMaxTime := tsdbDumpCmd.Flag("max-time", "Maximum timestamp to dump.").Default(strconv.FormatInt(math.MaxInt64, 10)).Int64()

tsdbAnalyzeCompaction := tsdbCmd.Command("analyze-compaction", "Plot a distribution of how full TSDB chunks are, relative to the maximum capacity of 120 samples.")
analyzeCompactionDB := tsdbAnalyzeCompaction.Arg("db path", "Database path (default is "+defaultDBPath+").").Default(defaultDBPath).String()
analyzeCompactionBlockID := tsdbAnalyzeCompaction.Arg("block ID", "The TSDB block to analyze").Default("").String()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 can we merge to tsdb analyze then? 🤗

@fpetkovski fpetkovski force-pushed the promtool-analyze-compaction branch 5 times, most recently from 0d5fe71 to 00bcde1 Compare July 2, 2021 06:34
@fpetkovski
Copy link
Contributor Author

fpetkovski commented Jul 2, 2021

@bwplotka @dgl the compaction analysis should now be merged into the tsdb analyze command. Changed the commit message and PR description to reflect this change.

Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! LGTM, just small tiny nits.

Plus: Can we mention new functionality in tsdb analysis command help?


fmt.Printf("\nCompaction analysis:\n")
fmt.Println("Fullness: Amount of chunks")
// Normalize absolute counts to percentages and print them out
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Normalize absolute counts to percentages and print them out
// Normalize absolute counts to percentages and print them out.

return err
}
chunkSize := math.Min(float64(chk.NumSamples()), maxSamplesPerChunk)
// Calculate the bucket for the chunk and increment it in the histogram
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Calculate the bucket for the chunk and increment it in the histogram
// Calculate the bucket for the chunk and increment it in the histogram.

}

for _, chk := range chks {
// Load the actual data of the chunk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Load the actual data of the chunk
// Load the actual data of the chunk.

}

func analyzeCompaction(block tsdb.BlockReader, indexr tsdb.IndexReader) (err error) {
postingsr, err := indexr.Postings("", "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
postingsr, err := indexr.Postings("", "")
postingsr, err := indexr.Postings(index.AllPostingsKey())

This commit extends the promtool tsdb analyze command to help
troubleshoot high Prometheus disk usage. The command now plots a
distribution of how full chunks are relative to the maximum capacity of
120 samples per chunk.

Signed-off-by: fpetkovski <filip.petkovsky@gmail.com>
@fpetkovski fpetkovski force-pushed the promtool-analyze-compaction branch from 3a7828d to 0f47b5f Compare July 2, 2021 09:04
Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing ;p

cmd/promtool/tsdb.go Outdated Show resolved Hide resolved
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
@bwplotka bwplotka merged commit 7c125aa into prometheus:main Jul 2, 2021
@bwplotka
Copy link
Member

bwplotka commented Jul 2, 2021

Thanks!

@roidelapluie
Copy link
Member

roidelapluie commented Jul 5, 2021

This pull request seems a massive regression on the time spent by tsdb analysis, as it now read the chunks. I think we should put this option behind a flag.

@fpetkovski
Copy link
Contributor Author

Hi @roidelapluie, thanks for the review. What do you think about an --extended flag which would enable the compaction analysis?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants