forked from mtusi2026/mtusi2026lab6
feat: add bounded observability and verified SLO incident alerts
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
// Package fiber implements the messenger HTTP transport using Fiber.
|
||||
package fiber
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/google/uuid"
|
||||
"go.lab260.ru/fielderr"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab6/internal/admission"
|
||||
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab6/internal/config"
|
||||
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab6/internal/controller"
|
||||
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab6/internal/service"
|
||||
)
|
||||
|
||||
// Controller owns the HTTP server and delegates business operations to Service.
|
||||
// Its configuration is copied at construction and must not change during serving.
|
||||
// Fx manages its listener through Start and Stop.
|
||||
type Controller struct {
|
||||
observer HTTPObserver
|
||||
attachments Attachments
|
||||
metrics *httpMetrics
|
||||
log *zap.Logger
|
||||
cfg config.Controller
|
||||
service service.Service
|
||||
server *fiber.App
|
||||
errorRegistry *fielderr.Registry
|
||||
admission admission.Distributed
|
||||
auth service.Authentication
|
||||
readiness Readiness
|
||||
stopping atomic.Bool
|
||||
instanceID string
|
||||
serveDone chan error
|
||||
}
|
||||
|
||||
var _ controller.Controller = (*Controller)(nil)
|
||||
|
||||
// New validates dependencies and prepares the server without opening a listener.
|
||||
// Routing, middleware and Fiber configuration are installed by configure.
|
||||
func New(log *zap.Logger, cfg *config.Controller, svc service.Service, registry *fielderr.Registry, limiter admission.Distributed, auth service.Authentication, readiness Readiness) (*Controller, error) {
|
||||
if err := cfg.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if log == nil || svc == nil || registry == nil || limiter == nil || auth == nil || readiness == nil {
|
||||
return nil, fmt.Errorf("HTTP logger, service, error registry and admission limiter are required")
|
||||
}
|
||||
ctrl := &Controller{
|
||||
metrics: newHTTPMetrics(),
|
||||
log: log.Named("controller.http.fiber"),
|
||||
cfg: *cfg,
|
||||
service: svc,
|
||||
errorRegistry: registry,
|
||||
admission: limiter,
|
||||
auth: auth,
|
||||
readiness: readiness,
|
||||
serveDone: make(chan error, 1),
|
||||
}
|
||||
ctrl.instanceID = cfg.InstanceID
|
||||
if ctrl.instanceID == "" {
|
||||
ctrl.instanceID = uuid.NewString()
|
||||
}
|
||||
ctrl.configure()
|
||||
return ctrl, nil
|
||||
}
|
||||
Reference in New Issue
Block a user