Skip to content

ingest-storage: Add consumer support for a new record version 2, based on Remote Write 2.0 #11406

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

Merged
merged 14 commits into from
May 23, 2025

Conversation

alexweav
Copy link
Contributor

@alexweav alexweav commented May 6, 2025

What this PR does

Introduces a new record version V2, and implements consumer-side support for it.

It's inspired by Prometheus Remote Write 2.0, but not strictly compatible with it. A notable difference is that the symbol refs are shifted up by 64. This reserves space for a future common symbols table, allowing us to completely avoid sending certain commonly used symbols through Kafka.

The format is internal to Mimir, it doesn't need to exactly match any external standard. Aside from within test code, there is currently no way to produce records of the V2 format. Therefore, we're still able to iterate on the format in the future and make breaking changes. I'm not adding this to the changelog for that reason; when we decide to "lock down" the format, the changelog will be updated at that time.

The implementation heavily leverages @krajorama's work in #11100 and inherits several optimizations from it.

Which issue(s) this PR fixes or relates to

Rel https://github.com/grafana/mimir-squad/issues/2253

Checklist

  • Tests updated.
  • Documentation added.
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • about-versioning.md updated with experimental features.

})
}

func BenchmarkDeserializeRecordContent(b *testing.B) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For those curious, the v2 benchmark gives one extra allocation per timeseries over v1. This PR doesn't try to add any optimizations beyond what's already there. This is on par with my initial test results.

go test ./pkg/storage/ingest/... -run ^$ -bench BenchmarkDeserializeRecordContent -benchtime=1000x -benchmem
BenchmarkDeserializeRecordContent/deserialize_v1-16         	    1000	   5242524 ns/op	12498059 B/op	   39975 allocs/op
BenchmarkDeserializeRecordContent/deserialize_v2-16         	    1000	   4888400 ns/op	12886412 B/op	   49978 allocs/op

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use benchstat next time to compare benchmarks 😉 Run each benchmark at least 6 times to get better results from benchstat.

@@ -66,7 +66,7 @@ func (c pusherConsumer) Consume(ctx context.Context, records []record) (returnEr
}(time.Now())

type parsedRecord struct {
*mimirpb.WriteRequest
*mimirpb.PreallocWriteRequest
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR depends on #11393. I inlined those changes into this PR until that's merged.

This is logically equivalent to:

WriteRequest: &mimirpb.WriteRequest{
	Timeseries: mimirpb.PreallocTimeseriesSliceFromPool(),
},

PreallocWriteRequest.Unmarshal() calls PreallocTimeseriesSliceFromPool()

@alexweav alexweav changed the title ingest-storage: Add consumer support for a new record version 2, based on RW 2.0 ingest-storage: Add consumer support for a new record version 2, based on Remote Write 2.0 May 6, 2025
Copy link
Collaborator

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

Overall LGTM (modulo a comment about the symbols builder that I think is wrong). Waiting for the rebase once the other PR is merged.

})
}

func BenchmarkDeserializeRecordContent(b *testing.B) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use benchstat next time to compare benchmarks 😉 Run each benchmark at least 6 times to get better results from benchstat.

@alexweav alexweav force-pushed the alexweav/rw-v2-consumer branch from c28c1f3 to f24b2e6 Compare May 19, 2025 15:53
@alexweav alexweav marked this pull request as ready for review May 19, 2025 16:01
@alexweav alexweav requested a review from a team as a code owner May 19, 2025 16:01
@alexweav alexweav force-pushed the alexweav/rw-v2-consumer branch from f24b2e6 to d638be4 Compare May 23, 2025 21:20
@alexweav alexweav merged commit 57c00a5 into main May 23, 2025
30 checks passed
@alexweav alexweav deleted the alexweav/rw-v2-consumer branch May 23, 2025 22:00
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