Marina Biryukova
2c95250f72
All checks were successful
/ DCO (pull_request) Successful in 1m19s
/ Builds (1.20) (pull_request) Successful in 2m31s
/ Builds (1.21) (pull_request) Successful in 1m15s
/ Vulncheck (pull_request) Successful in 2m8s
/ Lint (pull_request) Successful in 3m39s
/ Tests (1.20) (pull_request) Successful in 2m16s
/ Tests (1.21) (pull_request) Successful in 2m9s
Signed-off-by: Marina Biryukova <m.biryukova@yadro.com>
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package metrics
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/logs"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// Service serves metrics.
|
|
type Service struct {
|
|
*http.Server
|
|
enabled bool
|
|
log *zap.Logger
|
|
serviceType string
|
|
}
|
|
|
|
// Config is a params to configure service.
|
|
type Config struct {
|
|
Address string
|
|
Enabled bool
|
|
}
|
|
|
|
// Start runs http service with the exposed endpoint on the configured port.
|
|
func (ms *Service) Start() {
|
|
if ms.enabled {
|
|
ms.log.Info(logs.ServiceIsRunning, zap.String("endpoint", ms.Addr))
|
|
err := ms.ListenAndServe()
|
|
if err != nil && err != http.ErrServerClosed {
|
|
ms.log.Warn(logs.ServiceCouldntStartOnConfiguredPort)
|
|
}
|
|
} else {
|
|
ms.log.Info(logs.ServiceHasntStartedSinceItsDisabled)
|
|
}
|
|
}
|
|
|
|
// ShutDown stops the service.
|
|
func (ms *Service) ShutDown(ctx context.Context) {
|
|
ms.log.Info(logs.ShuttingDownService, zap.String("endpoint", ms.Addr))
|
|
err := ms.Shutdown(ctx)
|
|
if err != nil {
|
|
ms.log.Error(logs.CantGracefullyShutDownService, zap.Error(err))
|
|
if err = ms.Close(); err != nil {
|
|
ms.log.Panic(logs.CantShutDownService, zap.Error(err))
|
|
}
|
|
}
|
|
}
|