/
app_config.go
106 lines (88 loc) · 4.86 KB
/
app_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package app
import (
"github.com/jitsucom/bulker/eventslog"
"github.com/jitsucom/bulker/jitsubase/appbase"
"github.com/jitsucom/bulker/jitsubase/utils"
"github.com/jitsucom/bulker/kafkabase"
"github.com/spf13/viper"
"os"
"strings"
)
// Config is a struct for bulker app configuration
// It is loaded from `bulker.env` config file or environment variables.
//
// Environment variables requires prefix `BULKER_`
type Config struct {
appbase.Config `mapstructure:",squash"`
kafkabase.KafkaConfig `mapstructure:",squash"`
// # EVENTS LOG CONFIG - settings for events log
eventslog.EventsLogConfig `mapstructure:",squash"`
// For ingest endpoint only
GlobalHashSecret string `mapstructure:"GLOBAL_HASH_SECRET" default:"dea42a58-acf4-45af-85bb-e77e94bd5025"`
// For ingest endpoint only
GlobalHashSecrets []string
// # DESTINATIONS CONFIGS
// ConfigSource source of destinations configs. Can be:
// - `file://...` for destinations config in yaml format
// - `http://...` for destinations config in json array format
// - `redis` or `redis://redis_url` to load configs from redis `enrichedConnections` key
// - postgresql://postgres_url to load configs from postgresql
// - `env://PREFIX` to load each destination environment variables with like `PREFIX_ID` where ID is destination id
//
// Default: `env://BULKER_DESTINATION`
ConfigSource string `mapstructure:"CONFIG_SOURCE"`
// ConfigSourceHTTPAuthToken auth token for http:// config source
ConfigSourceHTTPAuthToken string `mapstructure:"CONFIG_SOURCE_HTTP_AUTH_TOKEN"`
// ConfigSourceSQLQuery for `postgresql` config source, SQL query to load connections
ConfigSourceSQLQuery string `mapstructure:"CONFIG_SOURCE_SQL_QUERY" default:"select * from enriched_connections"`
// CacheDir dir for config source data
CacheDir string `mapstructure:"CACHE_DIR"`
// ConfigRefreshPeriodSec how often config source will check for new configs. Supported by `postgresql` config sources
ConfigRefreshPeriodSec int `mapstructure:"CONFIG_REFRESH_PERIOD_SEC" default:"5"`
// RedisURL that will be used by default by all services that need Redis
RedisURL string `mapstructure:"REDIS_URL"`
RedisTLSCA string `mapstructure:"REDIS_TLS_CA"`
// TopicManagerRefreshPeriodSec how often topic manager will check for new topics
TopicManagerRefreshPeriodSec int `mapstructure:"TOPIC_MANAGER_REFRESH_PERIOD_SEC" default:"5"`
// # BATCHING
BatchRunnerPeriodSec int `mapstructure:"BATCH_RUNNER_DEFAULT_PERIOD_SEC" default:"300"`
BatchRunnerDefaultBatchSize int `mapstructure:"BATCH_RUNNER_DEFAULT_BATCH_SIZE" default:"10000"`
BatchRunnerWaitForMessagesSec int `mapstructure:"BATCH_RUNNER_WAIT_FOR_MESSAGES_SEC" default:"5"`
// # ERROR RETRYING
BatchRunnerRetryPeriodSec int `mapstructure:"BATCH_RUNNER_DEFAULT_RETRY_PERIOD_SEC" default:"300"`
BatchRunnerDefaultRetryBatchFraction float64 `mapstructure:"BATCH_RUNNER_DEFAULT_RETRY_BATCH_FRACTION" default:"0.1"`
MessagesRetryCount int `mapstructure:"MESSAGES_RETRY_COUNT" default:"5"`
// MessagesRetryBackoffBase defines base for exponential backoff in minutes.
// For example, if retry count is 3 and base is 5, then retry delays will be 5, 25, 125 minutes.
// Default: 5
MessagesRetryBackoffBase float64 `mapstructure:"MESSAGES_RETRY_BACKOFF_BASE" default:"5"`
// MessagesRetryBackoffMaxDelay defines maximum possible retry delay in minutes. Default: 1440 minutes = 24 hours
MessagesRetryBackoffMaxDelay float64 `mapstructure:"MESSAGES_RETRY_BACKOFF_MAX_DELAY" default:"1440"`
// # EVENTS REDIS LOGGING
EventsLogRedisURL string `mapstructure:"EVENTS_LOG_REDIS_URL"`
EventsLogMaxSize int `mapstructure:"EVENTS_LOG_MAX_SIZE" default:"1000"`
// # METRICS
MetricsPort int `mapstructure:"METRICS_PORT" default:"9091"`
MetricsRelayDestination string `mapstructure:"METRICS_RELAY_DESTINATION"`
MetricsRelayPeriodSec int `mapstructure:"METRICS_RELAY_PERIOD_SEC" default:"60"`
InstanceIndex int `mapstructure:"INSTANCE_INDEX" default:"0"`
ShardsCount int `mapstructure:"SHARDS" default:"1"`
// # GRACEFUL SHUTDOWN
//Timeout that give running batch tasks time to finish during shutdown.
ShutdownTimeoutSec int `mapstructure:"SHUTDOWN_TIMEOUT_SEC" default:"10"`
//Extra delay may be needed. E.g. for metric scrapper to scrape final metrics. So http server will stay active for an extra period.
ShutdownExtraDelay int `mapstructure:"SHUTDOWN_EXTRA_DELAY_SEC" default:"5"`
}
func init() {
viper.SetDefault("HTTP_PORT", utils.NvlString(os.Getenv("PORT"), "3042"))
viper.SetDefault("REDIS_URL", os.Getenv("REDIS_URL"))
viper.SetDefault("EVENTS_LOG_REDIS_URL", utils.NvlString(os.Getenv("BULKER_REDIS_URL"), os.Getenv("REDIS_URL")))
}
func (ac *Config) PostInit(settings *appbase.AppSettings) error {
err := ac.Config.PostInit(settings)
if err != nil {
return err
}
ac.GlobalHashSecrets = strings.Split(ac.GlobalHashSecret, ",")
return nil
}