Skip to content

Conversation

bwplotka
Copy link
Member

@bwplotka bwplotka commented Jun 26, 2024

This attempts to improve readability and consistency of our rw code & tests. For example to make sure conversions from/to model types are well tested.

We can't use generics easily due to details mentioned in Slack and old attempt so I propose we take it slowly and for now clean conversion code by:

  • Move v1 and v2 specific things to corresponding pkgs. This allows us to add methods to proto types which saves us from typos and give bit more readability. This allows to literally consistently duplicate conversion logic.
  • Have prompb/rwcommon for shared proto logic. For now I propose we test the above conversions in one place. The reason is that while having impl hidden in each version is beneficial, hiding tests is bit worse - it can be non-obvious when tests drifts for those. This rwcommon pkg can be also later used for more stuff e.g. shared types or interfaces/generics.

NOTE: For fun I shared one alternative here with generics. I think it's ... bit too much for 2 types, but maybe those generic interfaces would help further on with buildWriteRequest stuff. For just testing, it's too much and complex.

@bwplotka bwplotka force-pushed the rw20-histogram-helpers branch from bcc3595 to 97ffc66 Compare June 26, 2024 10:31
@bwplotka bwplotka marked this pull request as ready for review June 26, 2024 10:32
@bwplotka bwplotka force-pushed the rw20-histogram-helpers branch 3 times, most recently from f8f8535 to c5faeb9 Compare June 26, 2024 11:26
@bwplotka bwplotka force-pushed the rw20-histogram-helpers branch 2 times, most recently from 523097b to b244424 Compare June 28, 2024 07:44
@@ -915,57 +621,6 @@ func LabelProtosToMetric(labelPairs []*prompb.Label) model.Metric {
return metric
}

// LabelProtosToLabels transforms prompb labels into labels. The labels builder
// will be used to build the returned labels.
func LabelProtosToLabels(b *labels.ScratchBuilder, labelPairs []prompb.Label) labels.Labels {
Copy link
Member Author

@bwplotka bwplotka Jun 28, 2024

Choose a reason for hiding this comment

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

This affects #14316 cc @pracucci in some way, by removing this helper from this file.

We moved those methods, and they are accessible via prompb.FromLabels and prompb.TimeSeries.ToLabels. I think it makes things much cleaner and should work for downstream projects. Do you mind double checking if you are happy with this Marco? 🤗 (this PR is against remote-write-2.0 but we will merge this branch to main next week likely)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the ping Bartek. I'm good with this change, thanks.

// NOTE(bwplotka): This file's code is tested in /prompb/rwcommon.

// ToLabels return model labels.Labels from timeseries' remote labels.
func (m TimeSeries) ToLabels(b *labels.ScratchBuilder, _ []string) labels.Labels {
Copy link
Member Author

Choose a reason for hiding this comment

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

FYI @beorn7 @krajorama we cleaned up histogram conversions as it's gets tricky (duplicated) with another proto struct. Would you be happy with flow like this (see PR description).

Copy link
Member

Choose a reason for hiding this comment

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

I guess @krajorama is way deeper into practical considerations here than I, so he should make the call.

@bwplotka
Copy link
Member Author

/prombench main

@prombot
Copy link
Contributor

prombot commented Jun 28, 2024

⏱️ Welcome to Prometheus Benchmarking Tool. ⏱️

Compared versions: PR-14347 and main

After successful deployment, the benchmarking results can be viewed at:

Other Commands:
To stop benchmark: /prombench cancel
To restart benchmark: /prombench restart main

@krajorama krajorama self-requested a review July 1, 2024 08:48
Copy link
Member

@krajorama krajorama left a comment

Choose a reason for hiding this comment

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

Makes sense, I like how the naming is cleaner. We should probably follow the same in Mimir.

I've added some nits. Also there's already some generator functions in tsdb/tsdbutil/histogram.go for generating test histograms, but using your own is fine as well

req.Timeseries[i].Histograms[j].PositiveDeltas = h.PositiveDeltas
req.Timeseries[i].Histograms[j].PositiveCounts = h.PositiveCounts
req.Timeseries[i].Histograms[j].ResetHint = prompb.Histogram_ResetHint(h.ResetHint)
req.Timeseries[i].Histograms[j].Timestamp = h.Timestamp
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a panic() if this is called on a histogram with custome_values filled in. Just to be on the safe side.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Let's add TODOs to conversion code. For this conversion (I simplified it here), it;s only used in tests so we know it's not custom. Let's fix NHCB cases once on main branch?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's on main branch now (:

Copy link
Member Author

Choose a reason for hiding this comment

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

done in 49ab109

@bwplotka
Copy link
Member Author

bwplotka commented Jul 2, 2024

No big diffs in Mem, CPU and latencies:

image

image

image

@bwplotka
Copy link
Member Author

bwplotka commented Jul 2, 2024

/prombench cancel

@prombot
Copy link
Contributor

prombot commented Jul 2, 2024

Benchmark cancel is in progress.

@bwplotka bwplotka force-pushed the rw20-histogram-helpers branch from b244424 to 8a6ce53 Compare July 2, 2024 09:22
…v2 codecs.

Signed-off-by: bwplotka <bwplotka@gmail.com>
@bwplotka bwplotka merged commit f09c645 into remote-write-2.0 Jul 2, 2024
@bwplotka bwplotka deleted the rw20-histogram-helpers branch July 2, 2024 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants