diff --git a/.app.config b/.app.config index 57efa4e..25c50ba 100644 --- a/.app.config +++ b/.app.config @@ -5,10 +5,20 @@ "Tags": ["basket-svc", "basket", "https", "service"], "Port": 443, "Connect": { - "Native": true + "Native": true, + "SidecarService": { + "Port": 20001, + "Check": { + "Name": "Connect Envoy Sidecar", + "TCP": "127.0.0.1:20001", + "Interval": "5s" + } + } }, "Check": { "TCP": "__IP__:443", + "Interval": "5s", + "Timeout": "1s", "DeregisterCriticalServiceAfter": "10s" } } \ No newline at end of file diff --git a/.env.dist b/.env.dist index 757a003..be9ec0d 100644 --- a/.env.dist +++ b/.env.dist @@ -7,7 +7,7 @@ APP_PATH_PREFIX=/basket APP_KV_NAMESPACE=dev.egommerce/service/basket-svc LOGGER_ADDR=api-logger:24224 -REGISTRY_ADDR=api-registry:8500 +REGISTRY_ADDR=api-registry:8501 DATABASE_URL=postgres://postgres:12345678@postgres-db:5432/egommerce CACHE_ADDR=api-cache:6379 CACHE_PASSWORD=12345678 diff --git a/bin/entrypoint.sh b/bin/entrypoint.sh index a002a1b..b09888a 100755 --- a/bin/entrypoint.sh +++ b/bin/entrypoint.sh @@ -14,18 +14,20 @@ waitForService() done } -update-resolv # provided by stack - better approach - single copy +update-resolv update-ca-certificates -waitForService "api-registry:8500" -waitForService "postgres-db:5432" -# waitForService "postgres-db.service.ego.io:5432" -waitForService "api-eventbus:5672" -# waitForService "esb.service.ego.io:5672" -waitForService "api-logger:24224" -# waitForService "logger.service.ego.io:24224" -waitForService "pricing-svc:443" +waitForService "api-registry:8501" +waitForService "esb.service.ego.io:5672" +waitForService "logger.service.ego.io:24224" +waitForService "postgresdb.service.ego.io:5432" # waitForService "pricing.service.ego.io:443" +# waitForService "api-eventbus:5672" +# waitForService "api-logger:24224" +# waitForService "db-postgres:5432" +# waitForService "pricing-svc:443" #dev-disabled + +register-service # run migrations migrate.sh diff --git a/deploy/certs b/deploy/certs new file mode 120000 index 0000000..0267044 --- /dev/null +++ b/deploy/certs @@ -0,0 +1 @@ +../../stack/deploy/certs/basket-svc/ \ No newline at end of file diff --git a/src/cmd/health/main.go b/src/cmd/health/main.go index c27f125..4c4420e 100644 --- a/src/cmd/health/main.go +++ b/src/cmd/health/main.go @@ -29,7 +29,7 @@ func main() { } func healthCheck() bool { - run, err := os.Open("/app.run") + run, err := os.Open("./app.run") if err != nil { return false } diff --git a/src/cmd/server/main.go b/src/cmd/server/main.go index 8394edd..fd26539 100644 --- a/src/cmd/server/main.go +++ b/src/cmd/server/main.go @@ -25,7 +25,7 @@ func main() { a.RegisterPlugin(app.CachePlugin(cArr)) a.RegisterPlugin(app.DatabasePlugin(cArr)) a.RegisterPlugin(app.EventbusPlugin(cArr)) - a.RegisterPlugin(app.RegistryPlugin(cArr)) + // a.RegisterPlugin(app.RegistryPlugin(cArr)) while := make(chan struct{}) err := a.Start(while) diff --git a/src/go.mod b/src/go.mod index e29e0fd..37b6349 100644 --- a/src/go.mod +++ b/src/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( git.pbiernat.io/egommerce/api-entities v0.2.3 - git.pbiernat.io/egommerce/go-api-pkg v0.3.18 + git.pbiernat.io/egommerce/go-api-pkg v0.3.24 github.com/georgysavva/scany/v2 v2.0.0 github.com/go-pg/migrations/v8 v8.1.0 github.com/go-pg/pg/v10 v10.10.7 diff --git a/src/go.sum b/src/go.sum index 9ebe000..aacbadc 100644 --- a/src/go.sum +++ b/src/go.sum @@ -37,8 +37,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 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 h1:mR6EYfZkAzh4teydb7KXDBWoxwVW3qasnmmH5J3mnas= git.pbiernat.io/egommerce/api-entities v0.2.3/go.mod h1:INXAG5x4+i+vNwg1NpfPHiDW8nY1kn1K7pgLOtX+/I0= -git.pbiernat.io/egommerce/go-api-pkg v0.3.18 h1:0+C9BMsllrNvRbh4kb7dJ5lrzP1Lc7J4pb+KV76YrXk= -git.pbiernat.io/egommerce/go-api-pkg v0.3.18/go.mod h1:XIy2mmvRNIzQmYIUAcDZafhRPxTQFS2HDmsK7ZQ6980= +git.pbiernat.io/egommerce/go-api-pkg v0.3.24 h1:if6xsFOStckWdGm7kcgKWOhOGOe6iIBOOr+3DjgX5tM= +git.pbiernat.io/egommerce/go-api-pkg v0.3.24/go.mod h1:XIy2mmvRNIzQmYIUAcDZafhRPxTQFS2HDmsK7ZQ6980= 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= diff --git a/src/internal/server/config.go b/src/internal/server/config.go index 64b9b63..93ccaa7 100644 --- a/src/internal/server/config.go +++ b/src/internal/server/config.go @@ -21,7 +21,7 @@ const ( defNetAddr = ":443" defMongoDbURL = "mongodb://mongodb:12345678@mongo-db:27017" defPathPrefix = "/basket" - defRegistryAddr = "api-registry:8500" + defRegistryAddr = "api-registry:8501" defEbEventsExchange = "api-events" defEbEventsQueue = "basket-svc" ) diff --git a/src/internal/server/middleware.go b/src/internal/server/middleware.go index 32328d9..8c7a36c 100644 --- a/src/internal/server/middleware.go +++ b/src/internal/server/middleware.go @@ -1,8 +1,6 @@ package server import ( - "strings" - "github.com/gofiber/fiber/v2" "git.pbiernat.io/egommerce/go-api-pkg/fluentd" @@ -17,10 +15,10 @@ func SetupMiddleware(s *Server) { func LoggingMiddleware(log *fluentd.Logger) func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error { - path := string(c.Request().URI().Path()) - if strings.Contains(path, "/health") { - return c.Next() - } + // path := string(c.Request().URI().Path()) + // if strings.Contains(path, "/health") { + // return c.Next() + // } log.Log("Request: %s, remote: %s, via: %s", c.Request().URI().String(), diff --git a/src/internal/server/server.go b/src/internal/server/server.go index 1bfa7b6..e76063e 100644 --- a/src/internal/server/server.go +++ b/src/internal/server/server.go @@ -69,7 +69,7 @@ func (s *Server) RegisterHandler(name string, fn func() any) { func (s *Server) OnShutdown() { // s.GetLogger().Log("Server %s is going down...", s.ID) - s.GetRegistry().Unregister() + // s.GetRegistry().Unregister() // a.clearMetadataCache() s.GetEventBus().Close() s.GetDatabase().Close() diff --git a/src/internal/service/basket.go b/src/internal/service/basket.go index e89b1e4..86486db 100644 --- a/src/internal/service/basket.go +++ b/src/internal/service/basket.go @@ -18,7 +18,7 @@ import ( ) const ( - ServiceUserAgent = "basket-httpclient" + ServiceUserAgent = "basket-api/internal" ) type BasketService struct { diff --git a/src/internal/ui/basket.go b/src/internal/ui/basket.go index 4f5b8d0..085fa4f 100644 --- a/src/internal/ui/basket.go +++ b/src/internal/ui/basket.go @@ -35,8 +35,7 @@ func AddProductToBasket(srv *service.BasketService, productID, qty int, basketID return basket, nil } - qty = item.Quantity + qty - err = srv.UpdateItem(ctx, item, qty) + err = srv.UpdateItem(ctx, item, item.Quantity+qty) if err != nil { srv.Log("UpdateItem error: %v", err) } diff --git a/src/internal/worker/command.go b/src/internal/worker/command.go index 97abc65..c075845 100644 --- a/src/internal/worker/command.go +++ b/src/internal/worker/command.go @@ -22,12 +22,12 @@ type CommandRunner struct { func NewCommandRunner(cmd string, srvc *service.BasketService) *CommandRunner { rnr := &CommandRunner{} - rnr.cmd = getCommand(cmd, srvc) + rnr.cmd = initCommand(cmd, srvc) return rnr } -func getCommand(cmd string, srvc *service.BasketService) Command { +func initCommand(cmd string, srvc *service.BasketService) Command { // fmt.Printf("getCommand: %v\n", cmd) var c Command diff --git a/src/internal/worker/worker.go b/src/internal/worker/worker.go index 10bc926..256b8d5 100644 --- a/src/internal/worker/worker.go +++ b/src/internal/worker/worker.go @@ -174,8 +174,8 @@ func (w *Worker) processMsg(srvc *service.BasketService, m amqp.Delivery) { // w.Logger.Log("Removing product #%d from basket #%s. ReqID: #%s", productID, basketID, reqID) // } - rnr := NewCommandRunner((data["command"]).(string), srvc) - ok, _ = rnr.run(data) + r := NewCommandRunner((data["command"]).(string), srvc) + ok, _ = r.run(data) if ok { w.GetLogger().Log("Successful executed message \"%s\"\n", name) fmt.Printf("Successful executed message \"%s\"\n", name)