Skip to content
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

Implement deletion based on partially matching labels #1013

Merged
merged 14 commits into from Apr 21, 2022

Conversation

stone-z
Copy link
Contributor

@stone-z stone-z commented Mar 25, 2022

Towards #834. This is an approach which I think feels user-friendly and accomplishes what folks were asking for. Open to suggestions of course, I'm new here.

This PR introduces a new deletion method:

  • DeletePartialMatch(labels Labels) - deletes a metric if all of the given labels and associated values are present in that metric.

It returns the number of metrics which were deleted.

Signed-off-by: Zach Stone <zach@giantswarm.io>
Signed-off-by: Zach Stone <zach@giantswarm.io>
Signed-off-by: Zach Stone <zach@giantswarm.io>
Signed-off-by: Zach Stone <zach@giantswarm.io>
Signed-off-by: Zach Stone <zach@giantswarm.io>
Signed-off-by: Zach Stone <zach@giantswarm.io>
Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Nice! It looks quite good to me however, I personally did not have a code that needs functionality like this. This is why it would be amazing to have opinions from potential users: @taiyang-li @pstibrany

I added a small comment though, I think the DeletePartialMatchLabelValues(values..) semantics is too open. I wonder if DeletePartialMatchLabelValues(name, values ...) make more sense (:

prometheus/vec.go Outdated Show resolved Hide resolved
Signed-off-by: Zach Stone <zach@giantswarm.io>
Signed-off-by: Zach Stone <zach@giantswarm.io>
prometheus/vec_test.go Outdated Show resolved Hide resolved
prometheus/vec.go Outdated Show resolved Hide resolved
Signed-off-by: Zach Stone <zach@giantswarm.io>
Signed-off-by: Zach Stone <zach@giantswarm.io>
prometheus/vec_test.go Outdated Show resolved Hide resolved
prometheus/vec_test.go Outdated Show resolved Hide resolved
prometheus/vec_test.go Outdated Show resolved Hide resolved
prometheus/vec_test.go Outdated Show resolved Hide resolved
prometheus/vec_test.go Outdated Show resolved Hide resolved
prometheus/vec_test.go Outdated Show resolved Hide resolved
@taiyang-li
Copy link

Nice! It looks quite good to me however, I personally did not have a code that needs functionality like this. This is why it would be amazing to have opinions from potential users: @taiyang-li @pstibrany

I added a small comment though, I think the DeletePartialMatchLabelValues(values..) semantics is too open. I wonder if DeletePartialMatchLabelValues(name, values ...) make more sense (:

This is the exact function I needed .

Signed-off-by: Zach Stone <zach@giantswarm.io>
Signed-off-by: Zach Stone <zach@giantswarm.io>
Signed-off-by: Zach Stone <zach@giantswarm.io>
@stone-z
Copy link
Contributor Author

stone-z commented Apr 11, 2022

Ok, I've updated this PR with what I think @beorn7 had in mind. I am open to returning an error if a user passes a curried label to DeletePartialMatch, but I checked and this would actually be different from Delete and DeleteLabelValues, which just return booleans. So I'm happy with this if the maintainers are as well. Thanks for your patience 🙏

@beorn7
Copy link
Member

beorn7 commented Apr 13, 2022

I'm aware, and this is on my review queue, but the queue is very long and progressing slowly. I'll get to this eventually, but feel free to make the call without me.

Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Thanks 💪🏽

Great!

@bwplotka
Copy link
Member

bwplotka commented Apr 13, 2022

I think it's safe to merge as the API got smaller and very sensible, but waiting for your eyes @beorn7 if you want to check it still. I am happy with this (:

Signed-off-by: Zach Stone <zach@giantswarm.io>
Copy link
Member

@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

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

Semantics looks OK to me now.

Copy link
Member

@kakkoyun kakkoyun left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +108 to +110
func (m *MetricVec) DeletePartialMatch(labels Labels) int {
return m.metricMap.deleteByLabels(labels, m.curry)
}
Copy link

Choose a reason for hiding this comment

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

What is the computational complexity of this function? I imagine it is O(metrics count), right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. I hoped to find a constant time implementation but didn't find one (at least at the time)

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.

None yet

6 participants