(configDir string, cryptoKey string)
| 28 | ) |
| 29 | |
| 30 | func Initialize(configDir string, cryptoKey string) (func(), error) { |
| 31 | config, err := conf.InitConfig(configDir, cryptoKey) |
| 32 | if err != nil { |
| 33 | return nil, fmt.Errorf("failed to init config: %v", err) |
| 34 | } |
| 35 | |
| 36 | logxClean, err := logx.Init(config.Log) |
| 37 | if err != nil { |
| 38 | return nil, err |
| 39 | } |
| 40 | //check CenterApi is default value |
| 41 | if len(config.CenterApi.Addrs) < 1 { |
| 42 | return nil, errors.New("failed to init config: the CenterApi configuration is missing") |
| 43 | } |
| 44 | ctx := ctx.NewContext(context.Background(), nil, false, config.CenterApi) |
| 45 | |
| 46 | var redis storage.Redis |
| 47 | redis, err = storage.NewRedis(config.Redis) |
| 48 | if err != nil { |
| 49 | return nil, err |
| 50 | } |
| 51 | |
| 52 | syncStats := memsto.NewSyncStats() |
| 53 | |
| 54 | targetCache := memsto.NewTargetCache(ctx, syncStats, redis) |
| 55 | busiGroupCache := memsto.NewBusiGroupCache(ctx, syncStats) |
| 56 | configCvalCache := memsto.NewCvalCache(ctx, syncStats) |
| 57 | idents := idents.New(ctx, redis, config.Pushgw) |
| 58 | metas := metas.New(redis) |
| 59 | writers := writer.NewWriters(config.Pushgw) |
| 60 | pushgwRouter := pushgwrt.New(config.HTTP, config.Pushgw, config.Alert, targetCache, busiGroupCache, idents, metas, writers, ctx) |
| 61 | r := httpx.GinEngine(config.Global.RunMode, config.HTTP, configCvalCache.PrintBodyPaths, configCvalCache.PrintAccessLog) |
| 62 | |
| 63 | pushgwRouter.Config(r) |
| 64 | macros.RegisterMacro(macros.MacroInVain) |
| 65 | dscache.Init(ctx, false) |
| 66 | |
| 67 | if !config.Alert.Disable { |
| 68 | configCache := memsto.NewConfigCache(ctx, syncStats, nil, "") |
| 69 | alertStats := astats.NewSyncStats() |
| 70 | dsCache := memsto.NewDatasourceCache(ctx, syncStats) |
| 71 | alertMuteCache := memsto.NewAlertMuteCache(ctx, syncStats) |
| 72 | alertRuleCache := memsto.NewAlertRuleCache(ctx, syncStats) |
| 73 | notifyConfigCache := memsto.NewNotifyConfigCache(ctx, configCache) |
| 74 | userCache := memsto.NewUserCache(ctx, syncStats) |
| 75 | userGroupCache := memsto.NewUserGroupCache(ctx, syncStats) |
| 76 | taskTplsCache := memsto.NewTaskTplCache(ctx) |
| 77 | notifyRuleCache := memsto.NewNotifyRuleCache(ctx, syncStats) |
| 78 | notifyChannelCache := memsto.NewNotifyChannelCache(ctx, syncStats) |
| 79 | messageTemplateCache := memsto.NewMessageTemplateCache(ctx, syncStats) |
| 80 | |
| 81 | promClients := prom.NewPromClient(ctx) |
| 82 | |
| 83 | dispatch.InitRegisterQueryFunc(promClients) |
| 84 | |
| 85 | externalProcessors := process.NewExternalProcessors() |
| 86 | |
| 87 | alert.Start(config.Alert, config.Pushgw, syncStats, alertStats, externalProcessors, targetCache, busiGroupCache, alertMuteCache, |
no test coverage detected