Remove deprecated DefObjectives from Summary

Signed-off-by: beorn7 <beorn@soundcloud.com>
This commit is contained in:
beorn7 2018-10-15 19:55:40 +02:00
parent 0cb0b3eaf6
commit 1cb875e111
4 changed files with 26 additions and 43 deletions

View File

@ -231,13 +231,6 @@ func TestHistogramVecConcurrency(t *testing.T) {
rand.Seed(42) rand.Seed(42)
objectives := make([]float64, 0, len(DefObjectives))
for qu := range DefObjectives {
objectives = append(objectives, qu)
}
sort.Float64s(objectives)
it := func(n uint32) bool { it := func(n uint32) bool {
mutations := int(n%1e4 + 1e4) mutations := int(n%1e4 + 1e4)
concLevel := int(n%7 + 1) concLevel := int(n%7 + 1)

View File

@ -256,8 +256,9 @@ collected metric "name" { label:<name:"constname" value:"\377" > label:<name:"la
`) `)
summary := prometheus.NewSummary(prometheus.SummaryOpts{ summary := prometheus.NewSummary(prometheus.SummaryOpts{
Name: "complex", Name: "complex",
Help: "A metric to check collisions with _sum and _count.", Help: "A metric to check collisions with _sum and _count.",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
}) })
summaryAsText := []byte(`# HELP complex A metric to check collisions with _sum and _count. summaryAsText := []byte(`# HELP complex A metric to check collisions with _sum and _count.
# TYPE complex summary # TYPE complex summary

View File

@ -56,16 +56,8 @@ type Summary interface {
Observe(float64) Observe(float64)
} }
// DefObjectives are the default Summary quantile values. var errQuantileLabelNotAllowed = fmt.Errorf(
// "%q is not allowed as label name in summaries", quantileLabel,
// Deprecated: DefObjectives will not be used as the default objectives in
// v0.10 of the library. The default Summary will have no quantiles then.
var (
DefObjectives = map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}
errQuantileLabelNotAllowed = fmt.Errorf(
"%q is not allowed as label name in summaries", quantileLabel,
)
) )
// Default values for SummaryOpts. // Default values for SummaryOpts.
@ -121,13 +113,8 @@ type SummaryOpts struct {
// Objectives defines the quantile rank estimates with their respective // Objectives defines the quantile rank estimates with their respective
// absolute error. If Objectives[q] = e, then the value reported for q // absolute error. If Objectives[q] = e, then the value reported for q
// will be the φ-quantile value for some φ between q-e and q+e. The // will be the φ-quantile value for some φ between q-e and q+e. The
// default value is DefObjectives. It is used if Objectives is left at // default value is an empty map, resulting in a summary without
// its zero value (i.e. nil). To create a Summary without Objectives, // quantiles.
// set it to an empty map (i.e. map[float64]float64{}).
//
// Deprecated: Note that the current value of DefObjectives is
// deprecated. It will be replaced by an empty map in v0.10 of the
// library. Please explicitly set Objectives to the desired value.
Objectives map[float64]float64 Objectives map[float64]float64
// MaxAge defines the duration for which an observation stays relevant // MaxAge defines the duration for which an observation stays relevant
@ -196,7 +183,7 @@ func newSummary(desc *Desc, opts SummaryOpts, labelValues ...string) Summary {
} }
if opts.Objectives == nil { if opts.Objectives == nil {
opts.Objectives = DefObjectives opts.Objectives = map[float64]float64{}
} }
if opts.MaxAge < 0 { if opts.MaxAge < 0 {

View File

@ -39,8 +39,8 @@ func TestSummaryWithDefaultObjectives(t *testing.T) {
if err := summaryWithDefaultObjectives.Write(m); err != nil { if err := summaryWithDefaultObjectives.Write(m); err != nil {
t.Error(err) t.Error(err)
} }
if len(m.GetSummary().Quantile) != len(DefObjectives) { if len(m.GetSummary().Quantile) != 0 {
t.Error("expected default objectives in summary") t.Error("expected no objectives in summary")
} }
} }
@ -189,6 +189,7 @@ func TestSummaryConcurrency(t *testing.T) {
} }
rand.Seed(42) rand.Seed(42)
objMap := map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}
it := func(n uint32) bool { it := func(n uint32) bool {
mutations := int(n%1e4 + 1e4) mutations := int(n%1e4 + 1e4)
@ -202,7 +203,7 @@ func TestSummaryConcurrency(t *testing.T) {
sum := NewSummary(SummaryOpts{ sum := NewSummary(SummaryOpts{
Name: "test_summary", Name: "test_summary",
Help: "helpless", Help: "helpless",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}, Objectives: objMap,
}) })
allVars := make([]float64, total) allVars := make([]float64, total)
@ -237,14 +238,14 @@ func TestSummaryConcurrency(t *testing.T) {
t.Errorf("got sample sum %f, want %f", got, want) t.Errorf("got sample sum %f, want %f", got, want)
} }
objectives := make([]float64, 0, len(DefObjectives)) objSlice := make([]float64, 0, len(objMap))
for qu := range DefObjectives { for qu := range objMap {
objectives = append(objectives, qu) objSlice = append(objSlice, qu)
} }
sort.Float64s(objectives) sort.Float64s(objSlice)
for i, wantQ := range objectives { for i, wantQ := range objSlice {
ε := DefObjectives[wantQ] ε := objMap[wantQ]
gotQ := *m.Summary.Quantile[i].Quantile gotQ := *m.Summary.Quantile[i].Quantile
gotV := *m.Summary.Quantile[i].Value gotV := *m.Summary.Quantile[i].Value
min, max := getBounds(allVars, wantQ, ε) min, max := getBounds(allVars, wantQ, ε)
@ -269,13 +270,14 @@ func TestSummaryVecConcurrency(t *testing.T) {
} }
rand.Seed(42) rand.Seed(42)
objMap := map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}
objectives := make([]float64, 0, len(DefObjectives)) objSlice := make([]float64, 0, len(objMap))
for qu := range DefObjectives { for qu := range objMap {
objectives = append(objectives, qu) objSlice = append(objSlice, qu)
} }
sort.Float64s(objectives) sort.Float64s(objSlice)
it := func(n uint32) bool { it := func(n uint32) bool {
mutations := int(n%1e4 + 1e4) mutations := int(n%1e4 + 1e4)
@ -290,7 +292,7 @@ func TestSummaryVecConcurrency(t *testing.T) {
SummaryOpts{ SummaryOpts{
Name: "test_summary", Name: "test_summary",
Help: "helpless", Help: "helpless",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}, Objectives: objMap,
}, },
[]string{"label"}, []string{"label"},
) )
@ -333,8 +335,8 @@ func TestSummaryVecConcurrency(t *testing.T) {
if got, want := *m.Summary.SampleSum, sampleSums[i]; math.Abs((got-want)/want) > 0.001 { if got, want := *m.Summary.SampleSum, sampleSums[i]; math.Abs((got-want)/want) > 0.001 {
t.Errorf("got sample sum %f for label %c, want %f", got, 'A'+i, want) t.Errorf("got sample sum %f for label %c, want %f", got, 'A'+i, want)
} }
for j, wantQ := range objectives { for j, wantQ := range objSlice {
ε := DefObjectives[wantQ] ε := objMap[wantQ]
gotQ := *m.Summary.Quantile[j].Quantile gotQ := *m.Summary.Quantile[j].Quantile
gotV := *m.Summary.Quantile[j].Value gotV := *m.Summary.Quantile[j].Value
min, max := getBounds(allVars[i], wantQ, ε) min, max := getBounds(allVars[i], wantQ, ε)