Repository navigation
Conversation
f7f1f84 to
9470ee5
Compare
Created a tool to import data formatted according to the Prometheus exposition format. The tool can be accessed via the TSDB CLI. Addresses #535 Signed-off-by: Dipack P Panjabi <[email protected]> Update PR to comply with changes on master. Signed-off-by: Dipack P Panjabi <[email protected]> Add Importer tool minimal documentation (#1) * Add Importer tool minimal documentation * Reduce a little import file example Update docs. Courtesy of @gillg Signed-off-by: Dipack P Panjabi <[email protected]> Fix stuff because of rebase Signed-off-by: Dipack P Panjabi <[email protected]>
|
|
||
| To learn more about existing integrations with remote storage systems, see the [Integrations documentation](https://prometheus.io/docs/operating/integrations/#remote-endpoints-and-storage). | ||
|
|
||
| ## Database management |
Based on #5887 Thanks for your work so far @dipack95, it helped a lot! Changes on top of @dipack95: * Addressed all reviews components * Use subcommands for different formats * Simplifed block creation, no need to be such complex for first iteration. * Simpliefied and separate concerns. No need to have access to DB. Block * writting is separated as well for ease of benchmarking and test. This will be also needed by @JessicaGreben * Added import support for different formats. * Removed all tests - those had to be pulled over and adjusted ): Signed-off-by: Bartlomiej Plotka <[email protected]>
| ### Import old metrics from file | ||
|
|
||
| The command-line tool `tsdb` contains an `import` command. The goal of this tool is not for a regular backfilling, don't forget prometheus is a pull based system by assumed choice. | ||
| You can use it to restore another prometheus partial dump, or any metrics exported from any system. The only supported input format is [OpenMetrics](https://openmetrics.io/) which is the same as Prometheus exporters exposition. |
There was a problem hiding this comment.
OpenMetrics is not the same as the Prometheus text format, and the below format is not valid OpenMetrics (OM is seconds for timestamps, plus the grouping is invalid).
There was a problem hiding this comment.
Yes this is something I did not touch yet, to be done 👍
| MetricTypeUnknown = "unknown" | ||
| ) | ||
|
|
||
| func (m *MetricType) ParseForOpenMetrics(mtyp string) error { |
There was a problem hiding this comment.
Per-parser code should not live outside each of the respective parser files.
| func (p *Parser) Series() ([]byte, *int64, float64) { | ||
| b, ts, v := p.Parser.Series() | ||
| if ts != nil { | ||
| // OpenMetrics parser has time in nanoseconds. Convert to milliseconds. |
There was a problem hiding this comment.
It's in milliseconds, and that would not be the correct conversion anyway.
There was a problem hiding this comment.
ack, I copied what previous PR had (: Let's fix
| MetricName HeaderType = "metric_name" // Value of "__name__" label. | ||
| LabelName HeaderType = "label_name" // If both labels and metric_name are specified labels are merged. This header can repeat, but label_value is expected as next column. | ||
| LabelValue HeaderType = "label_value" // If both labels and metric_name are specified labels are merged. This header can repeat but label_name is expected to be in previous column. | ||
| Help HeaderType = "help" |
There was a problem hiding this comment.
Why are you taking in any of this? This is about a very simple sample ingestion to the TSDB, not trying to create a brand new fully-fledged exposition format with its own brand new data model. If someone has more complex needs they can use one of the actual exposition formats.
There was a problem hiding this comment.
Can agree. We don't even utilize this data yet, some maybe we can skip now.
| Value HeaderType = "value" | ||
| TimestampMs HeaderType = "timestamp_ms" // Milliseconds from seconds since 1970-01-01 00:00:00 UTC | ||
| MetricName HeaderType = "metric_name" // Value of "__name__" label. | ||
| LabelName HeaderType = "label_name" // If both labels and metric_name are specified labels are merged. This header can repeat, but label_value is expected as next column. |
There was a problem hiding this comment.
It'd seem simpler and more natural to have the column name be the label name.
| logger = log.NewNopLogger() | ||
| } | ||
|
|
||
| level.Info(logger).Log("msg", "started importing input data.") |
There was a problem hiding this comment.
Log messages should start with a capital letter.
| return w.head.Init(math.MinInt64) | ||
| } | ||
|
|
||
| // Appender is not thread-safe. Returned Appender is thread-save however. |
There was a problem hiding this comment.
And it's better to say "goroutine-safe". Or even better:
// Appender must not be called concurrently. The returned Appender, however, can safely be used concurrently.
| omImportCmd = importCmd.Command("openmetrics", "import samples from OpenMetrics input and produce TSDB block. Please refer to the storage docs for more details.") | ||
|
|
||
| csvImportCmd = importCmd.Command("csv", "import samples from CSV input and produce TSDB block. Please refer to the storage docs for more details.") | ||
| csvImportDelimiter = csvImportCmd.Flag("delimiter", "CSV single character for fields delimiting").Default(",").String() |
There was a problem hiding this comment.
This should not be configurable.
There was a problem hiding this comment.
I think it does not harm to allow configuring this (:
There was a problem hiding this comment.
I think there is harm, as it allows for more than one way to do things and thus confusion. Let's support one single CSV format - not N mildly different formats.
There was a problem hiding this comment.
I think it's safe to first go with only one CSV format. However, we do not maintain our own CSV parser but use encoding/csv from the Go standard library. Passing through the option that that parser offers appears sane to me. CSVs with semicolons are frequent enough that I could see the feature request popping up pretty soon.
"One way to do things" is great, but CSV is already not following it. We won't unify the CSV world by not allowing other delimiters in Prometheus.
| importCmd = cli.Command("import", "[Experimental] import samples from input and produce TSDB block. Please refer to the storage docs for more details.") | ||
| importDbPath = importCmd.Flag("output", "output directory for generated block").Default(".").String() | ||
| importFilePath = importCmd.Flag("input-file", "disables reading from input and using file to import samples from. If empty input is required").String() | ||
| importBlockSize = importCmd.Flag("block-size", "The maximum block size. The actual block timestamps will be aligned with Prometheus time ranges.").Default("2h").Hidden().Duration() |
There was a problem hiding this comment.
The help here doesn't seem right.
|
We (in the bug scrub) assume this has been superseded by #7675 and close this. Please re-open if we are wrong. |
|
Reopening as those are two different things: Rule backfilling vs CSV backfilling. |
|
Still happy to have some help / finish it (: Sorry for lag on this. |
beorn7
left a comment
There was a problem hiding this comment.
My plan is to let our intern pick this up in the week of 2020-09-07.
| This format is simple to produce, but not optimized or compressed, so it's normal if your data file is huge. | ||
|
|
||
| Before starting the import process, please verify if there is an overlap between the data you are importing, and what already exists in TSDB. | ||
| If there is an overlap, you will need to shut down TSDB, and restart it with `--storage.tsdb.allow-overlapping-blocks`, else you do not need to shut down TSDB. |
There was a problem hiding this comment.
"else" as in "if the flag is already set" or as in "if there are no overlapping blocks". I guess both, but that could be worded more clearly, e.g.: If there is no overlap or if the flag is already set, no shut-down is required.
|
|
||
| Before starting the import process, please verify if there is an overlap between the data you are importing, and what already exists in TSDB. | ||
| If there is an overlap, you will need to shut down TSDB, and restart it with `--storage.tsdb.allow-overlapping-blocks`, else you do not need to shut down TSDB. | ||
| However, it is recommended you do so anyway. |
There was a problem hiding this comment.
You mean, keep the TSDB shut-down while adding the blocks? This could be worded more explicitly, and perhaps amended with a short explanation why.
| omImportCmd = importCmd.Command("openmetrics", "import samples from OpenMetrics input and produce TSDB block. Please refer to the storage docs for more details.") | ||
|
|
||
| csvImportCmd = importCmd.Command("csv", "import samples from CSV input and produce TSDB block. Please refer to the storage docs for more details.") | ||
| csvImportDelimiter = csvImportCmd.Flag("delimiter", "CSV single character for fields delimiting").Default(",").String() |
There was a problem hiding this comment.
I think it's safe to first go with only one CSV format. However, we do not maintain our own CSV parser but use encoding/csv from the Go standard library. Passing through the option that that parser offers appears sane to me. CSVs with semicolons are frequent enough that I could see the feature request popping up pretty soon.
"One way to do things" is great, but CSV is already not following it. We won't unify the CSV world by not allowing other delimiters in Prometheus.
| return w.head.Init(math.MinInt64) | ||
| } | ||
|
|
||
| // Appender is not thread-safe. Returned Appender is thread-save however. |
There was a problem hiding this comment.
And it's better to say "goroutine-safe". Or even better:
// Appender must not be called concurrently. The returned Appender, however, can safely be used concurrently.
|
Closing this as I believe it is superseded by #7999 |
|
@codesome Why if anyone new is trying to solve the same issue all the previous PRs are immediately closed? |
Based on #5887 Thanks for your work so far @dipack95, it helped a lot!
Changes on top of @dipack95 and above PR:
openmetricspackage and tests 🤗needed by @JessicaGreben
I wanted to create a demo of CSV file import for KubeCon import, so went ahead and tried to help you @dipack95. Hope we can together finish this and add two formats soon 🤗 What do you think of using this (if you think it's ok, please give your feedback!). Feel free to propose changes (PRs) to this branch
tsdb-importso we can have this merged together. Help wanted around tests and benchmarks!cc @krasi-georgiev @JessicaGreben @dipack95 @brian-brazil
WIP (we can do some of those in separate PR)
Signed-off-by: Bartlomiej Plotka [email protected]