Add Metrics
This commit is contained in:
parent
4dc448056c
commit
8e97af8dc3
121 changed files with 8364 additions and 3811 deletions
|
@ -306,7 +306,7 @@ func TestRouterManager_Get(t *testing.T) {
|
|||
Middlewares: test.middlewaresConfig,
|
||||
},
|
||||
})
|
||||
serviceManager := service.NewManager(rtConf.Services, http.DefaultTransport)
|
||||
serviceManager := service.NewManager(rtConf.Services, http.DefaultTransport, nil)
|
||||
middlewaresBuilder := middleware.NewBuilder(rtConf.Middlewares, serviceManager)
|
||||
responseModifierFactory := responsemodifiers.NewBuilder(rtConf.Middlewares)
|
||||
routerManager := NewManager(rtConf, serviceManager, middlewaresBuilder, responseModifierFactory)
|
||||
|
@ -407,7 +407,7 @@ func TestAccessLog(t *testing.T) {
|
|||
Middlewares: test.middlewaresConfig,
|
||||
},
|
||||
})
|
||||
serviceManager := service.NewManager(rtConf.Services, http.DefaultTransport)
|
||||
serviceManager := service.NewManager(rtConf.Services, http.DefaultTransport, nil)
|
||||
middlewaresBuilder := middleware.NewBuilder(rtConf.Middlewares, serviceManager)
|
||||
responseModifierFactory := responsemodifiers.NewBuilder(rtConf.Middlewares)
|
||||
routerManager := NewManager(rtConf, serviceManager, middlewaresBuilder, responseModifierFactory)
|
||||
|
@ -693,7 +693,7 @@ func TestRuntimeConfiguration(t *testing.T) {
|
|||
Middlewares: test.middlewareConfig,
|
||||
},
|
||||
})
|
||||
serviceManager := service.NewManager(rtConf.Services, http.DefaultTransport)
|
||||
serviceManager := service.NewManager(rtConf.Services, http.DefaultTransport, nil)
|
||||
middlewaresBuilder := middleware.NewBuilder(rtConf.Middlewares, serviceManager)
|
||||
responseModifierFactory := responsemodifiers.NewBuilder(map[string]*runtime.MiddlewareInfo{})
|
||||
routerManager := NewManager(rtConf, serviceManager, middlewaresBuilder, responseModifierFactory)
|
||||
|
@ -767,7 +767,7 @@ func BenchmarkRouterServe(b *testing.B) {
|
|||
Middlewares: map[string]*dynamic.Middleware{},
|
||||
},
|
||||
})
|
||||
serviceManager := service.NewManager(rtConf.Services, &staticTransport{res})
|
||||
serviceManager := service.NewManager(rtConf.Services, &staticTransport{res}, nil)
|
||||
middlewaresBuilder := middleware.NewBuilder(rtConf.Middlewares, serviceManager)
|
||||
responseModifierFactory := responsemodifiers.NewBuilder(rtConf.Middlewares)
|
||||
routerManager := NewManager(rtConf, serviceManager, middlewaresBuilder, responseModifierFactory)
|
||||
|
@ -808,7 +808,7 @@ func BenchmarkService(b *testing.B) {
|
|||
Services: serviceConfig,
|
||||
},
|
||||
})
|
||||
serviceManager := service.NewManager(rtConf.Services, &staticTransport{res})
|
||||
serviceManager := service.NewManager(rtConf.Services, &staticTransport{res}, nil)
|
||||
w := httptest.NewRecorder()
|
||||
req := testhelpers.MustNewRequest(http.MethodGet, "http://foo.bar/", nil)
|
||||
|
||||
|
|
|
@ -12,7 +12,9 @@ import (
|
|||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/config/runtime"
|
||||
"github.com/containous/traefik/pkg/log"
|
||||
"github.com/containous/traefik/pkg/metrics"
|
||||
"github.com/containous/traefik/pkg/middlewares/accesslog"
|
||||
metricsmiddleware "github.com/containous/traefik/pkg/middlewares/metrics"
|
||||
"github.com/containous/traefik/pkg/middlewares/requestdecorator"
|
||||
"github.com/containous/traefik/pkg/middlewares/tracing"
|
||||
"github.com/containous/traefik/pkg/responsemodifiers"
|
||||
|
@ -49,7 +51,13 @@ func (s *Server) loadConfiguration(configMsg dynamic.Message) {
|
|||
listener(*configMsg.Configuration)
|
||||
}
|
||||
|
||||
s.postLoadConfiguration()
|
||||
if s.metricsRegistry.IsEpEnabled() || s.metricsRegistry.IsSvcEnabled() {
|
||||
var entrypoints []string
|
||||
for key := range s.entryPointsTCP {
|
||||
entrypoints = append(entrypoints, key)
|
||||
}
|
||||
metrics.OnConfigurationUpdate(newConfigurations, entrypoints)
|
||||
}
|
||||
}
|
||||
|
||||
// loadConfigurationTCP returns a new gorilla.mux Route from the specified global configuration and the dynamic
|
||||
|
@ -89,7 +97,7 @@ func (s *Server) createTCPRouters(ctx context.Context, configuration *runtime.Co
|
|||
|
||||
// createHTTPHandlers returns, for the given configuration and entryPoints, the HTTP handlers for non-TLS connections, and for the TLS ones. the given configuration must not be nil. its fields will get mutated.
|
||||
func (s *Server) createHTTPHandlers(ctx context.Context, configuration *runtime.Configuration, entryPoints []string) (map[string]http.Handler, map[string]http.Handler) {
|
||||
serviceManager := service.NewManager(configuration.Services, s.defaultRoundTripper)
|
||||
serviceManager := service.NewManager(configuration.Services, s.defaultRoundTripper, s.metricsRegistry)
|
||||
middlewaresBuilder := middleware.NewBuilder(configuration.Middlewares, serviceManager)
|
||||
responseModifierFactory := responsemodifiers.NewBuilder(configuration.Middlewares)
|
||||
routerManager := router.NewManager(configuration, serviceManager, middlewaresBuilder, responseModifierFactory)
|
||||
|
@ -128,6 +136,10 @@ func (s *Server) createHTTPHandlers(ctx context.Context, configuration *runtime.
|
|||
chain = chain.Append(tracing.WrapEntryPointHandler(ctx, s.tracer, entryPointName))
|
||||
}
|
||||
|
||||
if s.metricsRegistry.IsEpEnabled() {
|
||||
chain = chain.Append(metricsmiddleware.WrapEntryPointHandler(ctx, s.metricsRegistry, entryPointName))
|
||||
}
|
||||
|
||||
chain = chain.Append(requestdecorator.WrapHandler(s.requestDecorator))
|
||||
|
||||
handler, err := chain.Then(internalMuxRouter.NotFoundHandler)
|
||||
|
@ -266,15 +278,6 @@ func (s *Server) throttleProviderConfigReload(throttle time.Duration, publish ch
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Server) postLoadConfiguration() {
|
||||
// FIXME metrics
|
||||
// if s.metricsRegistry.IsEnabled() {
|
||||
// activeConfig := s.currentConfigurations.Get().(config.Configurations)
|
||||
// metrics.OnConfigurationUpdate(activeConfig)
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
func buildDefaultHTTPRouter() *mux.Router {
|
||||
rt := mux.NewRouter()
|
||||
rt.NotFoundHandler = http.HandlerFunc(http.NotFound)
|
||||
|
|
|
@ -13,8 +13,10 @@ import (
|
|||
"github.com/containous/traefik/pkg/config/runtime"
|
||||
"github.com/containous/traefik/pkg/healthcheck"
|
||||
"github.com/containous/traefik/pkg/log"
|
||||
"github.com/containous/traefik/pkg/metrics"
|
||||
"github.com/containous/traefik/pkg/middlewares/accesslog"
|
||||
"github.com/containous/traefik/pkg/middlewares/emptybackendhandler"
|
||||
metricsMiddle "github.com/containous/traefik/pkg/middlewares/metrics"
|
||||
"github.com/containous/traefik/pkg/middlewares/pipelining"
|
||||
"github.com/containous/traefik/pkg/server/cookie"
|
||||
"github.com/containous/traefik/pkg/server/internal"
|
||||
|
@ -27,8 +29,9 @@ const (
|
|||
)
|
||||
|
||||
// NewManager creates a new Manager
|
||||
func NewManager(configs map[string]*runtime.ServiceInfo, defaultRoundTripper http.RoundTripper) *Manager {
|
||||
func NewManager(configs map[string]*runtime.ServiceInfo, defaultRoundTripper http.RoundTripper, metricsRegistry metrics.Registry) *Manager {
|
||||
return &Manager{
|
||||
metricsRegistry: metricsRegistry,
|
||||
bufferPool: newBufferPool(),
|
||||
defaultRoundTripper: defaultRoundTripper,
|
||||
balancers: make(map[string][]healthcheck.BalancerHandler),
|
||||
|
@ -38,6 +41,7 @@ func NewManager(configs map[string]*runtime.ServiceInfo, defaultRoundTripper htt
|
|||
|
||||
// Manager The service manager
|
||||
type Manager struct {
|
||||
metricsRegistry metrics.Registry
|
||||
bufferPool httputil.BufferPool
|
||||
defaultRoundTripper http.RoundTripper
|
||||
balancers map[string][]healthcheck.BalancerHandler
|
||||
|
@ -87,8 +91,12 @@ func (m *Manager) getLoadBalancerServiceHandler(
|
|||
alHandler := func(next http.Handler) (http.Handler, error) {
|
||||
return accesslog.NewFieldHandler(next, accesslog.ServiceName, serviceName, accesslog.AddServiceFields), nil
|
||||
}
|
||||
chain := alice.New()
|
||||
if m.metricsRegistry != nil && m.metricsRegistry.IsSvcEnabled() {
|
||||
chain = chain.Append(metricsMiddle.WrapServiceHandler(ctx, m.metricsRegistry, serviceName))
|
||||
}
|
||||
|
||||
handler, err := alice.New().Append(alHandler).Then(pipelining.New(ctx, fwd, "pipelining"))
|
||||
handler, err := chain.Append(alHandler).Then(pipelining.New(ctx, fwd, "pipelining"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ func TestGetLoadBalancer(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetLoadBalancerServiceHandler(t *testing.T) {
|
||||
sm := NewManager(nil, http.DefaultTransport)
|
||||
sm := NewManager(nil, http.DefaultTransport, nil)
|
||||
|
||||
server1 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("X-From", "first")
|
||||
|
@ -332,7 +332,7 @@ func TestManager_Build(t *testing.T) {
|
|||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
manager := NewManager(test.configs, http.DefaultTransport)
|
||||
manager := NewManager(test.configs, http.DefaultTransport, nil)
|
||||
|
||||
ctx := context.Background()
|
||||
if len(test.providerName) > 0 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue