2021-01-03 18:15:44 +05:30
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
2022-05-03 11:20:57 +05:30
|
|
|
"context"
|
2021-05-22 19:51:56 +05:30
|
|
|
"fmt"
|
2021-01-03 18:15:44 +05:30
|
|
|
"net"
|
|
|
|
|
"net/http"
|
2022-05-13 03:38:00 +05:30
|
|
|
_ "net/http/pprof" // http profiler
|
2021-01-03 18:15:44 +05:30
|
|
|
|
|
|
|
|
"github.com/gorilla/handlers"
|
2022-01-26 21:40:44 +05:30
|
|
|
|
2025-03-20 21:01:41 +05:30
|
|
|
"github.com/SigNoz/signoz/pkg/alertmanager"
|
2025-04-18 19:03:17 +05:30
|
|
|
"github.com/SigNoz/signoz/pkg/apis/fields"
|
2025-03-20 21:01:41 +05:30
|
|
|
"github.com/SigNoz/signoz/pkg/http/middleware"
|
2025-05-24 19:14:29 +05:30
|
|
|
"github.com/SigNoz/signoz/pkg/licensing/nooplicensing"
|
2025-05-31 16:04:13 +05:30
|
|
|
"github.com/SigNoz/signoz/pkg/modules/organization"
|
2025-03-31 19:41:11 +05:30
|
|
|
"github.com/SigNoz/signoz/pkg/prometheus"
|
2025-06-10 18:26:28 +05:30
|
|
|
querierAPI "github.com/SigNoz/signoz/pkg/querier"
|
2025-03-20 21:01:41 +05:30
|
|
|
"github.com/SigNoz/signoz/pkg/query-service/agentConf"
|
|
|
|
|
"github.com/SigNoz/signoz/pkg/query-service/app/clickhouseReader"
|
|
|
|
|
"github.com/SigNoz/signoz/pkg/query-service/app/cloudintegrations"
|
|
|
|
|
"github.com/SigNoz/signoz/pkg/query-service/app/integrations"
|
|
|
|
|
"github.com/SigNoz/signoz/pkg/query-service/app/logparsingpipeline"
|
|
|
|
|
"github.com/SigNoz/signoz/pkg/query-service/app/opamp"
|
|
|
|
|
opAmpModel "github.com/SigNoz/signoz/pkg/query-service/app/opamp/model"
|
|
|
|
|
"github.com/SigNoz/signoz/pkg/signoz"
|
|
|
|
|
"github.com/SigNoz/signoz/pkg/sqlstore"
|
2025-03-31 19:41:11 +05:30
|
|
|
"github.com/SigNoz/signoz/pkg/telemetrystore"
|
2025-03-20 21:01:41 +05:30
|
|
|
"github.com/SigNoz/signoz/pkg/types/authtypes"
|
|
|
|
|
"github.com/SigNoz/signoz/pkg/web"
|
2021-03-01 02:43:05 +05:30
|
|
|
"github.com/rs/cors"
|
2021-01-03 18:15:44 +05:30
|
|
|
"github.com/soheilhy/cmux"
|
2023-03-15 15:09:15 +05:30
|
|
|
|
2025-05-03 18:30:07 +05:30
|
|
|
"github.com/SigNoz/signoz/pkg/cache"
|
2025-03-20 21:01:41 +05:30
|
|
|
"github.com/SigNoz/signoz/pkg/query-service/constants"
|
|
|
|
|
"github.com/SigNoz/signoz/pkg/query-service/healthcheck"
|
|
|
|
|
"github.com/SigNoz/signoz/pkg/query-service/interfaces"
|
|
|
|
|
"github.com/SigNoz/signoz/pkg/query-service/rules"
|
|
|
|
|
"github.com/SigNoz/signoz/pkg/query-service/utils"
|
2021-01-03 18:15:44 +05:30
|
|
|
"go.uber.org/zap"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Server runs HTTP, Mux and a grpc server
|
|
|
|
|
type Server struct {
|
2025-06-21 00:55:38 +05:30
|
|
|
config signoz.Config
|
|
|
|
|
signoz *signoz.SigNoz
|
|
|
|
|
jwt *authtypes.JWT
|
|
|
|
|
ruleManager *rules.Manager
|
2022-06-08 12:22:25 +05:30
|
|
|
|
|
|
|
|
// public http router
|
2025-06-21 00:55:38 +05:30
|
|
|
httpConn net.Listener
|
|
|
|
|
httpServer *http.Server
|
|
|
|
|
httpHostPort string
|
2022-06-08 12:22:25 +05:30
|
|
|
|
|
|
|
|
// private http
|
2025-06-21 00:55:38 +05:30
|
|
|
privateConn net.Listener
|
|
|
|
|
privateHTTP *http.Server
|
|
|
|
|
privateHostPort string
|
2022-06-08 12:22:25 +05:30
|
|
|
|
2023-10-14 09:16:14 +05:30
|
|
|
opampServer *opamp.Server
|
|
|
|
|
|
2021-01-03 18:15:44 +05:30
|
|
|
unavailableChannel chan healthcheck.Status
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewServer creates and initializes Server
|
2025-06-21 00:55:38 +05:30
|
|
|
func NewServer(config signoz.Config, signoz *signoz.SigNoz, jwt *authtypes.JWT) (*Server, error) {
|
|
|
|
|
integrationsController, err := integrations.NewController(signoz.SQLStore)
|
2025-06-02 22:41:38 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-21 00:55:38 +05:30
|
|
|
cloudIntegrationsController, err := cloudintegrations.NewController(signoz.SQLStore)
|
2025-06-02 22:41:38 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-31 19:41:11 +05:30
|
|
|
reader := clickhouseReader.NewReader(
|
2025-06-21 00:55:38 +05:30
|
|
|
signoz.SQLStore,
|
|
|
|
|
signoz.TelemetryStore,
|
|
|
|
|
signoz.Prometheus,
|
|
|
|
|
signoz.TelemetryStore.Cluster(),
|
|
|
|
|
config.Querier.FluxInterval,
|
|
|
|
|
signoz.Cache,
|
2025-02-04 14:53:36 +05:30
|
|
|
)
|
|
|
|
|
|
2024-09-24 10:22:52 +05:30
|
|
|
rm, err := makeRulesManager(
|
2025-03-10 01:30:42 +05:30
|
|
|
reader,
|
2025-06-21 00:55:38 +05:30
|
|
|
signoz.Cache,
|
|
|
|
|
signoz.SQLStore,
|
|
|
|
|
signoz.TelemetryStore,
|
|
|
|
|
signoz.Prometheus,
|
|
|
|
|
signoz.Modules.OrgGetter,
|
2025-03-10 01:30:42 +05:30
|
|
|
)
|
2022-07-14 11:59:06 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2022-07-04 17:13:36 +05:30
|
|
|
|
2024-03-11 14:15:11 +05:30
|
|
|
logParsingPipelineController, err := logparsingpipeline.NewLogParsingPipelinesController(
|
2025-06-21 00:55:38 +05:30
|
|
|
signoz.SQLStore,
|
|
|
|
|
integrationsController.GetPipelinesForInstalledIntegrations,
|
2024-03-11 14:15:11 +05:30
|
|
|
)
|
2023-07-31 21:34:42 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-06 20:13:30 +05:30
|
|
|
apiHandler, err := NewAPIHandler(APIHandlerOpts{
|
2023-07-31 21:34:42 +05:30
|
|
|
Reader: reader,
|
|
|
|
|
RuleManager: rm,
|
2024-03-02 10:11:51 +05:30
|
|
|
IntegrationsController: integrationsController,
|
2025-01-10 18:43:35 +05:30
|
|
|
CloudIntegrationsController: cloudIntegrationsController,
|
2023-07-31 21:34:42 +05:30
|
|
|
LogsParsingPipelineController: logParsingPipelineController,
|
2025-06-21 00:55:38 +05:30
|
|
|
FluxInterval: config.Querier.FluxInterval,
|
|
|
|
|
AlertmanagerAPI: alertmanager.NewAPI(signoz.Alertmanager),
|
2025-05-24 19:14:29 +05:30
|
|
|
LicensingAPI: nooplicensing.NewLicenseAPI(),
|
2025-06-21 00:55:38 +05:30
|
|
|
FieldsAPI: fields.NewAPI(signoz.Instrumentation.ToProviderSettings(), signoz.TelemetryStore),
|
|
|
|
|
Signoz: signoz,
|
2025-06-23 14:00:50 +05:30
|
|
|
QuerierAPI: querierAPI.NewAPI(signoz.Instrumentation.ToProviderSettings(), signoz.Querier),
|
2022-10-06 20:13:30 +05:30
|
|
|
})
|
2021-09-02 13:18:47 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-08 12:22:25 +05:30
|
|
|
s := &Server{
|
2025-06-21 00:55:38 +05:30
|
|
|
config: config,
|
|
|
|
|
signoz: signoz,
|
|
|
|
|
jwt: jwt,
|
2022-07-14 11:59:06 +05:30
|
|
|
ruleManager: rm,
|
2025-06-21 00:55:38 +05:30
|
|
|
httpHostPort: constants.HTTPHostPort,
|
|
|
|
|
privateHostPort: constants.PrivateHostPort,
|
2022-06-08 12:22:25 +05:30
|
|
|
unavailableChannel: make(chan healthcheck.Status),
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-21 00:55:38 +05:30
|
|
|
httpServer, err := s.createPublicServer(apiHandler, signoz.Web)
|
2022-06-08 12:22:25 +05:30
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s.httpServer = httpServer
|
|
|
|
|
|
|
|
|
|
privateServer, err := s.createPrivateServer(apiHandler)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s.privateHTTP = privateServer
|
|
|
|
|
|
2025-06-21 00:55:38 +05:30
|
|
|
opAmpModel.Init(signoz.SQLStore, signoz.Instrumentation.Logger(), signoz.Modules.OrgGetter)
|
2023-03-15 15:09:15 +05:30
|
|
|
|
2025-06-21 00:55:38 +05:30
|
|
|
agentConfMgr, err := agentConf.Initiate(
|
|
|
|
|
&agentConf.ManagerOptions{
|
|
|
|
|
Store: signoz.SQLStore,
|
|
|
|
|
AgentFeatures: []agentConf.AgentFeature{
|
|
|
|
|
logParsingPipelineController,
|
|
|
|
|
},
|
2023-10-15 21:04:19 +05:30
|
|
|
},
|
2025-06-21 00:55:38 +05:30
|
|
|
)
|
2023-10-15 21:04:19 +05:30
|
|
|
if err != nil {
|
2023-03-15 15:09:15 +05:30
|
|
|
return nil, err
|
|
|
|
|
}
|
2023-10-14 09:16:14 +05:30
|
|
|
|
|
|
|
|
s.opampServer = opamp.InitializeServer(
|
2025-06-21 00:55:38 +05:30
|
|
|
&opAmpModel.AllAgents,
|
|
|
|
|
agentConfMgr,
|
2023-10-14 09:16:14 +05:30
|
|
|
)
|
|
|
|
|
|
2025-05-31 16:04:13 +05:30
|
|
|
orgs, err := apiHandler.Signoz.Modules.OrgGetter.ListByOwnedKeyRange(context.Background())
|
2025-05-03 18:30:07 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
for _, org := range orgs {
|
|
|
|
|
errorList := reader.PreloadMetricsMetadata(context.Background(), org.ID)
|
|
|
|
|
for _, er := range errorList {
|
|
|
|
|
zap.L().Error("failed to preload metrics metadata", zap.Error(er))
|
|
|
|
|
}
|
2025-03-18 16:09:34 +05:30
|
|
|
}
|
|
|
|
|
|
2022-06-08 12:22:25 +05:30
|
|
|
return s, nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-21 00:55:38 +05:30
|
|
|
// HealthCheckStatus returns health check status channel a client can subscribe to
|
|
|
|
|
func (s Server) HealthCheckStatus() chan healthcheck.Status {
|
|
|
|
|
return s.unavailableChannel
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-08 12:22:25 +05:30
|
|
|
func (s *Server) createPrivateServer(api *APIHandler) (*http.Server, error) {
|
|
|
|
|
|
|
|
|
|
r := NewRouter()
|
|
|
|
|
|
2025-06-21 00:55:38 +05:30
|
|
|
r.Use(middleware.NewAuth(s.jwt, []string{"Authorization", "Sec-WebSocket-Protocol"}, s.signoz.Sharder, s.signoz.Instrumentation.Logger()).Wrap)
|
|
|
|
|
r.Use(middleware.NewTimeout(s.signoz.Instrumentation.Logger(),
|
|
|
|
|
s.config.APIServer.Timeout.ExcludedRoutes,
|
|
|
|
|
s.config.APIServer.Timeout.Default,
|
|
|
|
|
s.config.APIServer.Timeout.Max,
|
2025-01-22 23:18:47 +05:30
|
|
|
).Wrap)
|
2025-06-21 00:55:38 +05:30
|
|
|
r.Use(middleware.NewAPIKey(s.signoz.SQLStore, []string{"SIGNOZ-API-KEY"}, s.signoz.Instrumentation.Logger(), s.signoz.Sharder).Wrap)
|
|
|
|
|
r.Use(middleware.NewLogging(s.signoz.Instrumentation.Logger(), s.config.APIServer.Logging.ExcludedRoutes).Wrap)
|
2022-06-08 12:22:25 +05:30
|
|
|
|
|
|
|
|
api.RegisterPrivateRoutes(r)
|
|
|
|
|
|
|
|
|
|
c := cors.New(cors.Options{
|
|
|
|
|
//todo(amol): find out a way to add exact domain or
|
|
|
|
|
// ip here for alert manager
|
|
|
|
|
AllowedOrigins: []string{"*"},
|
2022-08-04 11:55:54 +05:30
|
|
|
AllowedMethods: []string{"GET", "DELETE", "POST", "PUT", "PATCH"},
|
2024-08-14 19:53:36 +05:30
|
|
|
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-SIGNOZ-QUERY-ID", "Sec-WebSocket-Protocol"},
|
2022-06-08 12:22:25 +05:30
|
|
|
})
|
|
|
|
|
|
|
|
|
|
handler := c.Handler(r)
|
|
|
|
|
handler = handlers.CompressHandler(handler)
|
|
|
|
|
|
|
|
|
|
return &http.Server{
|
|
|
|
|
Handler: handler,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-20 17:45:33 +05:30
|
|
|
func (s *Server) createPublicServer(api *APIHandler, web web.Web) (*http.Server, error) {
|
2021-01-03 18:15:44 +05:30
|
|
|
r := NewRouter()
|
|
|
|
|
|
2025-06-21 00:55:38 +05:30
|
|
|
r.Use(middleware.NewAuth(s.jwt, []string{"Authorization", "Sec-WebSocket-Protocol"}, s.signoz.Sharder, s.signoz.Instrumentation.Logger()).Wrap)
|
|
|
|
|
r.Use(middleware.NewTimeout(s.signoz.Instrumentation.Logger(),
|
|
|
|
|
s.config.APIServer.Timeout.ExcludedRoutes,
|
|
|
|
|
s.config.APIServer.Timeout.Default,
|
|
|
|
|
s.config.APIServer.Timeout.Max,
|
2025-01-22 23:18:47 +05:30
|
|
|
).Wrap)
|
2025-06-21 00:55:38 +05:30
|
|
|
r.Use(middleware.NewAPIKey(s.signoz.SQLStore, []string{"SIGNOZ-API-KEY"}, s.signoz.Instrumentation.Logger(), s.signoz.Sharder).Wrap)
|
|
|
|
|
r.Use(middleware.NewLogging(s.signoz.Instrumentation.Logger(), s.config.APIServer.Logging.ExcludedRoutes).Wrap)
|
2021-01-09 19:10:34 +05:30
|
|
|
|
2025-06-21 00:55:38 +05:30
|
|
|
am := middleware.NewAuthZ(s.signoz.Instrumentation.Logger())
|
2023-02-15 23:49:03 +05:30
|
|
|
|
|
|
|
|
api.RegisterRoutes(r, am)
|
|
|
|
|
api.RegisterLogsRoutes(r, am)
|
2024-03-02 10:11:51 +05:30
|
|
|
api.RegisterIntegrationRoutes(r, am)
|
2025-01-10 18:43:35 +05:30
|
|
|
api.RegisterCloudIntegrationsRoutes(r, am)
|
2025-04-18 19:03:17 +05:30
|
|
|
api.RegisterFieldsRoutes(r, am)
|
2023-03-04 00:05:16 +05:30
|
|
|
api.RegisterQueryRangeV3Routes(r, am)
|
2024-10-10 17:02:46 +05:30
|
|
|
api.RegisterInfraMetricsRoutes(r, am)
|
2024-08-20 13:26:34 +05:30
|
|
|
api.RegisterWebSocketPaths(r, am)
|
2024-01-16 16:56:20 +05:30
|
|
|
api.RegisterQueryRangeV4Routes(r, am)
|
2025-06-10 18:26:28 +05:30
|
|
|
api.RegisterQueryRangeV5Routes(r, am)
|
2024-07-26 11:50:02 +05:30
|
|
|
api.RegisterMessagingQueuesRoutes(r, am)
|
2025-02-19 16:08:58 +05:30
|
|
|
api.RegisterThirdPartyApiRoutes(r, am)
|
2025-02-20 13:49:44 +05:30
|
|
|
api.MetricExplorerRoutes(r, am)
|
2025-06-02 12:30:49 +05:30
|
|
|
api.RegisterTraceFunnelsRoutes(r, am)
|
2021-01-03 18:15:44 +05:30
|
|
|
|
2021-03-01 02:43:05 +05:30
|
|
|
c := cors.New(cors.Options{
|
|
|
|
|
AllowedOrigins: []string{"*"},
|
2022-08-04 17:32:45 +05:30
|
|
|
AllowedMethods: []string{"GET", "DELETE", "POST", "PUT", "PATCH", "OPTIONS"},
|
2024-08-14 19:53:36 +05:30
|
|
|
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "cache-control", "X-SIGNOZ-QUERY-ID", "Sec-WebSocket-Protocol"},
|
2021-03-01 02:43:05 +05:30
|
|
|
})
|
2021-01-03 18:15:44 +05:30
|
|
|
|
2021-03-01 02:43:05 +05:30
|
|
|
handler := c.Handler(r)
|
2021-01-03 18:15:44 +05:30
|
|
|
|
|
|
|
|
handler = handlers.CompressHandler(handler)
|
|
|
|
|
|
2025-01-20 17:45:33 +05:30
|
|
|
err := web.AddToRouter(r)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-03 18:15:44 +05:30
|
|
|
return &http.Server{
|
|
|
|
|
Handler: handler,
|
2021-05-22 19:51:56 +05:30
|
|
|
}, nil
|
2021-01-03 18:15:44 +05:30
|
|
|
}
|
|
|
|
|
|
2022-06-08 12:22:25 +05:30
|
|
|
// initListeners initialises listeners of the server
|
|
|
|
|
func (s *Server) initListeners() error {
|
|
|
|
|
// listen on public port
|
|
|
|
|
var err error
|
2025-06-21 00:55:38 +05:30
|
|
|
publicHostPort := s.httpHostPort
|
2022-06-08 12:22:25 +05:30
|
|
|
if publicHostPort == "" {
|
|
|
|
|
return fmt.Errorf("constants.HTTPHostPort is required")
|
2021-01-03 18:15:44 +05:30
|
|
|
}
|
|
|
|
|
|
2022-06-08 12:22:25 +05:30
|
|
|
s.httpConn, err = net.Listen("tcp", publicHostPort)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2021-01-03 18:15:44 +05:30
|
|
|
|
2025-06-21 00:55:38 +05:30
|
|
|
zap.L().Info(fmt.Sprintf("Query server started listening on %s...", s.httpHostPort))
|
2021-01-03 18:15:44 +05:30
|
|
|
|
2022-06-08 12:22:25 +05:30
|
|
|
// listen on private port to support internal services
|
2025-06-21 00:55:38 +05:30
|
|
|
privateHostPort := s.privateHostPort
|
2021-01-03 18:15:44 +05:30
|
|
|
|
2022-06-08 12:22:25 +05:30
|
|
|
if privateHostPort == "" {
|
|
|
|
|
return fmt.Errorf("constants.PrivateHostPort is required")
|
|
|
|
|
}
|
2021-01-03 18:15:44 +05:30
|
|
|
|
2022-06-08 12:22:25 +05:30
|
|
|
s.privateConn, err = net.Listen("tcp", privateHostPort)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2025-06-21 00:55:38 +05:30
|
|
|
zap.L().Info(fmt.Sprintf("Query server started listening on private port %s...", s.privateHostPort))
|
2021-01-03 18:15:44 +05:30
|
|
|
|
2022-06-08 12:22:25 +05:30
|
|
|
return nil
|
2021-01-03 18:15:44 +05:30
|
|
|
}
|
|
|
|
|
|
2022-06-08 12:22:25 +05:30
|
|
|
// Start listening on http and private http port concurrently
|
2025-04-18 00:04:25 +05:30
|
|
|
func (s *Server) Start(ctx context.Context) error {
|
2025-04-28 14:57:26 +05:30
|
|
|
s.ruleManager.Start(ctx)
|
2022-07-14 11:59:06 +05:30
|
|
|
|
2022-06-08 12:22:25 +05:30
|
|
|
err := s.initListeners()
|
2021-01-03 18:15:44 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var httpPort int
|
|
|
|
|
if port, err := utils.GetPort(s.httpConn.Addr()); err == nil {
|
|
|
|
|
httpPort = port
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
go func() {
|
2025-06-21 00:55:38 +05:30
|
|
|
zap.L().Info("Starting HTTP server", zap.Int("port", httpPort), zap.String("addr", s.httpHostPort))
|
2021-01-03 18:15:44 +05:30
|
|
|
|
|
|
|
|
switch err := s.httpServer.Serve(s.httpConn); err {
|
|
|
|
|
case nil, http.ErrServerClosed, cmux.ErrListenerClosed:
|
|
|
|
|
// normal exit, nothing to do
|
|
|
|
|
default:
|
2024-03-27 00:07:29 +05:30
|
|
|
zap.L().Error("Could not start HTTP server", zap.Error(err))
|
2021-01-03 18:15:44 +05:30
|
|
|
}
|
|
|
|
|
s.unavailableChannel <- healthcheck.Unavailable
|
2022-05-13 03:38:00 +05:30
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
go func() {
|
2024-03-27 00:07:29 +05:30
|
|
|
zap.L().Info("Starting pprof server", zap.String("addr", constants.DebugHttpPort))
|
2021-01-03 18:15:44 +05:30
|
|
|
|
2022-05-13 03:38:00 +05:30
|
|
|
err = http.ListenAndServe(constants.DebugHttpPort, nil)
|
|
|
|
|
if err != nil {
|
2024-03-27 00:07:29 +05:30
|
|
|
zap.L().Error("Could not start pprof server", zap.Error(err))
|
2022-05-13 03:38:00 +05:30
|
|
|
}
|
2021-01-03 18:15:44 +05:30
|
|
|
}()
|
|
|
|
|
|
2022-06-08 12:22:25 +05:30
|
|
|
var privatePort int
|
|
|
|
|
if port, err := utils.GetPort(s.privateConn.Addr()); err == nil {
|
|
|
|
|
privatePort = port
|
|
|
|
|
}
|
|
|
|
|
fmt.Println("starting private http")
|
|
|
|
|
go func() {
|
2025-06-21 00:55:38 +05:30
|
|
|
zap.L().Info("Starting Private HTTP server", zap.Int("port", privatePort), zap.String("addr", s.privateHostPort))
|
2022-06-08 12:22:25 +05:30
|
|
|
|
|
|
|
|
switch err := s.privateHTTP.Serve(s.privateConn); err {
|
|
|
|
|
case nil, http.ErrServerClosed, cmux.ErrListenerClosed:
|
|
|
|
|
// normal exit, nothing to do
|
2024-03-27 00:07:29 +05:30
|
|
|
zap.L().Info("private http server closed")
|
2022-06-08 12:22:25 +05:30
|
|
|
default:
|
2024-03-27 00:07:29 +05:30
|
|
|
zap.L().Error("Could not start private HTTP server", zap.Error(err))
|
2022-06-08 12:22:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s.unavailableChannel <- healthcheck.Unavailable
|
|
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
2023-03-15 15:09:15 +05:30
|
|
|
go func() {
|
2024-03-27 00:07:29 +05:30
|
|
|
zap.L().Info("Starting OpAmp Websocket server", zap.String("addr", constants.OpAmpWsEndpoint))
|
2023-10-14 09:16:14 +05:30
|
|
|
err := s.opampServer.Start(constants.OpAmpWsEndpoint)
|
2023-03-15 15:09:15 +05:30
|
|
|
if err != nil {
|
2024-03-27 00:07:29 +05:30
|
|
|
zap.L().Info("opamp ws server failed to start", zap.Error(err))
|
2023-03-15 15:09:15 +05:30
|
|
|
s.unavailableChannel <- healthcheck.Unavailable
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-18 00:04:25 +05:30
|
|
|
func (s *Server) Stop(ctx context.Context) error {
|
2023-03-15 15:09:15 +05:30
|
|
|
if s.httpServer != nil {
|
|
|
|
|
if err := s.httpServer.Shutdown(context.Background()); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if s.privateHTTP != nil {
|
|
|
|
|
if err := s.privateHTTP.Shutdown(context.Background()); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-14 09:16:14 +05:30
|
|
|
s.opampServer.Stop()
|
2023-03-15 15:09:15 +05:30
|
|
|
|
|
|
|
|
if s.ruleManager != nil {
|
2025-04-18 00:04:25 +05:30
|
|
|
s.ruleManager.Stop(ctx)
|
2023-03-15 15:09:15 +05:30
|
|
|
}
|
|
|
|
|
|
2021-01-03 18:15:44 +05:30
|
|
|
return nil
|
|
|
|
|
}
|
2022-07-14 11:59:06 +05:30
|
|
|
|
|
|
|
|
func makeRulesManager(
|
|
|
|
|
ch interfaces.Reader,
|
2024-09-24 10:22:52 +05:30
|
|
|
cache cache.Cache,
|
2025-03-10 01:30:42 +05:30
|
|
|
sqlstore sqlstore.SQLStore,
|
2025-03-31 19:41:11 +05:30
|
|
|
telemetryStore telemetrystore.TelemetryStore,
|
|
|
|
|
prometheus prometheus.Prometheus,
|
2025-05-31 16:04:13 +05:30
|
|
|
orgGetter organization.Getter,
|
2025-03-10 01:30:42 +05:30
|
|
|
) (*rules.Manager, error) {
|
2022-07-14 11:59:06 +05:30
|
|
|
// create manager opts
|
|
|
|
|
managerOpts := &rules.ManagerOptions{
|
2025-04-28 21:01:35 +05:30
|
|
|
TelemetryStore: telemetryStore,
|
|
|
|
|
Prometheus: prometheus,
|
|
|
|
|
Context: context.Background(),
|
|
|
|
|
Logger: zap.L(),
|
|
|
|
|
Reader: ch,
|
|
|
|
|
Cache: cache,
|
|
|
|
|
EvalDelay: constants.GetEvalDelay(),
|
|
|
|
|
SQLStore: sqlstore,
|
2025-05-31 16:04:13 +05:30
|
|
|
OrgGetter: orgGetter,
|
2022-07-14 11:59:06 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create Manager
|
|
|
|
|
manager, err := rules.NewManager(managerOpts)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("rule manager error: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-27 00:07:29 +05:30
|
|
|
zap.L().Info("rules manager is ready")
|
2022-07-14 11:59:06 +05:30
|
|
|
|
|
|
|
|
return manager, nil
|
|
|
|
|
}
|