Compare commits

...

41 Commits

Author SHA1 Message Date
e6b03fdd02 Removed useless tags 2025-04-26 12:36:34 +02:00
1018e24060 Updated TTL param 2025-04-26 12:05:55 +02:00
ebef6e138d Consul update 2024-12-24 18:15:48 +01:00
7bd8f754d8 Consul update 2024-12-24 18:10:41 +01:00
43574a1d1c Consul update 2024-12-24 18:04:55 +01:00
f130eaedd7 API Basket update 2024-12-24 17:59:01 +01:00
8394feaec7 Debug update 2024-12-24 17:51:02 +01:00
Piotr Biernat
68e6e3ef55 module update 2024-12-06 14:15:02 +01:00
Piotr Biernat
feff40bf55 update 2024-12-06 14:05:06 +01:00
eb1e8a9cb0 consul registration update 2024-07-21 21:11:34 +02:00
2c797164e0 consul registration update 2024-07-21 21:00:49 +02:00
7725e5dd65 debug fix 2024-07-20 20:12:29 +02:00
07c0cd6f2e debug fix 2024-07-20 19:59:12 +02:00
d29bd0810b debug fix 2024-07-20 19:55:33 +02:00
b62c0e5a8c debug fix 2024-07-20 19:03:21 +02:00
a9eb0d0732 debug fix 2024-07-20 18:19:56 +02:00
92b84685c9 routing fix 2024-07-20 17:30:37 +02:00
cd6e62e3bc debug fix 2024-07-20 16:17:13 +02:00
7cf2d91fd8 debug fix 2024-07-20 16:15:20 +02:00
936982731d debug fix 2024-07-20 16:11:06 +02:00
33759c87db debug fix 2024-07-20 15:56:59 +02:00
974f82e9be debug fix 2024-07-20 15:53:05 +02:00
d7dc75c18f debug fix 2024-07-20 15:45:49 +02:00
c62c63249c debug fix 2024-07-20 14:44:45 +02:00
6c290eb66b tls fix 2024-07-20 14:43:47 +02:00
31ce7fc48e tls fix 2024-07-20 14:42:16 +02:00
99957861dc fix ssl support 2024-07-20 14:24:38 +02:00
19d27b4ff6 add ssl support 2024-07-20 14:20:01 +02:00
7f2025ef6f add debug point 2024-07-20 14:18:08 +02:00
3afe78f9e3 fix in consul discovery 2024-07-19 17:06:39 +02:00
eb763ed49c fix in consul discovery 2024-07-19 16:52:54 +02:00
6537d79b19 fix in consul discovery 2024-07-19 16:48:08 +02:00
e55a2f42fe fix in consul discovery 2024-07-19 16:45:42 +02:00
82d68e91b8 fix in consul discovery 2024-07-19 16:41:37 +02:00
767eb5688c fix in consul discovery 2024-07-19 16:39:11 +02:00
37fa05402e fix in consul discovery 2024-07-19 16:30:04 +02:00
615281ae9a fix in consul discovery lib 2024-07-19 16:25:41 +02:00
42532b1d44 FIX Remove RetryIf plugin 2024-07-17 22:59:16 +02:00
1d4164711e FIX RetryIf plugin config 2024-07-17 22:46:28 +02:00
a50778380e Added RetryIf plugin with config 2024-07-17 22:39:49 +02:00
159bce1ff2 Added RetryIf plugin with config 2024-07-17 22:37:26 +02:00
4 changed files with 58 additions and 48 deletions

View File

@@ -3,7 +3,8 @@ package api
import (
"fmt"
def "git.pbiernat.io/egommerce/api-entities/http"
"git.ego.cloudns.be/egommerce/api-entities/basket"
basket "git.ego.cloudns.be/egommerce/api-entities/basket/dto"
"github.com/go-redis/redis/v8"
)
@@ -15,9 +16,9 @@ type BasketAPI struct {
httpClient *HttpClient
}
func (a *BasketAPI) GetBasket(basketID string) (*def.GetBasketResponse, error) {
req := &def.GetBasketRequest{BasketID: basketID}
res := new(def.GetBasketResponse)
func (a *BasketAPI) GetBasket(basketID string) (*basket.GetBasketResponseDTO, error) {
req := &basket.GetBasketRequestDTO{BasketID: basketID}
res := new(basket.GetBasketResponse)
if err := a.httpClient.SendGet("basket-svc", "/api/v1/basket", req, res); err != nil {
return nil, err
}
@@ -25,9 +26,9 @@ func (a *BasketAPI) GetBasket(basketID string) (*def.GetBasketResponse, error) {
return res, nil
}
func (a *BasketAPI) GetBasketItems(basketID string) ([]*def.GetBasketItemsResponse, error) {
func (a *BasketAPI) GetBasketItems(basketID string) ([]*basket.GetBasketItemsResponseDTO, error) {
url := fmt.Sprintf("/api/v1/basket/%s/items", basketID)
var res []*def.GetBasketItemsResponse
var res []*basket.GetBasketItemsResponseDTO
if err := a.httpClient.SendGet("basket-svc", url, nil, &res); err != nil {
return nil, err
}

View File

@@ -3,10 +3,8 @@ package consul
import (
"fmt"
"net/http"
"strconv"
"time"
"git.pbiernat.io/egommerce/go-api-pkg/config"
consul "github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/connect"
)
@@ -17,12 +15,16 @@ type Service struct {
appID string
domain string
pathPrefix string
tls bool
port int
ttl time.Duration
client *consul.Client
agent *consul.Agent
connect *connect.Service
kv *consul.KV
// hcTicker *time.Ticker
// ttlTicker *time.Ticker
}
var ErrServiceUnavailable = fmt.Errorf("Service is unavailable")
@@ -34,6 +36,7 @@ func NewService(servAddr, id, name, useDomainOverIp, addr, domain, pathPrefix st
s.appID = id
s.domain = domain
s.pathPrefix = pathPrefix
s.tls = true // FIXME add arg
s.port = appPort
s.ttl = time.Second * 10
@@ -65,12 +68,11 @@ func (s *Service) GetID() string {
}
func (s *Service) GetFullAddr() string {
isTLS := s.port == 443
proto := "http"
if isTLS {
if s.tls {
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 {
@@ -81,11 +83,13 @@ func (s *Service) Register() error {
Address: s.Address,
Port: s.port,
Tags: s.getTags(),
// Connect: &consul.AgentServiceConnect{Native: true},
Connect: &consul.AgentServiceConnect{Native: true},
// Proxy: &consul.AgentServiceConnectProxyConfig{
// DestinationServiceName: s.Name,
// },
Check: &consul.AgentServiceCheck{
// Interval: "5s",
// Timeout: "1s",
TTL: s.ttl.String(),
Status: "passing",
DeregisterCriticalServiceAfter: "10s",
@@ -99,30 +103,33 @@ func (s *Service) Register() error {
return nil
}
func (s *Service) Unregister() error {
// s.client.Catalog().Deregister(&consul.CatalogDeregistration{
// Address: s.Address,
// ServiceID: s.GetID(),
// }, nil)
// s.ttlTicker.Stop()
// s.hcTicker.Stop()
s.client.Catalog().Deregister(&consul.CatalogDeregistration{
Address: s.Address,
ServiceID: s.GetID(),
}, nil)
return s.agent.ServiceDeregister(s.GetID())
}
func (s *Service) RegisterHealthChecks() {
go func() { // startup register
ticker := time.NewTicker(time.Second * 1)
for range ticker.C {
t := time.NewTicker(time.Second)
for range t.C {
if ok, _ := s.healthCheck(); ok {
ticker.Stop()
t.Stop()
}
}
}()
go func() { // TTL
interval := s.ttl - (time.Second * 2) // 2 seconds overhead
ticker := time.NewTicker(interval)
for range ticker.C {
t := time.NewTicker(time.Second * 5)
for range t.C {
if _, err := s.healthCheck(); err != nil {
fmt.Printf("HealthCheck endpoint not available (%s)#: %v\n", s.GetFullAddr(), err)
// fmt.Printf("HealthCheck endpoint not available (%s)#: %v\n", s.GetFullAddr(), err)
t.Stop()
}
}
}()
@@ -135,11 +142,10 @@ func (s *Service) Connect() (*connect.Service, error) {
// })
svc, err := connect.NewService(s.Name, s.client)
s.connect = svc
cnf := svc.ServerTLSConfig()
fmt.Printf("CONNECT SERVER:: %s CONFIG:: %v\n", s.Name, cnf)
for k, c := range cnf.Certificates {
fmt.Printf("CONNECT CERT %d: %v", k, c)
}
fmt.Printf("CONNECT SERVER:: %s CERTS:: %v\n", s.Name, svc.ServerTLSConfig())
// for k, c := range cnf.Certificates {
// fmt.Printf("CONNECT CERT %d: %v", k, c)
// }
return svc, err
}
@@ -152,6 +158,7 @@ func (s *Service) healthCheck() (bool, error) {
alive := func() bool {
client := &http.Client{}
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)
if err != nil {
return false
@@ -186,28 +193,29 @@ func (s *Service) healthCheck() (bool, error) {
func (s *Service) getTags() []string {
tags := []string{
"traefik.enable=true",
// "traefik.enable=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.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.requestid_" + s.Name + ".plugin.requestid.headerName=X-Request-ID",
"traefik.http.middlewares.stripprefix_" + s.Name + ".stripprefix.prefixes=" + s.pathPrefix,
"traefik.http.routers." + s.Name + ".rule=PathPrefix(`" + s.pathPrefix + "`)",
// "traefik.http.routers." + s.Name + ".rule=Host(`" + s.domain + "`)",
"traefik.http.routers." + s.Name + ".entryPoints=https",
// "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.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.statusCode=503",
// "traefik.http.routers." + s.Name + ".rule=Host(`" + s.domain + "`) && PathPrefix(`" + s.pathPrefix + "`)",
// "traefik.http.routers." + s.Name + ".entryPoints=https",
// "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 + ",requestid_" + s.Name + ",stripprefix_" + s.Name + "",
"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=true",
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.interval=1s",
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.timeout=1s",
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.path=/health",
"traefik.tls.certificates.certfile=/certs/client.cert",
"traefik.tls.certificates.keyfile=/certs/client.key",
// "traefik.http.routers." + s.Name + ".middlewares=auth_" + s.Name + ",stripprefix_" + s.Name + ",requestid_" + s.Name + "",
// "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.passhostheader=true",
// "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.path=/health",
// "traefik.tls.certificates.certfile=certs/client.crt",
// "traefik.tls.certificates.keyfile=certs/client.key",
}
return tags

4
go.mod
View File

@@ -1,9 +1,8 @@
module git.pbiernat.io/egommerce/go-api-pkg
module git.ego.cloudns.be/egommerce/go-api-pkg
go 1.18
require (
git.pbiernat.io/egommerce/api-entities v0.2.3
github.com/fluent/fluent-logger-golang v1.9.0
github.com/go-redis/redis/v8 v8.11.5
github.com/hashicorp/consul v1.16.0
@@ -12,6 +11,7 @@ require (
)
require (
git.ego.cloudns.be/egommerce/api-entities v0.2.5 // indirect
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/armon/go-radix v1.0.0 // indirect

3
go.sum
View File

@@ -35,7 +35,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
git.pbiernat.io/egommerce/api-entities v0.2.3/go.mod h1:INXAG5x4+i+vNwg1NpfPHiDW8nY1kn1K7pgLOtX+/I0=
git.ego.cloudns.be/egommerce/api-entities v0.2.5 h1:A7KQNXLB3l0ck7/R6MzyU33H490feZOlEodnU6bC+DA=
git.ego.cloudns.be/egommerce/api-entities v0.2.5/go.mod h1:xr9mW9DKq+oNO4cMqtqY3VCAVCn6iImw4MqNj51dTFc=
github.com/Azure/azure-sdk-for-go v44.0.0+incompatible h1:e82Yv2HNpS0kuyeCrV29OPKvEiqfs2/uJHic3/3iKdg=
github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs=
github.com/Azure/go-autorest/autorest v0.11.18 h1:90Y4srNYrwOtAgVo3ndrQkTYn6kf1Eg/AjTFJ8Is2aM=