-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add disabled and prometheus metric providers
FAB-12694 #done Change-Id: I60a243b6f5376f8d24f6856f01dd40e3e053404c Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
- Loading branch information
Showing
8 changed files
with
635 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package disabled_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestDisabled(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Disabled Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package disabled | ||
|
||
import ( | ||
"github.com/hyperledger/fabric/common/metrics" | ||
) | ||
|
||
type Provider struct{} | ||
|
||
func (p *Provider) NewCounter(o metrics.CounterOpts) metrics.Counter { return &Counter{} } | ||
func (p *Provider) NewGauge(o metrics.GaugeOpts) metrics.Gauge { return &Gauge{} } | ||
func (p *Provider) NewHistogram(o metrics.HistogramOpts) metrics.Histogram { return &Histogram{} } | ||
|
||
type Counter struct{} | ||
|
||
func (c *Counter) Add(delta float64) {} | ||
func (c *Counter) With(labelValues ...string) metrics.Counter { | ||
return c | ||
} | ||
|
||
type Gauge struct{} | ||
|
||
func (g *Gauge) Add(delta float64) {} | ||
func (g *Gauge) Set(delta float64) {} | ||
func (g *Gauge) With(labelValues ...string) metrics.Gauge { | ||
return g | ||
} | ||
|
||
type Histogram struct{} | ||
|
||
func (h *Histogram) Observe(value float64) {} | ||
func (h *Histogram) With(labelValues ...string) metrics.Histogram { | ||
return h | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package disabled_test | ||
|
||
import ( | ||
"github.com/hyperledger/fabric/common/metrics" | ||
"github.com/hyperledger/fabric/common/metrics/disabled" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Provider", func() { | ||
var p metrics.Provider | ||
|
||
BeforeEach(func() { | ||
p = &disabled.Provider{} | ||
}) | ||
|
||
Describe("NewCounter", func() { | ||
It("creates a no-op counter that doesn't blow up", func() { | ||
c := p.NewCounter(metrics.CounterOpts{}) | ||
Expect(c).NotTo(BeNil()) | ||
|
||
c.Add(1) | ||
c.With("whatever").Add(2) | ||
}) | ||
}) | ||
|
||
Describe("NewGauge", func() { | ||
It("creates a no-op gauge that doesn't blow up", func() { | ||
g := p.NewGauge(metrics.GaugeOpts{}) | ||
Expect(g).NotTo(BeNil()) | ||
|
||
g.Set(1) | ||
g.Add(1) | ||
g.With("whatever").Set(2) | ||
g.With("whatever").Add(2) | ||
}) | ||
}) | ||
|
||
Describe("NewHistogram", func() { | ||
It("creates a no-op histogram that doesn't blow up", func() { | ||
h := p.NewHistogram(metrics.HistogramOpts{}) | ||
Expect(h).NotTo(BeNil()) | ||
|
||
h.Observe(1) | ||
h.With("whatever").Observe(2) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package prometheus_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestPrometheus(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Prometheus Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package prometheus | ||
|
||
import ( | ||
kitmetrics "github.com/go-kit/kit/metrics" | ||
"github.com/go-kit/kit/metrics/prometheus" | ||
"github.com/hyperledger/fabric/common/metrics" | ||
prom "github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
type Provider struct{} | ||
|
||
func (p *Provider) NewCounter(o metrics.CounterOpts) metrics.Counter { | ||
return &Counter{ | ||
Counter: prometheus.NewCounterFrom( | ||
prom.CounterOpts{ | ||
Namespace: o.Namespace, | ||
Subsystem: o.Subsystem, | ||
Name: o.Name, | ||
Help: o.Help, | ||
}, | ||
o.LabelNames, | ||
), | ||
} | ||
} | ||
|
||
func (p *Provider) NewGauge(o metrics.GaugeOpts) metrics.Gauge { | ||
return &Gauge{ | ||
Gauge: prometheus.NewGaugeFrom( | ||
prom.GaugeOpts{ | ||
Namespace: o.Namespace, | ||
Subsystem: o.Subsystem, | ||
Name: o.Name, | ||
Help: o.Help, | ||
}, | ||
o.LabelNames, | ||
), | ||
} | ||
} | ||
|
||
func (p *Provider) NewHistogram(o metrics.HistogramOpts) metrics.Histogram { | ||
return &Histogram{ | ||
Histogram: prometheus.NewHistogramFrom( | ||
prom.HistogramOpts{ | ||
Namespace: o.Namespace, | ||
Subsystem: o.Subsystem, | ||
Name: o.Name, | ||
Help: o.Help, | ||
Buckets: o.Buckets, | ||
}, | ||
o.LabelNames, | ||
), | ||
} | ||
} | ||
|
||
type Counter struct{ kitmetrics.Counter } | ||
|
||
func (c *Counter) With(labelValues ...string) metrics.Counter { | ||
return &Counter{Counter: c.Counter.With(labelValues...)} | ||
} | ||
|
||
type Gauge struct{ kitmetrics.Gauge } | ||
|
||
func (g *Gauge) With(labelValues ...string) metrics.Gauge { | ||
return &Gauge{Gauge: g.Gauge.With(labelValues...)} | ||
} | ||
|
||
type Histogram struct{ kitmetrics.Histogram } | ||
|
||
func (h *Histogram) With(labelValues ...string) metrics.Histogram { | ||
return &Histogram{Histogram: h.Histogram.With(labelValues...)} | ||
} |
Oops, something went wrong.