Skip to content

Added TSDB import with OpenMetrics and CSV file support. - #7586

Closed
bwplotka wants to merge 2 commits into
masterfrom
tsdb-import
Closed

bwplotka wants to merge 2 commits into
masterfrom
tsdb-import

Conversation

@bwplotka

@bwplotka bwplotka commented Jul 16, 2020 •

Copy link
Copy Markdown
Member

Based on #5887 Thanks for your work so far @dipack95, it helped a lot!

Changes on top of @dipack95 and above PR:

  • Addressed all reviews components
  • Used subcommands for different formats
  • Simplified block creation, no need to be such complex for the first iteration.
  • Simplified OpenMetrics parsing from io.Reader, the previous implementation was over-allocating a lot, I think this might be simple start. @dipack95 please help to finish openmetrics package and tests 🤗
  • Simplified and separate concerns. No need to have access to DB. Block
    • Block Writing is separated from parsing 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 ):

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-import so 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)

  • Adjust Docs
  • Openmetrics package (parsing from io.Reader and tests)
  • CSV parser support for different entries than series
  • Tests
  • Benchmark.

Signed-off-by: Bartlomiej Plotka [email protected]

@bwplotka
bwplotka force-pushed the tsdb-import branch 2 times, most recently from f7f1f84 to 9470ee5 Compare July 16, 2020 09:16
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]>
Comment thread docs/storage.md

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To be adjusted

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]>
Comment thread docs/storage.md
### 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes this is something I did not touch yet, to be done 👍

MetricTypeUnknown = "unknown"
)

func (m *MetricType) ParseForOpenMetrics(mtyp string) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Per-parser code should not live outside each of the respective parser files.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ack

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's in milliseconds, and that would not be the correct conversion anyway.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ack, I copied what previous PR had (: Let's fix

Comment thread tsdb/importer/csv/csv.go
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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Can agree. We don't even utilize this data yet, some maybe we can skip now.

Comment thread tsdb/importer/csv/csv.go
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It'd seem simpler and more natural to have the column name be the label name.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

makes sense

Comment thread tsdb/importer/import.go
logger = log.NewNopLogger()
}

level.Info(logger).Log("msg", "started importing input data.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

save?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread tsdb/cmd/tsdb/main.go
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()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should not be configurable.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it does not harm to allow configuring this (:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread tsdb/cmd/tsdb/main.go
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()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The help here doesn't seem right.

@beorn7

beorn7 commented Aug 17, 2020

Copy link
Copy Markdown
Contributor

We (in the bug scrub) assume this has been superseded by #7675 and close this. Please re-open if we are wrong.

@beorn7 beorn7 closed this Aug 17, 2020
@bwplotka

Copy link
Copy Markdown
Member Author

Reopening as those are two different things: Rule backfilling vs CSV backfilling.

@bwplotka bwplotka reopened this Aug 17, 2020
@bwplotka

Copy link
Copy Markdown
Member Author

Still happy to have some help / finish it (: Sorry for lag on this.

@beorn7 beorn7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My plan is to let our intern pick this up in the week of 2020-09-07.

Comment thread docs/storage.md
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"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.

Comment thread docs/storage.md

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread tsdb/cmd/tsdb/main.go
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()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@codesome

codesome commented Oct 8, 2020

Copy link
Copy Markdown
Member

Closing this as I believe it is superseded by #7999

@codesome codesome closed this Oct 8, 2020
@omron93

omron93 commented Oct 9, 2020

Copy link
Copy Markdown

@codesome Why if anyone new is trying to solve the same issue all the previous PRs are immediately closed?
#7999 is a 'Draft' PR with most builds failing, this PR was working with most test jobs passing... so I think the current process of handling PRs isn't helping to solve the backfilling issue :-(

@beorn7

beorn7 commented Oct 9, 2020

Copy link
Copy Markdown
Contributor

The people working on #7999 and who have worked on this one are all collaborating closely. They have collectively decided it's best to use this PR as a PoC implementation but do the real one in a new PR, which is #7999.

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.

5 participants