mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
Use HandlerFor
This commit is contained in:
parent
49d341aa2b
commit
d9737eabf4
@ -22,7 +22,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
compbasemetrics "k8s.io/component-base/metrics"
|
compbasemetrics "k8s.io/component-base/metrics"
|
||||||
@ -33,6 +32,7 @@ import (
|
|||||||
func TestRecordOperation(t *testing.T) {
|
func TestRecordOperation(t *testing.T) {
|
||||||
// Use local registry
|
// Use local registry
|
||||||
var registry = compbasemetrics.NewKubeRegistry()
|
var registry = compbasemetrics.NewKubeRegistry()
|
||||||
|
var gather compbasemetrics.Gatherer = registry
|
||||||
defer registry.Reset()
|
defer registry.Reset()
|
||||||
registry.MustRegister(metrics.RuntimeOperations)
|
registry.MustRegister(metrics.RuntimeOperations)
|
||||||
registry.MustRegister(metrics.RuntimeOperationsDuration)
|
registry.MustRegister(metrics.RuntimeOperationsDuration)
|
||||||
@ -44,7 +44,7 @@ func TestRecordOperation(t *testing.T) {
|
|||||||
|
|
||||||
prometheusURL := "http://" + l.Addr().String() + "/metrics"
|
prometheusURL := "http://" + l.Addr().String() + "/metrics"
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
handler := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
|
handler := compbasemetrics.HandlerFor(gather, compbasemetrics.HandlerOpts{})
|
||||||
mux.Handle("/metrics", handler)
|
mux.Handle("/metrics", handler)
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Addr: l.Addr().String(),
|
Addr: l.Addr().String(),
|
||||||
|
Loading…
Reference in New Issue
Block a user