Skip to content
Permalink
Browse files

config: deal with multiple errors and their critcity

  • Loading branch information...
juliens authored and mpl committed Jul 4, 2019
1 parent 39aae41 commit 930456a76612e14bb1b127660a715f1b9b2134f0
@@ -0,0 +1,45 @@
[global]
checkNewVersion = false
sendAnonymousUsage = false

[log]
level = "DEBUG"

[entryPoints]
[entryPoints.web-secure]
address = ":4443"

[api]

[providers]
[providers.file]

## dynamic configuration ##

[http.routers]
[http.routers.router4]
service = "service1"
rule = "Host(`snitest.net`)"
[http.routers.router4.tls]
options = "foo"

[http.routers.router5]
service = "service1"
rule = "Host(`snitest.net`)"
middlewares = [ "unknown" ]
[http.routers.router5.tls]
options = "baz"

[http.services]
[http.services.service1]
[http.services.service1.loadBalancer]
[[http.services.service1.loadBalancer.servers]]
url = "http://127.0.0.1:9010"

[tls.options]

[tls.options.foo]
minversion = "VersionTLS11"

[tls.options.baz]
minversion = "VersionTLS11"
@@ -0,0 +1,34 @@
[global]
checkNewVersion = false
sendAnonymousUsage = false

[log]
level = "DEBUG"

[entryPoints]
[entryPoints.web-secure]
address = ":4443"

[api]

[providers]
[providers.file]

## dynamic configuration ##

[http.routers]
[http.routers.router4]
service = "service1"
rule = "Host(`snitest.net`)"

[http.routers.router5]
service = "service2"
rule = "Host(`snitest.com`)"

[http.services]
[http.services.service1]

[http.services.service2]
[http.services.service2.loadBalancer]
[[http.services.service2.loadBalancer.servers]]
url = "http://127.0.0.1:9010"
@@ -519,3 +519,41 @@ func (s *SimpleSuite) TestSimpleConfigurationHostRequestTrailingPeriod(c *check.
}
}
}

func (s *SimpleSuite) TestRouterConfigErrors(c *check.C) {
cmd, output := s.traefikCmd(withConfigFile("fixtures/router_errors.toml"))
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/http/routers", 1000*time.Millisecond, try.BodyContains("[\"middleware \\\"unknown@file\\\" does not exist\",\"found different TLS options for routers on the same host snitest.net, so using the default TLS option instead\"]"))
c.Assert(err, checker.IsNil)

err = try.GetRequest("http://127.0.0.1:8080/api/http/routers/router4@file", 1000*time.Millisecond, try.BodyContains("\"status\":\"enabled\""))
c.Assert(err, checker.IsNil)

err = try.GetRequest("http://127.0.0.1:8080/api/http/routers/router5@file", 1000*time.Millisecond, try.BodyContains("\"status\":\"disabled\""))
c.Assert(err, checker.IsNil)

}

func (s *SimpleSuite) TestServiceConfigErrors(c *check.C) {
cmd, output := s.traefikCmd(withConfigFile("fixtures/service_errors.toml"))
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/http/services", 1000*time.Millisecond, try.BodyContains(`["the service \"service1@file\" doesn't have any load balancer"]`))
c.Assert(err, checker.IsNil)

err = try.GetRequest("http://127.0.0.1:8080/api/http/services/service1@file", 1000*time.Millisecond, try.BodyContains("\"status\":\"disabled\""))
c.Assert(err, checker.IsNil)

err = try.GetRequest("http://127.0.0.1:8080/api/http/services/service2@file", 1000*time.Millisecond, try.BodyContains("\"status\":\"enabled\""))
c.Assert(err, checker.IsNil)

}
@@ -26,12 +26,18 @@ const nextPageHeader = "X-Next-Page"

type serviceInfoRepresentation struct {
*config.ServiceInfo
Status string `json:"status,omitempty"`
ServerStatus map[string]string `json:"serverStatus,omitempty"`
}

type routerInfoRepresentation struct {
*config.RouterInfo
Status string `json:"status,omitempty"`
}

// RunTimeRepresentation is the configuration information exposed by the API handler.
type RunTimeRepresentation struct {
Routers map[string]*config.RouterInfo `json:"routers,omitempty"`
Routers map[string]*routerInfoRepresentation `json:"routers,omitempty"`
Middlewares map[string]*config.MiddlewareInfo `json:"middlewares,omitempty"`
Services map[string]*serviceInfoRepresentation `json:"services,omitempty"`
TCPRouters map[string]*config.TCPRouterInfo `json:"tcpRouters,omitempty"`
@@ -40,12 +46,14 @@ type RunTimeRepresentation struct {

type routerRepresentation struct {
*config.RouterInfo
Status string `json:"status,omitempty"`
Name string `json:"name,omitempty"`
Provider string `json:"provider,omitempty"`
}

type serviceRepresentation struct {
*config.ServiceInfo
Status string `json:"status,omitempty"`
ServerStatus map[string]string `json:"serverStatus,omitempty"`
Name string `json:"name,omitempty"`
Provider string `json:"provider,omitempty"`
@@ -141,6 +149,7 @@ func (h Handler) getRouters(rw http.ResponseWriter, request *http.Request) {
for name, rt := range h.runtimeConfiguration.Routers {
results = append(results, routerRepresentation{
RouterInfo: rt,
Status: rt.Status(),
Name: name,
Provider: getProviderName(name),
})
@@ -177,6 +186,7 @@ func (h Handler) getRouter(rw http.ResponseWriter, request *http.Request) {

result := routerRepresentation{
RouterInfo: router,
Status: router.Status(),
Name: routerID,
Provider: getProviderName(routerID),
}
@@ -198,6 +208,7 @@ func (h Handler) getServices(rw http.ResponseWriter, request *http.Request) {
ServiceInfo: si,
Name: name,
Provider: getProviderName(name),
Status: si.Status(),
ServerStatus: si.GetAllStatus(),
})
}
@@ -235,6 +246,7 @@ func (h Handler) getService(rw http.ResponseWriter, request *http.Request) {
ServiceInfo: service,
Name: serviceID,
Provider: getProviderName(serviceID),
Status: service.Status(),
ServerStatus: service.GetAllStatus(),
}

@@ -418,11 +430,20 @@ func (h Handler) getRuntimeConfiguration(rw http.ResponseWriter, request *http.R
siRepr[k] = &serviceInfoRepresentation{
ServiceInfo: v,
ServerStatus: v.GetAllStatus(),
Status: v.Status(),
}
}

riRepr := make(map[string]*routerInfoRepresentation, len(h.runtimeConfiguration.Routers))
for k, v := range h.runtimeConfiguration.Routers {
riRepr[k] = &routerInfoRepresentation{
RouterInfo: v,
Status: v.Status(),
}
}

result := RunTimeRepresentation{
Routers: h.runtimeConfiguration.Routers,
Routers: riRepr,
Middlewares: h.runtimeConfiguration.Middlewares,
Services: siRepr,
TCPRouters: h.runtimeConfiguration.TCPRouters,
@@ -548,7 +548,7 @@ func TestHandlerHTTP_API(t *testing.T) {
},
UsedBy: []string{"foo@myprovider", "test@myprovider"},
}
si.UpdateStatus("http://127.0.0.1", "UP")
si.UpdateServerStatus("http://127.0.0.1", "UP")
return si
}(),
"baz@myprovider": func() *config.ServiceInfo {
@@ -564,7 +564,7 @@ func TestHandlerHTTP_API(t *testing.T) {
},
UsedBy: []string{"foo@myprovider"},
}
si.UpdateStatus("http://127.0.0.2", "UP")
si.UpdateServerStatus("http://127.0.0.2", "UP")
return si
}(),
},
@@ -593,7 +593,7 @@ func TestHandlerHTTP_API(t *testing.T) {
},
UsedBy: []string{"foo@myprovider", "test@myprovider"},
}
si.UpdateStatus("http://127.0.0.1", "UP")
si.UpdateServerStatus("http://127.0.0.1", "UP")
return si
}(),
"baz@myprovider": func() *config.ServiceInfo {
@@ -609,7 +609,7 @@ func TestHandlerHTTP_API(t *testing.T) {
},
UsedBy: []string{"foo@myprovider"},
}
si.UpdateStatus("http://127.0.0.2", "UP")
si.UpdateServerStatus("http://127.0.0.2", "UP")
return si
}(),
"test@myprovider": func() *config.ServiceInfo {
@@ -625,7 +625,7 @@ func TestHandlerHTTP_API(t *testing.T) {
},
UsedBy: []string{"foo@myprovider", "test@myprovider"},
}
si.UpdateStatus("http://127.0.0.4", "UP")
si.UpdateServerStatus("http://127.0.0.4", "UP")
return si
}(),
},
@@ -654,7 +654,7 @@ func TestHandlerHTTP_API(t *testing.T) {
},
UsedBy: []string{"foo@myprovider", "test@myprovider"},
}
si.UpdateStatus("http://127.0.0.1", "UP")
si.UpdateServerStatus("http://127.0.0.1", "UP")
return si
}(),
},
@@ -682,7 +682,7 @@ func TestHandlerHTTP_API(t *testing.T) {
},
UsedBy: []string{"foo@myprovider", "test@myprovider"},
}
si.UpdateStatus("http://127.0.0.1", "UP")
si.UpdateServerStatus("http://127.0.0.1", "UP")
return si
}(),
},
@@ -9,7 +9,8 @@
"addPrefixTest@anotherprovider"
],
"service": "foo-service@myprovider",
"rule": "Host(`foo.bar`)"
"rule": "Host(`foo.bar`)",
"status": "enabled"
},
"test@myprovider": {
"entryPoints": [
@@ -20,7 +21,8 @@
"auth"
],
"service": "foo-service@myprovider",
"rule": "Host(`foo.bar.other`)"
"rule": "Host(`foo.bar.other`)",
"status": "enabled"
}
},
"middlewares": {
@@ -65,7 +67,8 @@
"usedBy": [
"bar@myprovider",
"test@myprovider"
]
],
"status": "enabled"
}
},
"tcpRouters": {
@@ -9,5 +9,6 @@
"name": "bar@myprovider",
"provider": "myprovider",
"rule": "Host(`foo.bar`)",
"service": "foo-service@myprovider"
"service": "foo-service@myprovider",
"status": "enabled"
}
@@ -6,7 +6,8 @@
"name": "bar14@myprovider",
"provider": "myprovider",
"rule": "Host(`foo.bar14`)",
"service": "foo-service@myprovider"
"service": "foo-service@myprovider",
"status": "enabled"
},
{
"entryPoints": [
@@ -15,7 +16,8 @@
"name": "bar15@myprovider",
"provider": "myprovider",
"rule": "Host(`foo.bar15`)",
"service": "foo-service@myprovider"
"service": "foo-service@myprovider",
"status": "enabled"
},
{
"entryPoints": [
@@ -24,7 +26,8 @@
"name": "bar16@myprovider",
"provider": "myprovider",
"rule": "Host(`foo.bar16`)",
"service": "foo-service@myprovider"
"service": "foo-service@myprovider",
"status": "enabled"
},
{
"entryPoints": [
@@ -33,7 +36,8 @@
"name": "bar17@myprovider",
"provider": "myprovider",
"rule": "Host(`foo.bar17`)",
"service": "foo-service@myprovider"
"service": "foo-service@myprovider",
"status": "enabled"
},
{
"entryPoints": [
@@ -42,6 +46,7 @@
"name": "bar18@myprovider",
"provider": "myprovider",
"rule": "Host(`foo.bar18`)",
"service": "foo-service@myprovider"
"service": "foo-service@myprovider",
"status": "enabled"
}
]
@@ -6,6 +6,7 @@
"name": "baz@myprovider",
"provider": "myprovider",
"rule": "Host(`toto.bar`)",
"service": "foo-service@myprovider"
"service": "foo-service@myprovider",
"status": "enabled"
}
]
@@ -10,7 +10,8 @@
"name": "bar@myprovider",
"provider": "myprovider",
"rule": "Host(`foo.bar`)",
"service": "foo-service@myprovider"
"service": "foo-service@myprovider",
"status": "enabled"
},
{
"entryPoints": [
@@ -23,6 +24,7 @@
"name": "test@myprovider",
"provider": "myprovider",
"rule": "Host(`foo.bar.other`)",
"service": "foo-service@myprovider"
"service": "foo-service@myprovider",
"status": "enabled"
}
]

0 comments on commit 930456a

Please sign in to comment.
You can’t perform that action at this time.