Rename Delete / DeleteLabelValues → Remove / RemoveLabelValue

For metric vectors, that is.

This it to bring client_golang in line with the client library
guidelines. See #218.

Signed-off-by: beorn7 <beorn@soundcloud.com>
This commit is contained in:
beorn7 2018-10-16 15:12:52 +02:00
parent f53420cd1d
commit c94f67cd07
7 changed files with 83 additions and 83 deletions

View File

@ -154,8 +154,8 @@ func NewCounterVec(opts CounterOpts, labelNames []string) *CounterVec {
// SummaryVec example.
//
// Keeping the Counter for later use is possible (and should be considered if
// performance is critical), but keep in mind that Clear, DeleteLabelValues and
// Delete can be used to delete the Counter from the CounterVec. In that case,
// performance is critical), but keep in mind that Clear, RemoveLabelValues and
// Remove can be used to remove the Counter from the CounterVec. In that case,
// the Counter will still exist, but it will not be exported anymore, even if a
// Counter with the same label values is created later.
//

View File

@ -109,13 +109,13 @@ func ExampleCounterVec() {
for i := 0; i < 1000000; i++ {
m.Inc()
}
// Delete a metric from the vector. If you have previously kept a handle
// Remove a metric from the vector. If you have previously kept a handle
// to that metric (as above), future updates via that handle will go
// unseen (even if you re-create a metric with the same label set
// later).
httpReqs.DeleteLabelValues("200", "GET")
httpReqs.RemoveLabelValues("200", "GET")
// Same thing with the more verbose Labels syntax.
httpReqs.Delete(prometheus.Labels{"method": "GET", "code": "200"})
httpReqs.Remove(prometheus.Labels{"method": "GET", "code": "200"})
}
func ExampleRegister() {

View File

@ -165,8 +165,8 @@ func NewGaugeVec(opts GaugeOpts, labelNames []string) *GaugeVec {
// SummaryVec example.
//
// Keeping the Gauge for later use is possible (and should be considered if
// performance is critical), but keep in mind that Reset, DeleteLabelValues and
// Delete can be used to delete the Gauge from the GaugeVec. In that case, the
// performance is critical), but keep in mind that Clear, RemoveLabelValues and
// Remove can be used to remove the Gauge from the GaugeVec. In that case, the
// Gauge will still exist, but it will not be exported anymore, even if a
// Gauge with the same label values is created later. See also the CounterVec
// example.
@ -241,7 +241,7 @@ func (v *GaugeVec) With(labels Labels) Gauge {
// The metrics contained in the GaugeVec are shared between the curried and
// uncurried vectors. They are just accessed differently. Curried and uncurried
// vectors behave identically in terms of collection. Only one must be
// registered with a given registry (usually the uncurried version). The Reset
// registered with a given registry (usually the uncurried version). The Clear
// method deletes all metrics, even if called on a curried vector.
func (v *GaugeVec) CurryWith(labels Labels) (*GaugeVec, error) {
vec, err := v.curryWith(labels)

View File

@ -409,16 +409,16 @@ func NewHistogramVec(opts HistogramOpts, labelNames []string) *HistogramVec {
// values (same order as the VariableLabels in Desc). If that combination of
// label values is accessed for the first time, a new Histogram is created.
//
// It is possible to call this method without using the returned Histogram to only
// create the new Histogram but leave it at its starting value, a Histogram without
// any observations.
// It is possible to call this method without using the returned Histogram to
// only create the new Histogram but leave it at its starting value, a Histogram
// without any observations.
//
// Keeping the Histogram for later use is possible (and should be considered if
// performance is critical), but keep in mind that Clear, DeleteLabelValues and
// Delete can be used to delete the Histogram from the HistogramVec. In that case, the
// Histogram will still exist, but it will not be exported anymore, even if a
// Histogram with the same label values is created later. See also the CounterVec
// example.
// performance is critical), but keep in mind that Clear, RemoveLabelValues and
// Remove can be used to remove the Histogram from the HistogramVec. In that
// case, the Histogram will still exist, but it will not be exported anymore,
// even if a Histogram with the same label values is created later. See also the
// CounterVec example.
//
// An error is returned if the number of label values is not the same as the
// number of VariableLabels in Desc (minus any curried labels).

View File

@ -426,8 +426,8 @@ func NewSummaryVec(opts SummaryOpts, labelNames []string) *SummaryVec {
// any observations.
//
// Keeping the Summary for later use is possible (and should be considered if
// performance is critical), but keep in mind that Clear, DeleteLabelValues and
// Delete can be used to delete the Summary from the SummaryVec. In that case,
// performance is critical), but keep in mind that Clear, RemoveLabelValues and
// Remove can be used to remove the Summary from the SummaryVec. In that case,
// the Summary will still exist, but it will not be exported anymore, even if a
// Summary with the same label values is created later. See also the CounterVec
// example.

View File

@ -48,9 +48,9 @@ func newMetricVec(desc *Desc, newMetric func(lvs ...string) Metric) *metricVec {
}
}
// DeleteLabelValues removes the metric where the variable labels are the same
// RemoveLabelValues removes the metric where the variable labels are the same
// as those passed in as labels (same order as the VariableLabels in Desc). It
// returns true if a metric was deleted.
// returns true if a metric was removed.
//
// It is not an error if the number of label values is not the same as the
// number of VariableLabels in Desc. However, such inconsistent label count can
@ -58,37 +58,37 @@ func newMetricVec(desc *Desc, newMetric func(lvs ...string) Metric) *metricVec {
// case.
//
// Note that for more than one label value, this method is prone to mistakes
// caused by an incorrect order of arguments. Consider Delete(Labels) as an
// caused by an incorrect order of arguments. Consider Remove(Labels) as an
// alternative to avoid that type of mistake. For higher label numbers, the
// latter has a much more readable (albeit more verbose) syntax, but it comes
// with a performance overhead (for creating and processing the Labels map).
// See also the CounterVec example.
func (m *metricVec) DeleteLabelValues(lvs ...string) bool {
func (m *metricVec) RemoveLabelValues(lvs ...string) bool {
h, err := m.hashLabelValues(lvs)
if err != nil {
return false
}
return m.metricMap.deleteByHashWithLabelValues(h, lvs, m.curry)
return m.metricMap.removeByHashWithLabelValues(h, lvs, m.curry)
}
// Delete deletes the metric where the variable labels are the same as those
// passed in as labels. It returns true if a metric was deleted.
// Remove removes the metric where the variable labels are the same as those
// passed in as labels. It returns true if a metric was removed.
//
// It is not an error if the number and names of the Labels are inconsistent
// with those of the VariableLabels in Desc. However, such inconsistent Labels
// can never match an actual metric, so the method will always return false in
// that case.
//
// This method is used for the same purpose as DeleteLabelValues(...string). See
// This method is used for the same purpose as RemoveLabelValues(...string). See
// there for pros and cons of the two methods.
func (m *metricVec) Delete(labels Labels) bool {
func (m *metricVec) Remove(labels Labels) bool {
h, err := m.hashLabels(labels)
if err != nil {
return false
}
return m.metricMap.deleteByHashWithLabels(h, labels, m.curry)
return m.metricMap.removeByHashWithLabels(h, labels, m.curry)
}
func (m *metricVec) curryWith(labels Labels) (*metricVec, error) {
@ -234,7 +234,7 @@ func (m *metricMap) Collect(ch chan<- Metric) {
}
}
// Clear deletes all metrics in this vector.
// Clear removes all metrics from this vector.
func (m *metricMap) Clear() {
m.mtx.Lock()
defer m.mtx.Unlock()
@ -244,10 +244,10 @@ func (m *metricMap) Clear() {
}
}
// deleteByHashWithLabelValues removes the metric from the hash bucket h. If
// removeByHashWithLabelValues removes the metric from the hash bucket h. If
// there are multiple matches in the bucket, use lvs to select a metric and
// remove only that metric.
func (m *metricMap) deleteByHashWithLabelValues(
func (m *metricMap) removeByHashWithLabelValues(
h uint64, lvs []string, curry []curriedLabelValue,
) bool {
m.mtx.Lock()
@ -271,10 +271,10 @@ func (m *metricMap) deleteByHashWithLabelValues(
return true
}
// deleteByHashWithLabels removes the metric from the hash bucket h. If there
// removeByHashWithLabels removes the metric from the hash bucket h. If there
// are multiple matches in the bucket, use lvs to select a metric and remove
// only that metric.
func (m *metricMap) deleteByHashWithLabels(
func (m *metricMap) removeByHashWithLabels(
h uint64, labels Labels, curry []curriedLabelValue,
) bool {
m.mtx.Lock()

View File

@ -20,7 +20,7 @@ import (
dto "github.com/prometheus/client_model/go"
)
func TestDelete(t *testing.T) {
func TestRemove(t *testing.T) {
vec := NewGaugeVec(
GaugeOpts{
Name: "test",
@ -28,10 +28,10 @@ func TestDelete(t *testing.T) {
},
[]string{"l1", "l2"},
)
testDelete(t, vec)
testRemove(t, vec)
}
func TestDeleteWithCollisions(t *testing.T) {
func TestRemoveWithCollisions(t *testing.T) {
vec := NewGaugeVec(
GaugeOpts{
Name: "test",
@ -41,40 +41,40 @@ func TestDeleteWithCollisions(t *testing.T) {
)
vec.hashAdd = func(h uint64, s string) uint64 { return 1 }
vec.hashAddByte = func(h uint64, b byte) uint64 { return 1 }
testDelete(t, vec)
testRemove(t, vec)
}
func testDelete(t *testing.T, vec *GaugeVec) {
if got, want := vec.Delete(Labels{"l1": "v1", "l2": "v2"}), false; got != want {
func testRemove(t *testing.T, vec *GaugeVec) {
if got, want := vec.Remove(Labels{"l1": "v1", "l2": "v2"}), false; got != want {
t.Errorf("got %v, want %v", got, want)
}
vec.With(Labels{"l1": "v1", "l2": "v2"}).(Gauge).Set(42)
if got, want := vec.Delete(Labels{"l1": "v1", "l2": "v2"}), true; got != want {
if got, want := vec.Remove(Labels{"l1": "v1", "l2": "v2"}), true; got != want {
t.Errorf("got %v, want %v", got, want)
}
if got, want := vec.Delete(Labels{"l1": "v1", "l2": "v2"}), false; got != want {
if got, want := vec.Remove(Labels{"l1": "v1", "l2": "v2"}), false; got != want {
t.Errorf("got %v, want %v", got, want)
}
vec.With(Labels{"l1": "v1", "l2": "v2"}).(Gauge).Set(42)
if got, want := vec.Delete(Labels{"l2": "v2", "l1": "v1"}), true; got != want {
if got, want := vec.Remove(Labels{"l2": "v2", "l1": "v1"}), true; got != want {
t.Errorf("got %v, want %v", got, want)
}
if got, want := vec.Delete(Labels{"l2": "v2", "l1": "v1"}), false; got != want {
if got, want := vec.Remove(Labels{"l2": "v2", "l1": "v1"}), false; got != want {
t.Errorf("got %v, want %v", got, want)
}
vec.With(Labels{"l1": "v1", "l2": "v2"}).(Gauge).Set(42)
if got, want := vec.Delete(Labels{"l2": "v1", "l1": "v2"}), false; got != want {
if got, want := vec.Remove(Labels{"l2": "v1", "l1": "v2"}), false; got != want {
t.Errorf("got %v, want %v", got, want)
}
if got, want := vec.Delete(Labels{"l1": "v1"}), false; got != want {
if got, want := vec.Remove(Labels{"l1": "v1"}), false; got != want {
t.Errorf("got %v, want %v", got, want)
}
}
func TestDeleteLabelValues(t *testing.T) {
func TestRemoveLabelValues(t *testing.T) {
vec := NewGaugeVec(
GaugeOpts{
Name: "test",
@ -82,10 +82,10 @@ func TestDeleteLabelValues(t *testing.T) {
},
[]string{"l1", "l2"},
)
testDeleteLabelValues(t, vec)
testRemoveLabelValues(t, vec)
}
func TestDeleteLabelValuesWithCollisions(t *testing.T) {
func TestRemoveLabelValuesWithCollisions(t *testing.T) {
vec := NewGaugeVec(
GaugeOpts{
Name: "test",
@ -95,32 +95,32 @@ func TestDeleteLabelValuesWithCollisions(t *testing.T) {
)
vec.hashAdd = func(h uint64, s string) uint64 { return 1 }
vec.hashAddByte = func(h uint64, b byte) uint64 { return 1 }
testDeleteLabelValues(t, vec)
testRemoveLabelValues(t, vec)
}
func testDeleteLabelValues(t *testing.T, vec *GaugeVec) {
if got, want := vec.DeleteLabelValues("v1", "v2"), false; got != want {
func testRemoveLabelValues(t *testing.T, vec *GaugeVec) {
if got, want := vec.RemoveLabelValues("v1", "v2"), false; got != want {
t.Errorf("got %v, want %v", got, want)
}
vec.With(Labels{"l1": "v1", "l2": "v2"}).(Gauge).Set(42)
vec.With(Labels{"l1": "v1", "l2": "v3"}).(Gauge).Set(42) // Add junk data for collision.
if got, want := vec.DeleteLabelValues("v1", "v2"), true; got != want {
if got, want := vec.RemoveLabelValues("v1", "v2"), true; got != want {
t.Errorf("got %v, want %v", got, want)
}
if got, want := vec.DeleteLabelValues("v1", "v2"), false; got != want {
if got, want := vec.RemoveLabelValues("v1", "v2"), false; got != want {
t.Errorf("got %v, want %v", got, want)
}
if got, want := vec.DeleteLabelValues("v1", "v3"), true; got != want {
if got, want := vec.RemoveLabelValues("v1", "v3"), true; got != want {
t.Errorf("got %v, want %v", got, want)
}
vec.With(Labels{"l1": "v1", "l2": "v2"}).(Gauge).Set(42)
// Delete out of order.
if got, want := vec.DeleteLabelValues("v2", "v1"), false; got != want {
// Remove out of order.
if got, want := vec.RemoveLabelValues("v2", "v1"), false; got != want {
t.Errorf("got %v, want %v", got, want)
}
if got, want := vec.DeleteLabelValues("v1"), false; got != want {
if got, want := vec.RemoveLabelValues("v1"), false; got != want {
t.Errorf("got %v, want %v", got, want)
}
}
@ -305,10 +305,10 @@ func testCurryVec(t *testing.T, vec *CounterVec) {
c1.WithLabelValues("1", "2", "3").Inc()
c2.With(Labels{"one": "11", "two": "22", "three": "33"}).Inc()
assertMetrics(t)
if !c1.Delete(Labels{"one": "1", "two": "2", "three": "3"}) {
if !c1.Remove(Labels{"one": "1", "two": "2", "three": "3"}) {
t.Error("deletion failed")
}
if !c2.DeleteLabelValues("11", "22", "33") {
if !c2.RemoveLabelValues("11", "22", "33") {
t.Error("deletion failed")
}
assertNoMetric(t)
@ -319,16 +319,16 @@ func testCurryVec(t *testing.T, vec *CounterVec) {
c1.WithLabelValues("2", "3").Inc()
c2.With(Labels{"two": "22", "three": "33"}).Inc()
assertMetrics(t)
if c1.Delete(Labels{"two": "22", "three": "33"}) {
if c1.Remove(Labels{"two": "22", "three": "33"}) {
t.Error("deletion unexpectedly succeeded")
}
if c2.DeleteLabelValues("2", "3") {
if c2.RemoveLabelValues("2", "3") {
t.Error("deletion unexpectedly succeeded")
}
if !c1.Delete(Labels{"two": "2", "three": "3"}) {
if !c1.Remove(Labels{"two": "2", "three": "3"}) {
t.Error("deletion failed")
}
if !c2.DeleteLabelValues("22", "33") {
if !c2.RemoveLabelValues("22", "33") {
t.Error("deletion failed")
}
assertNoMetric(t)
@ -339,16 +339,16 @@ func testCurryVec(t *testing.T, vec *CounterVec) {
c1.WithLabelValues("1", "3").Inc()
c2.With(Labels{"one": "11", "three": "33"}).Inc()
assertMetrics(t)
if c1.Delete(Labels{"one": "11", "three": "33"}) {
if c1.Remove(Labels{"one": "11", "three": "33"}) {
t.Error("deletion unexpectedly succeeded")
}
if c2.DeleteLabelValues("1", "3") {
if c2.RemoveLabelValues("1", "3") {
t.Error("deletion unexpectedly succeeded")
}
if !c1.Delete(Labels{"one": "1", "three": "3"}) {
if !c1.Remove(Labels{"one": "1", "three": "3"}) {
t.Error("deletion failed")
}
if !c2.DeleteLabelValues("11", "33") {
if !c2.RemoveLabelValues("11", "33") {
t.Error("deletion failed")
}
assertNoMetric(t)
@ -359,16 +359,16 @@ func testCurryVec(t *testing.T, vec *CounterVec) {
c1.WithLabelValues("1", "2").Inc()
c2.With(Labels{"one": "11", "two": "22"}).Inc()
assertMetrics(t)
if c1.Delete(Labels{"two": "22", "one": "11"}) {
if c1.Remove(Labels{"two": "22", "one": "11"}) {
t.Error("deletion unexpectedly succeeded")
}
if c2.DeleteLabelValues("1", "2") {
if c2.RemoveLabelValues("1", "2") {
t.Error("deletion unexpectedly succeeded")
}
if !c1.Delete(Labels{"two": "2", "one": "1"}) {
if !c1.Remove(Labels{"two": "2", "one": "1"}) {
t.Error("deletion failed")
}
if !c2.DeleteLabelValues("11", "22") {
if !c2.RemoveLabelValues("11", "22") {
t.Error("deletion failed")
}
assertNoMetric(t)
@ -379,16 +379,16 @@ func testCurryVec(t *testing.T, vec *CounterVec) {
c1.WithLabelValues("2").Inc()
c2.With(Labels{"two": "22"}).Inc()
assertMetrics(t)
if c1.Delete(Labels{"two": "22"}) {
if c1.Remove(Labels{"two": "22"}) {
t.Error("deletion unexpectedly succeeded")
}
if c2.DeleteLabelValues("2") {
if c2.RemoveLabelValues("2") {
t.Error("deletion unexpectedly succeeded")
}
if !c1.Delete(Labels{"two": "2"}) {
if !c1.Remove(Labels{"two": "2"}) {
t.Error("deletion failed")
}
if !c2.DeleteLabelValues("22") {
if !c2.RemoveLabelValues("22") {
t.Error("deletion failed")
}
assertNoMetric(t)
@ -399,10 +399,10 @@ func testCurryVec(t *testing.T, vec *CounterVec) {
c1.WithLabelValues().Inc()
c2.With(nil).Inc()
assertMetrics(t)
if !c1.Delete(Labels{}) {
if !c1.Remove(Labels{}) {
t.Error("deletion failed")
}
if !c2.DeleteLabelValues() {
if !c2.RemoveLabelValues() {
t.Error("deletion failed")
}
assertNoMetric(t)
@ -413,16 +413,16 @@ func testCurryVec(t *testing.T, vec *CounterVec) {
c1.WithLabelValues("2").Inc()
c2.With(Labels{"two": "22"}).Inc()
assertMetrics(t)
if c1.Delete(Labels{"two": "22"}) {
if c1.Remove(Labels{"two": "22"}) {
t.Error("deletion unexpectedly succeeded")
}
if c2.DeleteLabelValues("2") {
if c2.RemoveLabelValues("2") {
t.Error("deletion unexpectedly succeeded")
}
if !c1.Delete(Labels{"two": "2"}) {
if !c1.Remove(Labels{"two": "2"}) {
t.Error("deletion failed")
}
if !c2.DeleteLabelValues("22") {
if !c2.RemoveLabelValues("22") {
t.Error("deletion failed")
}
assertNoMetric(t)
@ -437,10 +437,10 @@ func testCurryVec(t *testing.T, vec *CounterVec) {
}
assertNoMetric(t)
c1.WithLabelValues("1", "2").Inc()
if c1.Delete(Labels{"one": "1", "two": "2", "three": "3"}) {
if c1.Remove(Labels{"one": "1", "two": "2", "three": "3"}) {
t.Error("deletion unexpectedly succeeded")
}
if !c1.Delete(Labels{"one": "1", "two": "2"}) {
if !c1.Remove(Labels{"one": "1", "two": "2"}) {
t.Error("deletion failed")
}
assertNoMetric(t)