Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0aa79c7d35 | |||
| d484c0e3b0 | |||
| 7a35d1f44a | |||
| 7bfd048051 | |||
| 1433b69abe | |||
| c49ec85b3b | |||
| bdac1d5bc9 |
@@ -6,6 +6,7 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"git.pbiernat.dev/egommerce/go-api-pkg/config"
|
||||
consul "github.com/hashicorp/consul/api"
|
||||
)
|
||||
|
||||
@@ -32,7 +33,7 @@ func NewService(servAddr, id, name, hostname, domain, pathPrefix string, appPort
|
||||
s.domain = domain
|
||||
s.pathPrefix = pathPrefix
|
||||
s.port = appPort
|
||||
s.ttl = time.Second * 15
|
||||
s.ttl = time.Second * 10
|
||||
|
||||
client, err := consul.NewClient(newClientConfig(servAddr))
|
||||
if err != nil {
|
||||
@@ -53,7 +54,7 @@ func newClientConfig(serverAddr string) *consul.Config {
|
||||
}
|
||||
|
||||
func (s *Service) GetID() string {
|
||||
return fmt.Sprintf("%s_%s", s.Name, s.appID)
|
||||
return fmt.Sprintf("%s:%s", s.Name, s.appID)
|
||||
}
|
||||
|
||||
func (s *Service) GetFullAddr() string {
|
||||
@@ -69,7 +70,7 @@ func (s *Service) Register() error {
|
||||
Tags: s.getTags(),
|
||||
Check: &consul.AgentServiceCheck{
|
||||
TTL: s.ttl.String(),
|
||||
DeregisterCriticalServiceAfter: "5s",
|
||||
DeregisterCriticalServiceAfter: "10s",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -78,7 +79,7 @@ func (s *Service) Register() error {
|
||||
}
|
||||
|
||||
go func(s *Service) { // startup register
|
||||
ticker := time.NewTicker(time.Millisecond * 100)
|
||||
ticker := time.NewTicker(time.Second * 1)
|
||||
for range ticker.C {
|
||||
if ok, _ := s.healthCheck(); ok {
|
||||
ticker.Stop()
|
||||
@@ -86,15 +87,15 @@ func (s *Service) Register() error {
|
||||
}
|
||||
}(s)
|
||||
|
||||
go func(s *Service) { // TTL
|
||||
interval := s.ttl - time.Second*2 // 2 seconds overhead
|
||||
ticker := time.NewTicker(interval)
|
||||
for range ticker.C {
|
||||
if _, err := s.healthCheck(); err != nil {
|
||||
fmt.Printf("TTL Error: %v\n", err)
|
||||
}
|
||||
}
|
||||
}(s)
|
||||
// go func(s *Service) { // TTL
|
||||
// interval := s.ttl - time.Second*2 // 2 seconds overhead
|
||||
// ticker := time.NewTicker(interval)
|
||||
// for range ticker.C {
|
||||
// if _, err := s.healthCheck(); err != nil {
|
||||
// fmt.Printf("TTL Error #: %v\n", err)
|
||||
// }
|
||||
// }
|
||||
// }(s)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -153,7 +154,7 @@ func (s *Service) getTags() []string {
|
||||
"traefik.http.services." + s.Name + ".loadbalancer.server.scheme=http",
|
||||
"traefik.http.services." + s.Name + ".loadbalancer.server.port=" + strconv.Itoa(s.port),
|
||||
"traefik.http.services." + s.Name + ".loadbalancer.passhostheader=false",
|
||||
"traefik.http.middlewares.auth_" + s.Name + ".plugin.auth.handlerURL="",
|
||||
"traefik.http.middlewares.auth_" + s.Name + ".plugin.auth.handlerURL=" + config.GetEnv("AUTH_HANDLER_URL", ""),
|
||||
// "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.trustForwardHeader=true",
|
||||
|
||||
Reference in New Issue
Block a user