mirror of
https://github.com/tendermint/tendermint.git
synced 2026-06-10 00:03:04 +00:00
metricsgen: port metrics code generation tool (#9156)
This is a port of #8470 and #8501 from the former mainline branch, in support of #2600 and #9076. No additional changes other than checking out the code have been implemented in this PR. A subsequent PR will incorporate this code.
This commit is contained in:
committed by
Sam Ricotta
parent
5733a0c737
commit
4228b80c15
30
scripts/metricsgen/testdata/basic/metrics.gen.go
vendored
Normal file
30
scripts/metricsgen/testdata/basic/metrics.gen.go
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
// Code generated by metricsgen. DO NOT EDIT.
|
||||
|
||||
package basic
|
||||
|
||||
import (
|
||||
"github.com/go-kit/kit/metrics/discard"
|
||||
prometheus "github.com/go-kit/kit/metrics/prometheus"
|
||||
stdprometheus "github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
|
||||
labels := []string{}
|
||||
for i := 0; i < len(labelsAndValues); i += 2 {
|
||||
labels = append(labels, labelsAndValues[i])
|
||||
}
|
||||
return &Metrics{
|
||||
Height: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: MetricsSubsystem,
|
||||
Name: "height",
|
||||
Help: "simple metric that tracks the height of the chain.",
|
||||
}, labels).With(labelsAndValues...),
|
||||
}
|
||||
}
|
||||
|
||||
func NopMetrics() *Metrics {
|
||||
return &Metrics{
|
||||
Height: discard.NewGauge(),
|
||||
}
|
||||
}
|
||||
11
scripts/metricsgen/testdata/basic/metrics.go
vendored
Normal file
11
scripts/metricsgen/testdata/basic/metrics.go
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
package basic
|
||||
|
||||
import "github.com/go-kit/kit/metrics"
|
||||
|
||||
//go:generate go run ../../../../scripts/metricsgen -struct=Metrics
|
||||
|
||||
// Metrics contains metrics exposed by this package.
|
||||
type Metrics struct {
|
||||
// simple metric that tracks the height of the chain.
|
||||
Height metrics.Gauge
|
||||
}
|
||||
30
scripts/metricsgen/testdata/commented/metrics.gen.go
vendored
Normal file
30
scripts/metricsgen/testdata/commented/metrics.gen.go
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
// Code generated by metricsgen. DO NOT EDIT.
|
||||
|
||||
package commented
|
||||
|
||||
import (
|
||||
"github.com/go-kit/kit/metrics/discard"
|
||||
prometheus "github.com/go-kit/kit/metrics/prometheus"
|
||||
stdprometheus "github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
|
||||
labels := []string{}
|
||||
for i := 0; i < len(labelsAndValues); i += 2 {
|
||||
labels = append(labels, labelsAndValues[i])
|
||||
}
|
||||
return &Metrics{
|
||||
Field: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: MetricsSubsystem,
|
||||
Name: "field",
|
||||
Help: "Height of the chain. We expect multi-line comments to parse correctly.",
|
||||
}, labels).With(labelsAndValues...),
|
||||
}
|
||||
}
|
||||
|
||||
func NopMetrics() *Metrics {
|
||||
return &Metrics{
|
||||
Field: discard.NewGauge(),
|
||||
}
|
||||
}
|
||||
11
scripts/metricsgen/testdata/commented/metrics.go
vendored
Normal file
11
scripts/metricsgen/testdata/commented/metrics.go
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
package commented
|
||||
|
||||
import "github.com/go-kit/kit/metrics"
|
||||
|
||||
//go:generate go run ../../../../scripts/metricsgen -struct=Metrics
|
||||
|
||||
type Metrics struct {
|
||||
// Height of the chain.
|
||||
// We expect multi-line comments to parse correctly.
|
||||
Field metrics.Gauge
|
||||
}
|
||||
55
scripts/metricsgen/testdata/tags/metrics.gen.go
vendored
Normal file
55
scripts/metricsgen/testdata/tags/metrics.gen.go
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
// Code generated by metricsgen. DO NOT EDIT.
|
||||
|
||||
package tags
|
||||
|
||||
import (
|
||||
"github.com/go-kit/kit/metrics/discard"
|
||||
prometheus "github.com/go-kit/kit/metrics/prometheus"
|
||||
stdprometheus "github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
|
||||
labels := []string{}
|
||||
for i := 0; i < len(labelsAndValues); i += 2 {
|
||||
labels = append(labels, labelsAndValues[i])
|
||||
}
|
||||
return &Metrics{
|
||||
WithLabels: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: MetricsSubsystem,
|
||||
Name: "with_labels",
|
||||
Help: "",
|
||||
}, append(labels, "step", "time")).With(labelsAndValues...),
|
||||
WithExpBuckets: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: MetricsSubsystem,
|
||||
Name: "with_exp_buckets",
|
||||
Help: "",
|
||||
|
||||
Buckets: stdprometheus.ExponentialBuckets(.1, 100, 8),
|
||||
}, labels).With(labelsAndValues...),
|
||||
WithBuckets: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: MetricsSubsystem,
|
||||
Name: "with_buckets",
|
||||
Help: "",
|
||||
|
||||
Buckets: []float64{1, 2, 3, 4, 5},
|
||||
}, labels).With(labelsAndValues...),
|
||||
Named: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: MetricsSubsystem,
|
||||
Name: "metric_with_name",
|
||||
Help: "",
|
||||
}, labels).With(labelsAndValues...),
|
||||
}
|
||||
}
|
||||
|
||||
func NopMetrics() *Metrics {
|
||||
return &Metrics{
|
||||
WithLabels: discard.NewCounter(),
|
||||
WithExpBuckets: discard.NewHistogram(),
|
||||
WithBuckets: discard.NewHistogram(),
|
||||
Named: discard.NewCounter(),
|
||||
}
|
||||
}
|
||||
12
scripts/metricsgen/testdata/tags/metrics.go
vendored
Normal file
12
scripts/metricsgen/testdata/tags/metrics.go
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
package tags
|
||||
|
||||
import "github.com/go-kit/kit/metrics"
|
||||
|
||||
//go:generate go run ../../../../scripts/metricsgen -struct=Metrics
|
||||
|
||||
type Metrics struct {
|
||||
WithLabels metrics.Counter `metrics_labels:"step,time"`
|
||||
WithExpBuckets metrics.Histogram `metrics_buckettype:"exp" metrics_bucketsizes:".1,100,8"`
|
||||
WithBuckets metrics.Histogram `metrics_bucketsizes:"1, 2, 3, 4, 5"`
|
||||
Named metrics.Counter `metrics_name:"metric_with_name"`
|
||||
}
|
||||
Reference in New Issue
Block a user