Fix metrics problem on multiple entrypoints
This commit is contained in:
parent
313357a6b3
commit
40b3c17703
4 changed files with 75 additions and 2 deletions
|
@ -189,6 +189,41 @@ func (s *SimpleSuite) TestApiOnSameEntryPoint(c *check.C) {
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SimpleSuite) TestStatsWithMultipleEntryPoint(c *check.C) {
|
||||||
|
s.createComposeProject(c, "stats")
|
||||||
|
s.composeProject.Start(c)
|
||||||
|
|
||||||
|
whoami1 := "http://" + s.composeProject.Container(c, "whoami1").NetworkSettings.IPAddress + ":80"
|
||||||
|
whoami2 := "http://" + s.composeProject.Container(c, "whoami2").NetworkSettings.IPAddress + ":80"
|
||||||
|
|
||||||
|
file := s.adaptFile(c, "fixtures/simple_stats.toml", struct {
|
||||||
|
Server1 string
|
||||||
|
Server2 string
|
||||||
|
}{whoami1, whoami2})
|
||||||
|
cmd, output := s.traefikCmd(withConfigFile(file))
|
||||||
|
defer output(c)
|
||||||
|
|
||||||
|
err := cmd.Start()
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
defer cmd.Process.Kill()
|
||||||
|
|
||||||
|
err = try.GetRequest("http://127.0.0.1:8080/api", 1*time.Second, try.StatusCodeIs(http.StatusOK))
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
|
err = try.GetRequest("http://127.0.0.1:8080/api/providers", 1*time.Second, try.BodyContains("PathPrefix"))
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
|
err = try.GetRequest("http://127.0.0.1:8000/whoami", 1*time.Second, try.StatusCodeIs(http.StatusOK))
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
|
err = try.GetRequest("http://127.0.0.1:8080/whoami", 1*time.Second, try.StatusCodeIs(http.StatusOK))
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
|
err = try.GetRequest("http://127.0.0.1:8080/health", 1*time.Second, try.BodyContains(`"total_status_code_count":{"200":2}`))
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SimpleSuite) TestNoAuthOnPing(c *check.C) {
|
func (s *SimpleSuite) TestNoAuthOnPing(c *check.C) {
|
||||||
s.createComposeProject(c, "base")
|
s.createComposeProject(c, "base")
|
||||||
s.composeProject.Start(c)
|
s.composeProject.Start(c)
|
||||||
|
|
30
integration/fixtures/simple_stats.toml
Normal file
30
integration/fixtures/simple_stats.toml
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
debug=true
|
||||||
|
|
||||||
|
[entryPoints]
|
||||||
|
[entryPoints.http]
|
||||||
|
address = ":8000"
|
||||||
|
|
||||||
|
[api]
|
||||||
|
[file]
|
||||||
|
[backends]
|
||||||
|
[backends.backend1]
|
||||||
|
[backends.backend1.servers.server1]
|
||||||
|
url = "{{ .Server1 }}"
|
||||||
|
[backends.backend2]
|
||||||
|
[backends.backend2.servers.server1]
|
||||||
|
url = "{{ .Server2 }}"
|
||||||
|
|
||||||
|
[frontends]
|
||||||
|
[frontends.frontend1]
|
||||||
|
entrypoints=["http"]
|
||||||
|
|
||||||
|
backend = "backend1"
|
||||||
|
[frontends.frontend1.routes.test_1]
|
||||||
|
rule = "PathPrefix:/whoami"
|
||||||
|
|
||||||
|
[frontends.frontend2]
|
||||||
|
backend = "backend2"
|
||||||
|
entrypoints=["traefik"]
|
||||||
|
|
||||||
|
[frontends.frontend2.routes.test_1]
|
||||||
|
rule = "PathPrefix:/whoami"
|
4
integration/resources/compose/stats.yml
Normal file
4
integration/resources/compose/stats.yml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
whoami1:
|
||||||
|
image: emilevauge/whoami
|
||||||
|
whoami2:
|
||||||
|
image: emilevauge/whoami
|
|
@ -289,10 +289,14 @@ func (s *Server) setupServerEntryPoint(newServerEntryPointName string, newServer
|
||||||
serverMiddlewares = append(serverMiddlewares, middlewares.NewMetricsWrapper(s.metricsRegistry, newServerEntryPointName))
|
serverMiddlewares = append(serverMiddlewares, middlewares.NewMetricsWrapper(s.metricsRegistry, newServerEntryPointName))
|
||||||
}
|
}
|
||||||
if s.globalConfiguration.API != nil {
|
if s.globalConfiguration.API != nil {
|
||||||
s.globalConfiguration.API.Stats = thoas_stats.New()
|
if s.globalConfiguration.API.Stats == nil {
|
||||||
|
s.globalConfiguration.API.Stats = thoas_stats.New()
|
||||||
|
}
|
||||||
serverMiddlewares = append(serverMiddlewares, s.globalConfiguration.API.Stats)
|
serverMiddlewares = append(serverMiddlewares, s.globalConfiguration.API.Stats)
|
||||||
if s.globalConfiguration.API.Statistics != nil {
|
if s.globalConfiguration.API.Statistics != nil {
|
||||||
s.globalConfiguration.API.StatsRecorder = middlewares.NewStatsRecorder(s.globalConfiguration.API.Statistics.RecentErrors)
|
if s.globalConfiguration.API.StatsRecorder == nil {
|
||||||
|
s.globalConfiguration.API.StatsRecorder = middlewares.NewStatsRecorder(s.globalConfiguration.API.Statistics.RecentErrors)
|
||||||
|
}
|
||||||
serverMiddlewares = append(serverMiddlewares, s.globalConfiguration.API.StatsRecorder)
|
serverMiddlewares = append(serverMiddlewares, s.globalConfiguration.API.StatsRecorder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue