Merge branch v2.1 into v2.2
This commit is contained in:
commit
f54b8d8847
4 changed files with 19 additions and 31 deletions
|
@ -1,3 +1,9 @@
|
|||
## [v2.1.8](https://github.com/containous/traefik/tree/v2.1.8) (2020-03-19)
|
||||
[All Commits](https://github.com/containous/traefik/compare/v2.1.7...v2.1.8)
|
||||
|
||||
**Bug fixes:**
|
||||
- **[middleware,metrics]** Fix memory leak in metrics ([#6522](https://github.com/containous/traefik/pull/6522) by [juliens](https://github.com/juliens))
|
||||
|
||||
## [v2.2.0-rc3](https://github.com/containous/traefik/tree/v2.2.0-rc3) (2020-03-18)
|
||||
[All Commits](https://github.com/containous/traefik/compare/v2.2.0-rc2...v2.2.0-rc3)
|
||||
|
||||
|
|
|
@ -213,36 +213,29 @@ func (r *standardRegistry) ServiceServerUpGauge() metrics.Gauge {
|
|||
// used when producing observations without explicitly setting the observed value.
|
||||
type ScalableHistogram interface {
|
||||
With(labelValues ...string) ScalableHistogram
|
||||
StartAt(t time.Time)
|
||||
Observe(v float64)
|
||||
ObserveDuration()
|
||||
ObserveFromStart(start time.Time)
|
||||
}
|
||||
|
||||
// HistogramWithScale is a histogram that will convert its observed value to the specified unit.
|
||||
type HistogramWithScale struct {
|
||||
histogram metrics.Histogram
|
||||
unit time.Duration
|
||||
start time.Time
|
||||
}
|
||||
|
||||
// With implements ScalableHistogram.
|
||||
func (s *HistogramWithScale) With(labelValues ...string) ScalableHistogram {
|
||||
s.histogram = s.histogram.With(labelValues...)
|
||||
return s
|
||||
h, _ := NewHistogramWithScale(s.histogram.With(labelValues...), s.unit)
|
||||
return h
|
||||
}
|
||||
|
||||
// StartAt implements ScalableHistogram.
|
||||
func (s *HistogramWithScale) StartAt(t time.Time) {
|
||||
s.start = t
|
||||
}
|
||||
|
||||
// ObserveDuration implements ScalableHistogram.
|
||||
func (s *HistogramWithScale) ObserveDuration() {
|
||||
// ObserveFromStart implements ScalableHistogram.
|
||||
func (s *HistogramWithScale) ObserveFromStart(start time.Time) {
|
||||
if s.unit <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
d := float64(time.Since(s.start).Nanoseconds()) / float64(s.unit)
|
||||
d := float64(time.Since(start).Nanoseconds()) / float64(s.unit)
|
||||
if d < 0 {
|
||||
d = 0
|
||||
}
|
||||
|
@ -273,17 +266,10 @@ func NewMultiHistogram(h ...ScalableHistogram) MultiHistogram {
|
|||
return MultiHistogram(h)
|
||||
}
|
||||
|
||||
// StartAt implements ScalableHistogram.
|
||||
func (h MultiHistogram) StartAt(t time.Time) {
|
||||
// ObserveFromStart implements ScalableHistogram.
|
||||
func (h MultiHistogram) ObserveFromStart(start time.Time) {
|
||||
for _, histogram := range h {
|
||||
histogram.StartAt(t)
|
||||
}
|
||||
}
|
||||
|
||||
// ObserveDuration implements ScalableHistogram.
|
||||
func (h MultiHistogram) ObserveDuration() {
|
||||
for _, histogram := range h {
|
||||
histogram.ObserveDuration()
|
||||
histogram.ObserveFromStart(start)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,9 @@ func TestScalableHistogram(t *testing.T) {
|
|||
|
||||
ticker := time.NewTicker(500 * time.Millisecond)
|
||||
<-ticker.C
|
||||
sh.StartAt(time.Now())
|
||||
start := time.Now()
|
||||
<-ticker.C
|
||||
sh.ObserveDuration()
|
||||
sh.ObserveFromStart(start)
|
||||
|
||||
var b bytes.Buffer
|
||||
h.Print(&b)
|
||||
|
@ -99,9 +99,7 @@ func (c *histogramMock) With(labelValues ...string) ScalableHistogram {
|
|||
|
||||
func (c *histogramMock) Start() {}
|
||||
|
||||
func (c *histogramMock) StartAt(t time.Time) {}
|
||||
|
||||
func (c *histogramMock) ObserveDuration() {}
|
||||
func (c *histogramMock) ObserveFromStart(t time.Time) {}
|
||||
|
||||
func (c *histogramMock) Observe(v float64) {
|
||||
c.lastHistogramValue = v
|
||||
|
|
|
@ -103,11 +103,9 @@ func (m *metricsMiddleware) ServeHTTP(rw http.ResponseWriter, req *http.Request)
|
|||
labels = append(labels, "code", strconv.Itoa(recorder.getCode()))
|
||||
|
||||
histograms := m.reqDurationHistogram.With(labels...)
|
||||
histograms.StartAt(start)
|
||||
histograms.ObserveFromStart(start)
|
||||
|
||||
m.reqsCounter.With(labels...).Add(1)
|
||||
|
||||
histograms.ObserveDuration()
|
||||
}
|
||||
|
||||
func getRequestProtocol(req *http.Request) string {
|
||||
|
|
Loading…
Reference in a new issue