Skip to content

Introduce TSDB changes for appending metadata to the WAL#10972

Merged
codesome merged 43 commits intoprometheus:mainfrom
tpaschalis:wal-store-metadata-tsdb-only
Jul 19, 2022
Merged

Introduce TSDB changes for appending metadata to the WAL#10972
codesome merged 43 commits intoprometheus:mainfrom
tpaschalis:wal-store-metadata-tsdb-only

Conversation

@tpaschalis
Copy link
Contributor

@tpaschalis tpaschalis commented Jul 4, 2022

This is a rehash of the recent PR #10312 for appending metadata to the WAL, but focusing on the TSDB-related changes only.

It includes a new storage format in the WAL, the changes to the Appender interface in the Storage package, stubbing all the implementations, as well testing that the encoding/decoding functionality works as intended.

Copy link
Member

@codesome codesome left a comment

Choose a reason for hiding this comment

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

This is a first pass re-review of some parts. Mostly nits. I am left with the checkpoint code and the unit tests to review. I think we can remove it out of the draft.

Comment on lines +255 to +264
// MetadataAppender provides an interface for associating metadata to stored series.
type MetadataAppender interface {
// AppendMetadata appends a metadata entry for the given series and labels.
// A series reference number is returned which can be used to modify the
// metadata of the given series in the same or later transactions.
// Returned reference numbers are ephemeral and may be rejected in calls
// to AppendMetadata() at any point. If the series does not exist, AppendMetadata
// returns an error.
// If the reference is 0 it must not be used for caching.
AppendMetadata(ref SeriesRef, l labels.Labels, m metadata.Metadata) (SeriesRef, error)
Copy link
Member

Choose a reason for hiding this comment

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

How about this? Because we are not appending metadata and storing a history of it. We are just updating it in-place.

Suggested change
// MetadataAppender provides an interface for associating metadata to stored series.
type MetadataAppender interface {
// AppendMetadata appends a metadata entry for the given series and labels.
// A series reference number is returned which can be used to modify the
// metadata of the given series in the same or later transactions.
// Returned reference numbers are ephemeral and may be rejected in calls
// to AppendMetadata() at any point. If the series does not exist, AppendMetadata
// returns an error.
// If the reference is 0 it must not be used for caching.
AppendMetadata(ref SeriesRef, l labels.Labels, m metadata.Metadata) (SeriesRef, error)
// MetadataUpdater provides an interface for associating metadata to stored series.
type MetadataUpdater interface {
// UpdateMetadata updates the metadata entry for the given series and labels.
// A series reference number is returned which can be used to modify the
// metadata of the given series in the same or later transactions.
// Returned reference numbers are ephemeral and may be rejected in calls
// to AppendMetadata() at any point. If the series does not exist, AppendMetadata
// returns an error.
// If the reference is 0 it must not be used for caching.
UpdateMetadata(ref SeriesRef, l labels.Labels, m metadata.Metadata) (SeriesRef, error)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, there's the same argument to be made about Exemplars as well right? I can get behind this change if you feel strongly about it, but (personally) I prefer how the current name works to extend the Appender interface.

Copy link
Member

Choose a reason for hiding this comment

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

You actually do append exemplars and don't update it in-place. You can have exemplars over time, not just the last one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it but couldn't think of a better name, so let's go with your idea ^^

Copy link
Contributor Author

@tpaschalis tpaschalis Jul 15, 2022

Choose a reason for hiding this comment

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

FYI FWIW the same name is also used in the pre-existing code on the remote package, for the current implementation of sending metadata via the QueueManager

https://github.com/prometheus/prometheus/blob/main/storage/remote/metadata_watcher.go#L28-L31

Copy link
Contributor Author

@tpaschalis tpaschalis Jul 15, 2022

Choose a reason for hiding this comment

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

Implemented in d86d5f7 :)

@codesome codesome marked this pull request as ready for review July 12, 2022 14:13
Copy link
Member

@codesome codesome left a comment

Choose a reason for hiding this comment

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

Nice work! While reading the test in db_test.go I realised that the behaviour of AppendMetadata when we use it to update the metadata of the same series more than once in the same transaction can be non-deterministic (like we can tell how it works, for a user it is non-deterministic). Should we document that?

Like if a series s1 had m1 meta already. And then in a transaction we do 3 updates m3 m2 m1 in order in the same transaction (i.e. before commit), then the meta m2 will be attached to s1 and not m1, while the user would expect m1.

repl := 0
for _, m := range metadata {
if keep(m.Ref) {
latestMetadataMap[m.Ref] = m
Copy link
Member

Choose a reason for hiding this comment

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

Note for future: once we have plugged in the scraping, we should run prombench on it and see if there are memory usage spikes after compactions when this checkpoint runs.

Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
When we're setting metadata entries in the scrapeCace, we're using the
p.Help(), p.Unit(), p.Type() helpers, which retrieve the series name and
use it as the cache key. When checking for cache entries though, we used
p.Series() as the key, which included the metric name _with_ its labels.
That meant that we were never actually hitting the cache. We're fixing
this by utiling the __name__ internal label for correctly getting the
cache entries after they've been set by setHelp(), setType() or
setUnit().

Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
…dMetadata

Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
…a replay

Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
…taUpdater/UpdateMetadata

Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
@tpaschalis tpaschalis force-pushed the wal-store-metadata-tsdb-only branch from 742c916 to 83fe62c Compare July 18, 2022 12:21
Copy link
Member

@codesome codesome left a comment

Choose a reason for hiding this comment

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

Last set of comments on the tests

Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
@codesome codesome enabled auto-merge (squash) July 19, 2022 08:42
@codesome codesome merged commit d1122e0 into prometheus:main Jul 19, 2022
@codesome
Copy link
Member

I merged this PR as an enabler for the scraping and remote-write part. This in itself adds very minimal overhead to the TSDB (additional field in the series struct) until the scraping is connected to it and TSDB starts storing metadata. This can be reverted easily if required.

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.

2 participants