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:
Sam Kleinman
2022-08-03 10:02:18 -04:00
committed by Sam Ricotta
parent 5733a0c737
commit 4228b80c15
10 changed files with 1014 additions and 0 deletions

View 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(),
}
}

View 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
}