Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d29bd0810b | |||
| b62c0e5a8c | |||
| a9eb0d0732 | |||
| 92b84685c9 | |||
| cd6e62e3bc | |||
| 7cf2d91fd8 | |||
| 936982731d | |||
| 33759c87db | |||
| 974f82e9be | |||
| d7dc75c18f | |||
| c62c63249c | |||
| 6c290eb66b | |||
| 31ce7fc48e | |||
| 99957861dc | |||
| 19d27b4ff6 | |||
| 7f2025ef6f |
@@ -17,6 +17,7 @@ type Service struct {
|
|||||||
appID string
|
appID string
|
||||||
domain string
|
domain string
|
||||||
pathPrefix string
|
pathPrefix string
|
||||||
|
tls bool
|
||||||
port int
|
port int
|
||||||
ttl time.Duration
|
ttl time.Duration
|
||||||
client *consul.Client
|
client *consul.Client
|
||||||
@@ -24,8 +25,8 @@ type Service struct {
|
|||||||
connect *connect.Service
|
connect *connect.Service
|
||||||
kv *consul.KV
|
kv *consul.KV
|
||||||
|
|
||||||
hcTicker *time.Ticker
|
// hcTicker *time.Ticker
|
||||||
ttlTicker *time.Ticker
|
// ttlTicker *time.Ticker
|
||||||
}
|
}
|
||||||
|
|
||||||
var ErrServiceUnavailable = fmt.Errorf("Service is unavailable")
|
var ErrServiceUnavailable = fmt.Errorf("Service is unavailable")
|
||||||
@@ -37,6 +38,7 @@ func NewService(servAddr, id, name, useDomainOverIp, addr, domain, pathPrefix st
|
|||||||
s.appID = id
|
s.appID = id
|
||||||
s.domain = domain
|
s.domain = domain
|
||||||
s.pathPrefix = pathPrefix
|
s.pathPrefix = pathPrefix
|
||||||
|
s.tls = true // FIXME add arg
|
||||||
s.port = appPort
|
s.port = appPort
|
||||||
s.ttl = time.Second * 10
|
s.ttl = time.Second * 10
|
||||||
|
|
||||||
@@ -68,12 +70,11 @@ func (s *Service) GetID() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) GetFullAddr() string {
|
func (s *Service) GetFullAddr() string {
|
||||||
isTLS := s.port == 443
|
|
||||||
proto := "http"
|
proto := "http"
|
||||||
if isTLS {
|
if s.tls {
|
||||||
proto = "https"
|
proto = "https"
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s://%s:%d/", proto, s.Address, s.port)
|
return fmt.Sprintf("%s://%s:%d/", proto, s.domain, s.port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) Register() error {
|
func (s *Service) Register() error {
|
||||||
@@ -89,6 +90,8 @@ func (s *Service) Register() error {
|
|||||||
// DestinationServiceName: s.Name,
|
// DestinationServiceName: s.Name,
|
||||||
// },
|
// },
|
||||||
Check: &consul.AgentServiceCheck{
|
Check: &consul.AgentServiceCheck{
|
||||||
|
Interval: "5s",
|
||||||
|
Timeout: "1s",
|
||||||
TTL: s.ttl.String(),
|
TTL: s.ttl.String(),
|
||||||
Status: "passing",
|
Status: "passing",
|
||||||
DeregisterCriticalServiceAfter: "10s",
|
DeregisterCriticalServiceAfter: "10s",
|
||||||
@@ -158,6 +161,7 @@ func (s *Service) healthCheck() (bool, error) {
|
|||||||
alive := func() bool {
|
alive := func() bool {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
healthUrl := fmt.Sprintf("%s%s?name=%s", s.GetFullAddr(), "health", s.Name)
|
healthUrl := fmt.Sprintf("%s%s?name=%s", s.GetFullAddr(), "health", s.Name)
|
||||||
|
// fmt.Printf("HealthCheck URL: %s%s?name=%s", s.GetFullAddr(), "health", s.Name)
|
||||||
req, err := http.NewRequest(http.MethodGet, healthUrl, nil)
|
req, err := http.NewRequest(http.MethodGet, healthUrl, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
@@ -196,26 +200,25 @@ func (s *Service) getTags() []string {
|
|||||||
// "traefik.http.middlewares.auth_" + s.Name + ".forwardauth.trustForwardHeader=true",
|
// "traefik.http.middlewares.auth_" + s.Name + ".forwardauth.trustForwardHeader=true",
|
||||||
// "traefik.http.middlewares.auth_" + s.Name + ".forwardauth.authRequestHeaders=Cookie",
|
// "traefik.http.middlewares.auth_" + s.Name + ".forwardauth.authRequestHeaders=Cookie",
|
||||||
// "traefik.http.middlewares.auth_" + s.Name + ".forwardauth.authResponseHeaders=Set-Cookie, Server",
|
// "traefik.http.middlewares.auth_" + s.Name + ".forwardauth.authResponseHeaders=Set-Cookie, Server",
|
||||||
"traefik.http.middlewares.auth_" + s.Name + ".plugin.auth.handlerURL=" + config.GetEnv("AUTH_HANDLER_URL", "http://identity.service.ego.io/api/v1/traefik"),
|
"traefik.http.middlewares.auth_" + s.Name + ".plugin.auth.handlerURL=" + config.GetEnv("AUTH_HANDLER_URL", "https://identity.service.ego.io/api/v1/traefik"),
|
||||||
"traefik.http.middlewares.stripprefix_" + s.Name + ".stripprefix.prefixes=" + s.pathPrefix,
|
"traefik.http.middlewares.stripprefix_" + s.Name + ".stripprefix.prefixes=" + s.pathPrefix,
|
||||||
"traefik.http.middlewares.requestid_" + s.Name + ".plugin.requestid.headerName=X-Request-ID",
|
"traefik.http.middlewares.requestid_" + s.Name + ".plugin.requestid.headerName=X-Request-ID",
|
||||||
// "treafik.http.middlewares.retryif_" + s.Name + ".plugin.retryif.attempts=3",
|
// "treafik.http.middlewares.retryif_" + s.Name + ".plugin.retryif.attempts=3",
|
||||||
// "treafik.http.middlewares.retryif_" + s.Name + ".plugin.retryif.statusCode=503",
|
// "treafik.http.middlewares.retryif_" + s.Name + ".plugin.retryif.statusCode=503",
|
||||||
"traefik.http.routers." + s.Name + ".rule=PathPrefix(`" + s.pathPrefix + "`)",
|
"traefik.http.routers." + s.Name + ".rule=Host(`" + s.domain + "`) && PathPrefix(`" + s.pathPrefix + "`)",
|
||||||
// "traefik.http.routers." + s.Name + ".rule=Host(`" + s.domain + "`)",
|
|
||||||
"traefik.http.routers." + s.Name + ".entryPoints=https",
|
"traefik.http.routers." + s.Name + ".entryPoints=https",
|
||||||
// "traefik.http.routers." + s.Name + ".tls=true",
|
"traefik.http.routers." + s.Name + ".tls=true",
|
||||||
"traefik.http.routers." + s.Name + ".service=" + s.Name,
|
"traefik.http.routers." + s.Name + ".service=" + s.Name,
|
||||||
// "traefik.http.routers." + s.Name + ".middlewares=auth_" + s.Name + ",stripprefix_" + s.Name,
|
// "traefik.http.routers." + s.Name + ".middlewares=auth_" + s.Name + ",stripprefix_" + s.Name,
|
||||||
"traefik.http.routers." + s.Name + ".middlewares=auth_" + s.Name + ",stripprefix_" + s.Name + ",requestid_" + s.Name + "",
|
"traefik.http.routers." + s.Name + ".middlewares=auth_" + s.Name + ",stripprefix_" + s.Name + ",requestid_" + s.Name + "",
|
||||||
"traefik.http.services." + s.Name + ".loadbalancer.server.scheme=http",
|
"traefik.http.services." + s.Name + ".loadbalancer.server.scheme=https",
|
||||||
"traefik.http.services." + s.Name + ".loadbalancer.server.port=" + strconv.Itoa(s.port),
|
"traefik.http.services." + s.Name + ".loadbalancer.server.port=" + strconv.Itoa(s.port),
|
||||||
"traefik.http.services." + s.Name + ".loadbalancer.passhostheader=true",
|
"traefik.http.services." + s.Name + ".loadbalancer.passhostheader=true",
|
||||||
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.interval=1s",
|
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.interval=5s",
|
||||||
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.timeout=1s",
|
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.timeout=1s",
|
||||||
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.path=/health",
|
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.path=/health",
|
||||||
"traefik.tls.certificates.certfile=/certs/client.cert",
|
"traefik.tls.certificates.certfile=certs/client.crt",
|
||||||
"traefik.tls.certificates.keyfile=/certs/client.key",
|
"traefik.tls.certificates.keyfile=certs/client.key",
|
||||||
}
|
}
|
||||||
|
|
||||||
return tags
|
return tags
|
||||||
|
|||||||
Reference in New Issue
Block a user