Improve tracing
This commit is contained in:
parent
4245096be4
commit
84d7c65039
23 changed files with 924 additions and 411 deletions
|
@ -12,14 +12,12 @@ level = "DEBUG"
|
|||
address = ":8000"
|
||||
|
||||
[tracing]
|
||||
backend = "{{.TracingBackend}}"
|
||||
servicename = "tracing"
|
||||
[tracing.zipkin]
|
||||
httpEndpoint = "http://{{.ZipkinIP}}:9411/api/v1/spans"
|
||||
debug = true
|
||||
[tracing.jaeger]
|
||||
samplingType = "const"
|
||||
samplingParam = 1.0
|
||||
[tracing.jaeger]
|
||||
samplingType = "const"
|
||||
samplingParam = 1.0
|
||||
samplingServerURL = "http://{{.IP}}:5778/sampling"
|
||||
localAgentHostPort = "{{.IP}}:6831"
|
||||
|
||||
[providers]
|
||||
[providers.file]
|
71
integration/fixtures/tracing/simple-zipkin.toml
Normal file
71
integration/fixtures/tracing/simple-zipkin.toml
Normal file
|
@ -0,0 +1,71 @@
|
|||
[global]
|
||||
checkNewVersion = false
|
||||
sendAnonymousUsage = false
|
||||
|
||||
[log]
|
||||
level = "DEBUG"
|
||||
|
||||
[api]
|
||||
|
||||
[entryPoints]
|
||||
[entryPoints.web]
|
||||
address = ":8000"
|
||||
|
||||
[tracing]
|
||||
servicename = "tracing"
|
||||
[tracing.zipkin]
|
||||
httpEndpoint = "http://{{.IP}}:9411/api/v1/spans"
|
||||
debug = true
|
||||
|
||||
[providers]
|
||||
[providers.file]
|
||||
|
||||
[http.routers]
|
||||
[http.routers.router1]
|
||||
Service = "service1"
|
||||
Middlewares = ["retry", "ratelimit"]
|
||||
Rule = "Path(`/ratelimit`)"
|
||||
[http.routers.router2]
|
||||
Service = "service2"
|
||||
Middlewares = ["retry"]
|
||||
Rule = "Path(`/retry`)"
|
||||
[http.routers.router3]
|
||||
Service = "service3"
|
||||
Middlewares = ["retry", "basic-auth"]
|
||||
Rule = "Path(`/auth`)"
|
||||
|
||||
[http.middlewares]
|
||||
[http.middlewares.retry.retry]
|
||||
attempts = 3
|
||||
[http.middlewares.basic-auth.BasicAuth]
|
||||
users = ["test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/", "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"]
|
||||
[http.middlewares.ratelimit.RateLimit]
|
||||
extractorfunc = "client.ip"
|
||||
[http.middlewares.ratelimit.RateLimit.rateset.rateset1]
|
||||
period = "60s"
|
||||
average = 4
|
||||
burst = 5
|
||||
[http.middlewares.ratelimit.RateLimit.rateset.rateset2]
|
||||
period = "3s"
|
||||
average = 1
|
||||
burst = 2
|
||||
|
||||
|
||||
[http.services]
|
||||
[http.services.service1]
|
||||
[http.services.service1.LoadBalancer]
|
||||
passHostHeader = true
|
||||
[[http.services.service1.LoadBalancer.Servers]]
|
||||
URL = "http://{{.WhoAmiIP}}:{{.WhoAmiPort}}"
|
||||
|
||||
[http.services.service2]
|
||||
passHostHeader = true
|
||||
[http.services.service2.LoadBalancer]
|
||||
[[http.services.service2.LoadBalancer.Servers]]
|
||||
URL = "http://{{.WhoAmiIP}}:{{.WhoAmiPort}}"
|
||||
|
||||
[http.services.service3]
|
||||
passHostHeader = true
|
||||
[http.services.service3.LoadBalancer]
|
||||
[[http.services.service3.LoadBalancer.Servers]]
|
||||
URL = "http://{{.WhoAmiIP}}:{{.WhoAmiPort}}"
|
|
@ -6,7 +6,7 @@ zipkin:
|
|||
ports:
|
||||
- 9411:9411
|
||||
jaeger:
|
||||
image: jaegertracing/all-in-one:latest
|
||||
image: jaegertracing/all-in-one:1.12
|
||||
environment:
|
||||
COLLECTOR_ZIPKIN_HTTP_PORT: 9411
|
||||
ports:
|
||||
|
|
|
@ -12,17 +12,15 @@ import (
|
|||
|
||||
type TracingSuite struct {
|
||||
BaseSuite
|
||||
WhoAmiIP string
|
||||
WhoAmiPort int
|
||||
ZipkinIP string
|
||||
TracingBackend string
|
||||
WhoAmiIP string
|
||||
WhoAmiPort int
|
||||
IP string
|
||||
}
|
||||
|
||||
type TracingTemplate struct {
|
||||
WhoAmiIP string
|
||||
WhoAmiPort int
|
||||
ZipkinIP string
|
||||
TracingBackend string
|
||||
WhoAmiIP string
|
||||
WhoAmiPort int
|
||||
IP string
|
||||
}
|
||||
|
||||
func (s *TracingSuite) SetUpSuite(c *check.C) {
|
||||
|
@ -35,21 +33,20 @@ func (s *TracingSuite) SetUpSuite(c *check.C) {
|
|||
|
||||
func (s *TracingSuite) startZipkin(c *check.C) {
|
||||
s.composeProject.Start(c, "zipkin")
|
||||
s.ZipkinIP = s.composeProject.Container(c, "zipkin").NetworkSettings.IPAddress
|
||||
s.TracingBackend = "zipkin"
|
||||
s.IP = s.composeProject.Container(c, "zipkin").NetworkSettings.IPAddress
|
||||
|
||||
// Wait for Zipkin to turn ready.
|
||||
err := try.GetRequest("http://"+s.ZipkinIP+":9411/api/v2/services", 20*time.Second, try.StatusCodeIs(http.StatusOK))
|
||||
err := try.GetRequest("http://"+s.IP+":9411/api/v2/services", 20*time.Second, try.StatusCodeIs(http.StatusOK))
|
||||
c.Assert(err, checker.IsNil)
|
||||
}
|
||||
|
||||
func (s *TracingSuite) TestZipkinRateLimit(c *check.C) {
|
||||
s.startZipkin(c)
|
||||
file := s.adaptFile(c, "fixtures/tracing/simple.toml", TracingTemplate{
|
||||
WhoAmiIP: s.WhoAmiIP,
|
||||
WhoAmiPort: s.WhoAmiPort,
|
||||
ZipkinIP: s.ZipkinIP,
|
||||
TracingBackend: s.TracingBackend,
|
||||
defer s.composeProject.Stop(c, "zipkin")
|
||||
file := s.adaptFile(c, "fixtures/tracing/simple-zipkin.toml", TracingTemplate{
|
||||
WhoAmiIP: s.WhoAmiIP,
|
||||
WhoAmiPort: s.WhoAmiPort,
|
||||
IP: s.IP,
|
||||
})
|
||||
defer os.Remove(file)
|
||||
|
||||
|
@ -89,18 +86,18 @@ func (s *TracingSuite) TestZipkinRateLimit(c *check.C) {
|
|||
err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusTooManyRequests))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
err = try.GetRequest("http://"+s.ZipkinIP+":9411/api/v2/spans?serviceName=tracing", 20*time.Second, try.BodyContains("forward service1/router1@file", "ratelimit@file"))
|
||||
err = try.GetRequest("http://"+s.IP+":9411/api/v2/spans?serviceName=tracing", 20*time.Second, try.BodyContains("forward service1/router1@file", "ratelimit@file"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
}
|
||||
|
||||
func (s *TracingSuite) TestZipkinRetry(c *check.C) {
|
||||
s.startZipkin(c)
|
||||
file := s.adaptFile(c, "fixtures/tracing/simple.toml", TracingTemplate{
|
||||
WhoAmiIP: s.WhoAmiIP,
|
||||
WhoAmiPort: 81,
|
||||
ZipkinIP: s.ZipkinIP,
|
||||
TracingBackend: s.TracingBackend,
|
||||
defer s.composeProject.Stop(c, "zipkin")
|
||||
file := s.adaptFile(c, "fixtures/tracing/simple-zipkin.toml", TracingTemplate{
|
||||
WhoAmiIP: s.WhoAmiIP,
|
||||
WhoAmiPort: 81,
|
||||
IP: s.IP,
|
||||
})
|
||||
defer os.Remove(file)
|
||||
|
||||
|
@ -117,17 +114,17 @@ func (s *TracingSuite) TestZipkinRetry(c *check.C) {
|
|||
err = try.GetRequest("http://127.0.0.1:8000/retry", 500*time.Millisecond, try.StatusCodeIs(http.StatusBadGateway))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
err = try.GetRequest("http://"+s.ZipkinIP+":9411/api/v2/spans?serviceName=tracing", 20*time.Second, try.BodyContains("forward service2/router2@file", "retry@file"))
|
||||
err = try.GetRequest("http://"+s.IP+":9411/api/v2/spans?serviceName=tracing", 20*time.Second, try.BodyContains("forward service2/router2@file", "retry@file"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
}
|
||||
|
||||
func (s *TracingSuite) TestZipkinAuth(c *check.C) {
|
||||
s.startZipkin(c)
|
||||
file := s.adaptFile(c, "fixtures/tracing/simple.toml", TracingTemplate{
|
||||
WhoAmiIP: s.WhoAmiIP,
|
||||
WhoAmiPort: s.WhoAmiPort,
|
||||
ZipkinIP: s.ZipkinIP,
|
||||
TracingBackend: s.TracingBackend,
|
||||
defer s.composeProject.Stop(c, "zipkin")
|
||||
file := s.adaptFile(c, "fixtures/tracing/simple-zipkin.toml", TracingTemplate{
|
||||
WhoAmiIP: s.WhoAmiIP,
|
||||
WhoAmiPort: s.WhoAmiPort,
|
||||
IP: s.IP,
|
||||
})
|
||||
defer os.Remove(file)
|
||||
|
||||
|
@ -144,6 +141,120 @@ func (s *TracingSuite) TestZipkinAuth(c *check.C) {
|
|||
err = try.GetRequest("http://127.0.0.1:8000/auth", 500*time.Millisecond, try.StatusCodeIs(http.StatusUnauthorized))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
err = try.GetRequest("http://"+s.ZipkinIP+":9411/api/v2/spans?serviceName=tracing", 20*time.Second, try.BodyContains("entrypoint web", "basic-auth@file"))
|
||||
err = try.GetRequest("http://"+s.IP+":9411/api/v2/spans?serviceName=tracing", 20*time.Second, try.BodyContains("entrypoint web", "basic-auth@file"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
}
|
||||
|
||||
func (s *TracingSuite) startJaeger(c *check.C) {
|
||||
s.composeProject.Start(c, "jaeger")
|
||||
s.IP = s.composeProject.Container(c, "jaeger").NetworkSettings.IPAddress
|
||||
|
||||
// Wait for Jaeger to turn ready.
|
||||
err := try.GetRequest("http://"+s.IP+":16686/api/services", 20*time.Second, try.StatusCodeIs(http.StatusOK))
|
||||
c.Assert(err, checker.IsNil)
|
||||
}
|
||||
|
||||
func (s *TracingSuite) TestJaegerRateLimit(c *check.C) {
|
||||
s.startJaeger(c)
|
||||
defer s.composeProject.Stop(c, "jaeger")
|
||||
file := s.adaptFile(c, "fixtures/tracing/simple-jaeger.toml", TracingTemplate{
|
||||
WhoAmiIP: s.WhoAmiIP,
|
||||
WhoAmiPort: s.WhoAmiPort,
|
||||
IP: s.IP,
|
||||
})
|
||||
defer os.Remove(file)
|
||||
|
||||
cmd, display := s.traefikCmd(withConfigFile(file))
|
||||
defer display(c)
|
||||
err := cmd.Start()
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer cmd.Process.Kill()
|
||||
|
||||
// wait for traefik
|
||||
err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", time.Second, try.BodyContains("basic-auth"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK))
|
||||
c.Assert(err, checker.IsNil)
|
||||
err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK))
|
||||
c.Assert(err, checker.IsNil)
|
||||
err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusTooManyRequests))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
// sleep for 4 seconds to be certain the configured time period has elapsed
|
||||
// then test another request and verify a 200 status code
|
||||
time.Sleep(4 * time.Second)
|
||||
err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
// continue requests at 3 second intervals to test the other rate limit time period
|
||||
time.Sleep(3 * time.Second)
|
||||
err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
time.Sleep(3 * time.Second)
|
||||
err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
time.Sleep(3 * time.Second)
|
||||
err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusTooManyRequests))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
err = try.GetRequest("http://"+s.IP+":16686/api/traces?service=tracing", 20*time.Second, try.BodyContains("forward service1/router1@file", "ratelimit@file"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
}
|
||||
|
||||
func (s *TracingSuite) TestJaegerRetry(c *check.C) {
|
||||
s.startJaeger(c)
|
||||
defer s.composeProject.Stop(c, "jaeger")
|
||||
file := s.adaptFile(c, "fixtures/tracing/simple-jaeger.toml", TracingTemplate{
|
||||
WhoAmiIP: s.WhoAmiIP,
|
||||
WhoAmiPort: 81,
|
||||
IP: s.IP,
|
||||
})
|
||||
defer os.Remove(file)
|
||||
|
||||
cmd, display := s.traefikCmd(withConfigFile(file))
|
||||
defer display(c)
|
||||
err := cmd.Start()
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer cmd.Process.Kill()
|
||||
|
||||
// wait for traefik
|
||||
err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", time.Second, try.BodyContains("basic-auth"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
err = try.GetRequest("http://127.0.0.1:8000/retry", 500*time.Millisecond, try.StatusCodeIs(http.StatusBadGateway))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
err = try.GetRequest("http://"+s.IP+":16686/api/traces?service=tracing", 20*time.Second, try.BodyContains("forward service2/router2@file", "retry@file"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
}
|
||||
|
||||
func (s *TracingSuite) TestJaegerAuth(c *check.C) {
|
||||
s.startJaeger(c)
|
||||
defer s.composeProject.Stop(c, "jaeger")
|
||||
file := s.adaptFile(c, "fixtures/tracing/simple-jaeger.toml", TracingTemplate{
|
||||
WhoAmiIP: s.WhoAmiIP,
|
||||
WhoAmiPort: s.WhoAmiPort,
|
||||
IP: s.IP,
|
||||
})
|
||||
defer os.Remove(file)
|
||||
|
||||
cmd, display := s.traefikCmd(withConfigFile(file))
|
||||
defer display(c)
|
||||
err := cmd.Start()
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer cmd.Process.Kill()
|
||||
|
||||
// wait for traefik
|
||||
err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", time.Second, try.BodyContains("basic-auth"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
err = try.GetRequest("http://127.0.0.1:8000/auth", 500*time.Millisecond, try.StatusCodeIs(http.StatusUnauthorized))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
err = try.GetRequest("http://"+s.IP+":16686/api/traces?service=tracing", 20*time.Second, try.BodyContains("EntryPoint web", "basic-auth@file"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue