2022-10-06 20:13:30 +05:30
package main
import (
"context"
"flag"
"os"
2023-06-21 11:47:30 +05:30
"time"
2022-10-06 20:13:30 +05:30
2025-05-24 19:14:29 +05:30
"github.com/SigNoz/signoz/ee/licensing"
"github.com/SigNoz/signoz/ee/licensing/httplicensing"
2025-03-20 21:01:41 +05:30
"github.com/SigNoz/signoz/ee/query-service/app"
2025-03-27 11:16:43 +05:30
"github.com/SigNoz/signoz/ee/sqlstore/postgressqlstore"
2025-04-28 19:50:47 +05:30
"github.com/SigNoz/signoz/ee/zeus"
"github.com/SigNoz/signoz/ee/zeus/httpzeus"
2025-03-20 21:01:41 +05:30
"github.com/SigNoz/signoz/pkg/config"
"github.com/SigNoz/signoz/pkg/config/envprovider"
"github.com/SigNoz/signoz/pkg/config/fileprovider"
2025-05-23 00:01:52 +05:30
"github.com/SigNoz/signoz/pkg/factory"
2025-05-24 19:14:29 +05:30
pkglicensing "github.com/SigNoz/signoz/pkg/licensing"
2025-05-31 16:04:13 +05:30
"github.com/SigNoz/signoz/pkg/modules/organization"
2025-03-20 21:01:41 +05:30
baseconst "github.com/SigNoz/signoz/pkg/query-service/constants"
"github.com/SigNoz/signoz/pkg/signoz"
2025-05-14 23:12:55 +05:30
"github.com/SigNoz/signoz/pkg/sqlstore"
2025-03-27 11:16:43 +05:30
"github.com/SigNoz/signoz/pkg/sqlstore/sqlstorehook"
2025-03-20 21:01:41 +05:30
"github.com/SigNoz/signoz/pkg/types/authtypes"
2025-03-24 14:38:48 +05:30
"github.com/SigNoz/signoz/pkg/version"
2025-05-24 19:14:29 +05:30
pkgzeus "github.com/SigNoz/signoz/pkg/zeus"
2023-06-21 11:47:30 +05:30
2022-10-06 20:13:30 +05:30
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
2025-04-28 21:01:35 +05:30
// Deprecated: Please use the logger from pkg/instrumentation.
2025-03-23 11:49:37 +05:30
func initZapLog ( ) * zap . Logger {
2024-03-27 00:07:29 +05:30
config := zap . NewProductionConfig ( )
2022-10-06 20:13:30 +05:30
config . EncoderConfig . TimeKey = "timestamp"
config . EncoderConfig . EncodeTime = zapcore . ISO8601TimeEncoder
2025-03-23 11:49:37 +05:30
logger , _ := config . Build ( )
2022-10-06 20:13:30 +05:30
return logger
}
func main ( ) {
2023-06-30 06:58:22 +05:30
var promConfigPath , skipTopLvlOpsPath string
2022-10-06 20:13:30 +05:30
// disables rule execution but allows change to the rule definition
var disableRules bool
// the url used to build link in the alert messages in slack and other systems
var ruleRepoURL string
2023-10-20 12:37:45 +05:30
var cluster string
2022-10-06 20:13:30 +05:30
2024-09-12 10:58:07 +05:30
var useLogsNewSchema bool
2024-11-22 12:00:29 +05:30
var useTraceNewSchema bool
2025-01-24 00:16:38 +05:30
var cacheConfigPath , fluxInterval , fluxIntervalForTraceDetail string
2023-07-14 11:31:44 +05:30
var preferSpanMetrics bool
2023-06-21 11:47:30 +05:30
2023-08-10 17:20:34 +05:30
var maxIdleConns int
var maxOpenConns int
var dialTimeout time . Duration
2024-06-04 18:25:24 +05:30
var gatewayUrl string
2024-12-17 01:12:31 +05:30
var useLicensesV3 bool
2023-08-10 17:20:34 +05:30
2025-04-28 21:01:35 +05:30
// Deprecated
2024-09-12 10:58:07 +05:30
flag . BoolVar ( & useLogsNewSchema , "use-logs-new-schema" , false , "use logs_v2 schema for logs" )
2025-04-28 21:01:35 +05:30
// Deprecated
2024-11-22 12:00:29 +05:30
flag . BoolVar ( & useTraceNewSchema , "use-trace-new-schema" , false , "use new schema for traces" )
2025-04-28 14:57:26 +05:30
// Deprecated
2022-10-06 20:13:30 +05:30
flag . StringVar ( & promConfigPath , "config" , "./config/prometheus.yml" , "(prometheus config to read metrics)" )
2025-04-28 14:57:26 +05:30
// Deprecated
2023-06-30 06:58:22 +05:30
flag . StringVar ( & skipTopLvlOpsPath , "skip-top-level-ops" , "" , "(config file to skip top level operations)" )
2025-04-28 14:57:26 +05:30
// Deprecated
2022-10-06 20:13:30 +05:30
flag . BoolVar ( & disableRules , "rules.disable" , false , "(disable rule evaluation)" )
2023-07-14 11:31:44 +05:30
flag . BoolVar ( & preferSpanMetrics , "prefer-span-metrics" , false , "(prefer span metrics for service level metrics)" )
2025-04-28 14:57:26 +05:30
// Deprecated
2023-08-10 17:20:34 +05:30
flag . IntVar ( & maxIdleConns , "max-idle-conns" , 50 , "(number of connections to maintain in the pool.)" )
2025-04-28 14:57:26 +05:30
// Deprecated
2023-08-10 17:20:34 +05:30
flag . IntVar ( & maxOpenConns , "max-open-conns" , 100 , "(max connections for use at any time.)" )
2025-04-28 14:57:26 +05:30
// Deprecated
2023-08-10 17:20:34 +05:30
flag . DurationVar ( & dialTimeout , "dial-timeout" , 5 * time . Second , "(the maximum time to establish a connection.)" )
2025-04-28 14:57:26 +05:30
// Deprecated
2022-10-06 20:13:30 +05:30
flag . StringVar ( & ruleRepoURL , "rules.repo-url" , baseconst . AlertHelpPage , "(host address used to build rule link in alert messages)" )
2025-05-03 18:30:07 +05:30
// Deprecated
2023-09-17 10:40:45 +05:30
flag . StringVar ( & cacheConfigPath , "experimental.cache-config" , "" , "(cache config to use)" )
2024-06-25 10:10:33 +05:30
flag . StringVar ( & fluxInterval , "flux-interval" , "5m" , "(the interval to exclude data from being cached to avoid incorrect cache for data in motion)" )
2025-01-24 00:16:38 +05:30
flag . StringVar ( & fluxIntervalForTraceDetail , "flux-interval-trace-detail" , "2m" , "(the interval to exclude data from being cached to avoid incorrect cache for trace data in motion)" )
2023-10-20 12:37:45 +05:30
flag . StringVar ( & cluster , "cluster" , "cluster" , "(cluster name - defaults to 'cluster')" )
2024-06-04 18:25:24 +05:30
flag . StringVar ( & gatewayUrl , "gateway-url" , "" , "(url to the gateway)" )
2025-04-28 14:57:26 +05:30
// Deprecated
2024-12-17 01:12:31 +05:30
flag . BoolVar ( & useLicensesV3 , "use-licenses-v3" , false , "use licenses_v3 schema for licenses" )
2022-10-06 20:13:30 +05:30
flag . Parse ( )
2025-03-23 11:49:37 +05:30
loggerMgr := initZapLog ( )
2022-10-06 20:13:30 +05:30
zap . ReplaceGlobals ( loggerMgr )
defer loggerMgr . Sync ( ) // flushes buffer, if any
2025-05-24 19:14:29 +05:30
ctx := context . Background ( )
2022-10-06 20:13:30 +05:30
2025-05-24 19:14:29 +05:30
config , err := signoz . NewConfig ( ctx , config . ResolverConfig {
2025-01-20 17:45:33 +05:30
Uris : [ ] string { "env:" } ,
ProviderFactories : [ ] config . ProviderFactory {
envprovider . NewFactory ( ) ,
fileprovider . NewFactory ( ) ,
2024-12-23 16:44:48 +05:30
} ,
2025-01-30 15:51:55 +05:30
} , signoz . DeprecatedFlags {
MaxIdleConns : maxIdleConns ,
MaxOpenConns : maxOpenConns ,
DialTimeout : dialTimeout ,
2025-03-31 19:41:11 +05:30
Config : promConfigPath ,
2024-12-23 16:44:48 +05:30
} )
if err != nil {
zap . L ( ) . Fatal ( "Failed to create config" , zap . Error ( err ) )
}
2025-03-24 14:38:48 +05:30
version . Info . PrettyPrint ( config . Version )
2025-03-27 11:16:43 +05:30
sqlStoreFactories := signoz . NewSQLStoreProviderFactories ( )
if err := sqlStoreFactories . Add ( postgressqlstore . NewFactory ( sqlstorehook . NewLoggingFactory ( ) ) ) ; err != nil {
zap . L ( ) . Fatal ( "Failed to add postgressqlstore factory" , zap . Error ( err ) )
}
2025-05-23 00:01:52 +05:30
jwtSecret := os . Getenv ( "SIGNOZ_JWT_SECRET" )
if len ( jwtSecret ) == 0 {
zap . L ( ) . Warn ( "No JWT secret key is specified." )
} else {
zap . L ( ) . Info ( "JWT secret key set successfully." )
}
jwt := authtypes . NewJWT ( jwtSecret , 30 * time . Minute , 30 * 24 * time . Hour )
2025-03-10 01:30:42 +05:30
signoz , err := signoz . New (
context . Background ( ) ,
config ,
2025-05-25 14:16:42 +05:30
jwt ,
2025-04-28 19:50:47 +05:30
zeus . Config ( ) ,
httpzeus . NewProviderFactory ( ) ,
2025-05-24 19:14:29 +05:30
licensing . Config ( 24 * time . Hour , 3 ) ,
2025-05-31 16:04:13 +05:30
func ( sqlstore sqlstore . SQLStore , zeus pkgzeus . Zeus , orgGetter organization . Getter ) factory . ProviderFactory [ pkglicensing . Licensing , pkglicensing . Config ] {
return httplicensing . NewProviderFactory ( sqlstore , zeus , orgGetter )
2025-05-24 19:14:29 +05:30
} ,
2025-05-23 00:01:52 +05:30
signoz . NewEmailingProviderFactories ( ) ,
2025-03-10 01:30:42 +05:30
signoz . NewCacheProviderFactories ( ) ,
signoz . NewWebProviderFactories ( ) ,
2025-03-27 11:16:43 +05:30
sqlStoreFactories ,
2025-03-10 01:30:42 +05:30
signoz . NewTelemetryStoreProviderFactories ( ) ,
)
2025-01-04 01:28:54 +05:30
if err != nil {
2025-03-31 19:41:11 +05:30
zap . L ( ) . Fatal ( "Failed to create signoz" , zap . Error ( err ) )
2024-12-23 16:44:48 +05:30
}
2022-10-06 20:13:30 +05:30
serverOptions := & app . ServerOptions {
2025-01-24 00:16:38 +05:30
Config : config ,
SigNoz : signoz ,
HTTPHostPort : baseconst . HTTPHostPort ,
PreferSpanMetrics : preferSpanMetrics ,
PrivateHostPort : baseconst . PrivateHostPort ,
FluxInterval : fluxInterval ,
FluxIntervalForTraceDetail : fluxIntervalForTraceDetail ,
Cluster : cluster ,
GatewayUrl : gatewayUrl ,
2025-02-17 18:16:41 +05:30
Jwt : jwt ,
2022-10-06 20:13:30 +05:30
}
2025-01-04 01:28:54 +05:30
server , err := app . NewServer ( serverOptions )
2022-10-06 20:13:30 +05:30
if err != nil {
2024-03-27 00:07:29 +05:30
zap . L ( ) . Fatal ( "Failed to create server" , zap . Error ( err ) )
2022-10-06 20:13:30 +05:30
}
2025-05-24 19:14:29 +05:30
if err := server . Start ( ctx ) ; err != nil {
2024-03-27 00:07:29 +05:30
zap . L ( ) . Fatal ( "Could not start server" , zap . Error ( err ) )
2022-10-06 20:13:30 +05:30
}
2025-05-24 19:14:29 +05:30
signoz . Start ( ctx )
2022-10-06 20:13:30 +05:30
2025-05-24 19:14:29 +05:30
if err := signoz . Wait ( ctx ) ; err != nil {
2025-03-10 01:30:42 +05:30
zap . L ( ) . Fatal ( "Failed to start signoz" , zap . Error ( err ) )
}
2025-05-24 19:14:29 +05:30
err = server . Stop ( ctx )
2025-03-10 01:30:42 +05:30
if err != nil {
zap . L ( ) . Fatal ( "Failed to stop server" , zap . Error ( err ) )
}
2025-05-24 19:14:29 +05:30
err = signoz . Stop ( ctx )
2025-03-10 01:30:42 +05:30
if err != nil {
zap . L ( ) . Fatal ( "Failed to stop signoz" , zap . Error ( err ) )
2022-10-06 20:13:30 +05:30
}
}