Skip to content

Commit ad39048

Browse files
parthlawParth Lawania
authored andcommitted
changed the name of all variables with min/max name (prometheus#1606)
* changed the name of all variables with min/max name Signed-off-by: Parth Lawania <[email protected]> * removed predeclared ignore condition for min and max identifiers Signed-off-by: Parth Lawania <[email protected]> --------- Signed-off-by: Parth Lawania <[email protected]> Co-authored-by: Parth Lawania <[email protected]> Signed-off-by: Eugene <[email protected]>
1 parent 8140a81 commit ad39048

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
lines changed

.golangci.yml

-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ linters-settings:
6666
local-prefixes: github.com/prometheus/client_golang
6767
gofumpt:
6868
extra-rules: true
69-
predeclared:
70-
ignore: "min,max"
7169
revive:
7270
rules:
7371
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter

prometheus/histogram.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -330,24 +330,24 @@ func ExponentialBuckets(start, factor float64, count int) []float64 {
330330
// used for the Buckets field of HistogramOpts.
331331
//
332332
// The function panics if 'count' is 0 or negative, if 'min' is 0 or negative.
333-
func ExponentialBucketsRange(min, max float64, count int) []float64 {
333+
func ExponentialBucketsRange(minBucket, maxBucket float64, count int) []float64 {
334334
if count < 1 {
335335
panic("ExponentialBucketsRange count needs a positive count")
336336
}
337-
if min <= 0 {
337+
if minBucket <= 0 {
338338
panic("ExponentialBucketsRange min needs to be greater than 0")
339339
}
340340

341341
// Formula for exponential buckets.
342342
// max = min*growthFactor^(bucketCount-1)
343343

344344
// We know max/min and highest bucket. Solve for growthFactor.
345-
growthFactor := math.Pow(max/min, 1.0/float64(count-1))
345+
growthFactor := math.Pow(maxBucket/minBucket, 1.0/float64(count-1))
346346

347347
// Now that we know growthFactor, solve for each bucket.
348348
buckets := make([]float64, count)
349349
for i := 1; i <= count; i++ {
350-
buckets[i-1] = min * math.Pow(growthFactor, float64(i-1))
350+
buckets[i-1] = minBucket * math.Pow(growthFactor, float64(i-1))
351351
}
352352
return buckets
353353
}

prometheus/internal/difflib.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ import (
2525
"strings"
2626
)
2727

28-
func min(a, b int) int {
28+
func minInt(a, b int) int {
2929
if a < b {
3030
return a
3131
}
3232
return b
3333
}
3434

35-
func max(a, b int) int {
35+
func maxInt(a, b int) int {
3636
if a > b {
3737
return a
3838
}
@@ -427,12 +427,12 @@ func (m *SequenceMatcher) GetGroupedOpCodes(n int) [][]OpCode {
427427
if codes[0].Tag == 'e' {
428428
c := codes[0]
429429
i1, i2, j1, j2 := c.I1, c.I2, c.J1, c.J2
430-
codes[0] = OpCode{c.Tag, max(i1, i2-n), i2, max(j1, j2-n), j2}
430+
codes[0] = OpCode{c.Tag, maxInt(i1, i2-n), i2, maxInt(j1, j2-n), j2}
431431
}
432432
if codes[len(codes)-1].Tag == 'e' {
433433
c := codes[len(codes)-1]
434434
i1, i2, j1, j2 := c.I1, c.I2, c.J1, c.J2
435-
codes[len(codes)-1] = OpCode{c.Tag, i1, min(i2, i1+n), j1, min(j2, j1+n)}
435+
codes[len(codes)-1] = OpCode{c.Tag, i1, minInt(i2, i1+n), j1, minInt(j2, j1+n)}
436436
}
437437
nn := n + n
438438
groups := [][]OpCode{}
@@ -443,12 +443,12 @@ func (m *SequenceMatcher) GetGroupedOpCodes(n int) [][]OpCode {
443443
// there is a large range with no changes.
444444
if c.Tag == 'e' && i2-i1 > nn {
445445
group = append(group, OpCode{
446-
c.Tag, i1, min(i2, i1+n),
447-
j1, min(j2, j1+n),
446+
c.Tag, i1, minInt(i2, i1+n),
447+
j1, minInt(j2, j1+n),
448448
})
449449
groups = append(groups, group)
450450
group = []OpCode{}
451-
i1, j1 = max(i1, i2-n), max(j1, j2-n)
451+
i1, j1 = maxInt(i1, i2-n), maxInt(j1, j2-n)
452452
}
453453
group = append(group, OpCode{c.Tag, i1, i2, j1, j2})
454454
}
@@ -515,7 +515,7 @@ func (m *SequenceMatcher) QuickRatio() float64 {
515515
// is faster to compute than either .Ratio() or .QuickRatio().
516516
func (m *SequenceMatcher) RealQuickRatio() float64 {
517517
la, lb := len(m.a), len(m.b)
518-
return calculateRatio(min(la, lb), la+lb)
518+
return calculateRatio(minInt(la, lb), la+lb)
519519
}
520520

521521
// Convert range to the "ed" format

prometheus/summary_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,12 @@ func TestSummaryConcurrency(t *testing.T) {
263263
ε := objMap[wantQ]
264264
gotQ := *m.Summary.Quantile[i].Quantile
265265
gotV := *m.Summary.Quantile[i].Value
266-
min, max := getBounds(allVars, wantQ, ε)
266+
minBound, maxBound := getBounds(allVars, wantQ, ε)
267267
if gotQ != wantQ {
268268
t.Errorf("got quantile %f, want %f", gotQ, wantQ)
269269
}
270-
if gotV < min || gotV > max {
271-
t.Errorf("got %f for quantile %f, want [%f,%f]", gotV, gotQ, min, max)
270+
if gotV < minBound || gotV > maxBound {
271+
t.Errorf("got %f for quantile %f, want [%f,%f]", gotV, gotQ, minBound, maxBound)
272272
}
273273
}
274274
return true
@@ -353,12 +353,12 @@ func TestSummaryVecConcurrency(t *testing.T) {
353353
ε := objMap[wantQ]
354354
gotQ := *m.Summary.Quantile[j].Quantile
355355
gotV := *m.Summary.Quantile[j].Value
356-
min, max := getBounds(allVars[i], wantQ, ε)
356+
minBound, maxBound := getBounds(allVars[i], wantQ, ε)
357357
if gotQ != wantQ {
358358
t.Errorf("got quantile %f for label %c, want %f", gotQ, 'A'+i, wantQ)
359359
}
360-
if gotV < min || gotV > max {
361-
t.Errorf("got %f for quantile %f for label %c, want [%f,%f]", gotV, gotQ, 'A'+i, min, max)
360+
if gotV < minBound || gotV > maxBound {
361+
t.Errorf("got %f for quantile %f for label %c, want [%f,%f]", gotV, gotQ, 'A'+i, minBound, maxBound)
362362
}
363363
}
364364
}
@@ -410,20 +410,20 @@ func TestSummaryDecay(t *testing.T) {
410410
}
411411
}
412412

413-
func getBounds(vars []float64, q, ε float64) (min, max float64) {
413+
func getBounds(vars []float64, q, ε float64) (minBound, maxBound float64) {
414414
// TODO(beorn7): This currently tolerates an error of up to 2*ε. The
415415
// error must be at most ε, but for some reason, it's sometimes slightly
416416
// higher. That's a bug.
417417
n := float64(len(vars))
418418
lower := int((q - 2*ε) * n)
419419
upper := int(math.Ceil((q + 2*ε) * n))
420-
min = vars[0]
420+
minBound = vars[0]
421421
if lower > 1 {
422-
min = vars[lower-1]
422+
minBound = vars[lower-1]
423423
}
424-
max = vars[len(vars)-1]
424+
maxBound = vars[len(vars)-1]
425425
if upper < len(vars) {
426-
max = vars[upper-1]
426+
maxBound = vars[upper-1]
427427
}
428428
return
429429
}

0 commit comments

Comments
 (0)