-
Notifications
You must be signed in to change notification settings - Fork 144
/
main.go
172 lines (139 loc) · 6.47 KB
/
main.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package main
import (
"github.com/frain-dev/convoy/cmd/ff"
"github.com/frain-dev/convoy/cmd/utils"
"os"
"time"
_ "time/tzdata"
"github.com/frain-dev/convoy/cmd/agent"
"github.com/frain-dev/convoy/cmd/bootstrap"
configCmd "github.com/frain-dev/convoy/cmd/config"
"github.com/frain-dev/convoy/cmd/hooks"
"github.com/frain-dev/convoy/cmd/ingest"
"github.com/frain-dev/convoy/cmd/migrate"
"github.com/frain-dev/convoy/cmd/retry"
"github.com/frain-dev/convoy/cmd/server"
"github.com/frain-dev/convoy/cmd/stream"
"github.com/frain-dev/convoy/cmd/version"
"github.com/frain-dev/convoy/cmd/worker"
"github.com/frain-dev/convoy/database/postgres"
"github.com/sirupsen/logrus"
"github.com/frain-dev/convoy/internal/pkg/cli"
"github.com/frain-dev/convoy"
)
func main() {
slog := logrus.New()
slog.Out = os.Stdout
err := os.Setenv("TZ", "") // Use UTC by default :)
if err != nil {
slog.Fatal("failed to set env - ", err)
}
app := &cli.App{}
app.Version = convoy.GetVersionFromFS(convoy.F)
db := &postgres.Postgres{}
c := cli.NewCli(app)
var dbPort int
var dbType string
var dbHost string
var dbScheme string
var dbUsername string
var dbPassword string
var dbDatabase string
var dbReadReplicasDSN []string
var fflag []string
var ipAllowList []string
var ipBLockList []string
var enableProfiling bool
var redisPort int
var redisHost string
var redisType string
var redisScheme string
var redisUsername string
var redisPassword string
var redisDatabase string
var tracerType string
var sentryDSN string
var otelSampleRate float64
var otelCollectorURL string
var otelAuthHeaderName string
var otelAuthHeaderValue string
var dataDogAgentUrl string
var metricsBackend string
var prometheusMetricsSampleTime uint64
var retentionPolicy string
var retentionPolicyEnabled bool
var maxRetrySeconds uint64
var instanceIngestRate int
var apiRateLimit int
var licenseKey string
var configFile string
c.Flags().StringVar(&configFile, "config", "./convoy.json", "Configuration file for convoy")
c.Flags().StringVar(&licenseKey, "license-key", "", "Convoy license key")
// db config
c.Flags().StringVar(&dbHost, "db-host", "", "Database Host")
c.Flags().StringVar(&dbType, "db-type", "", "Database provider")
c.Flags().StringVar(&dbScheme, "db-scheme", "", "Database Scheme")
c.Flags().StringVar(&dbUsername, "db-username", "", "Database Username")
c.Flags().StringVar(&dbPassword, "db-password", "", "Database Password")
c.Flags().StringVar(&dbDatabase, "db-database", "", "Database Database")
c.Flags().StringVar(&dbDatabase, "db-options", "", "Database Options")
c.Flags().IntVar(&dbPort, "db-port", 0, "Database Port")
c.Flags().BoolVar(&enableProfiling, "enable-profiling", false, "Enable profiling and exporting profile data to pyroscope")
c.Flags().StringSliceVar(&dbReadReplicasDSN, "read-replicas-dsn", []string{}, "Comma-separated list of read replica DSNs e.g. postgres://convoy:convoy@host1:5436/db,postgres://convoy:convoy@host2:5437/db")
// redis config
c.Flags().StringVar(&redisHost, "redis-host", "", "Redis Host")
c.Flags().StringVar(&redisType, "redis-type", "", "Redis provider")
c.Flags().StringVar(&redisScheme, "redis-scheme", "", "Redis Scheme")
c.Flags().StringVar(&redisUsername, "redis-username", "", "Redis Username")
c.Flags().StringVar(&redisPassword, "redis-password", "", "Redis Password")
c.Flags().StringVar(&redisDatabase, "redis-database", "", "Redis database")
c.Flags().IntVar(&redisPort, "redis-port", 0, "Redis Port")
// misc
c.Flags().StringSliceVar(&fflag, "enable-feature-flag", []string{}, "List of feature flags to enable e.g. \"full-text-search,prometheus\"")
c.Flags().StringSliceVar(&ipAllowList, "ip-allow-list", []string{}, "List of IPs CIDRs to allow e.g. \" 0.0.0.0/0,127.0.0.0/8\"")
c.Flags().StringSliceVar(&ipBLockList, "ip-block-list", []string{}, "List of IPs CIDRs to block e.g. \" 0.0.0.0/0,127.0.0.0/8\"")
c.Flags().IntVar(&instanceIngestRate, "instance-ingest-rate", 0, "Instance ingest Rate")
c.Flags().IntVar(&apiRateLimit, "api-rate-limit", 0, "API rate limit")
// tracing
c.Flags().StringVar(&tracerType, "tracer-type", "", "Tracer backend, e.g. sentry, datadog or otel")
c.Flags().StringVar(&sentryDSN, "sentry-dsn", "", "Sentry backend dsn")
c.Flags().Float64Var(&otelSampleRate, "otel-sample-rate", 1.0, "OTel tracing sample rate")
c.Flags().StringVar(&otelCollectorURL, "otel-collector-url", "", "OTel collector URL")
c.Flags().StringVar(&otelAuthHeaderName, "otel-auth-header-name", "", "OTel backend auth header name")
c.Flags().StringVar(&otelAuthHeaderValue, "otel-auth-header-value", "", "OTel backend auth header value")
c.Flags().StringVar(&dataDogAgentUrl, "datadog-agent-url", "", "Datadog agent URL")
// metrics
c.Flags().StringVar(&metricsBackend, "metrics-backend", "prometheus", "Metrics backend e.g. prometheus. ('prometheus' feature flag required")
c.Flags().Uint64Var(&prometheusMetricsSampleTime, "metrics-prometheus-sample-time", 5, "Prometheus metrics sample time")
c.Flags().StringVar(&retentionPolicy, "retention-policy", "", "Retention Policy Duration")
c.Flags().BoolVar(&retentionPolicyEnabled, "retention-policy-enabled", false, "Retention Policy Enabled")
c.Flags().Uint64Var(&maxRetrySeconds, "max-retry-seconds", 7200, "Max retry seconds exponential backoff")
AddHCPVaultFlags(c)
c.PersistentPreRunE(hooks.PreRun(app, db))
c.PersistentPostRunE(hooks.PostRun(app, db))
c.AddCommand(version.AddVersionCommand())
c.AddCommand(server.AddServerCommand(app))
c.AddCommand(worker.AddWorkerCommand(app))
c.AddCommand(retry.AddRetryCommand(app))
c.AddCommand(migrate.AddMigrateCommand(app))
c.AddCommand(configCmd.AddConfigCommand(app))
c.AddCommand(stream.AddStreamCommand(app))
c.AddCommand(ingest.AddIngestCommand(app))
c.AddCommand(bootstrap.AddBootstrapCommand(app))
c.AddCommand(agent.AddAgentCommand(app))
c.AddCommand(ff.AddFeatureFlagsCommand())
c.AddCommand(utils.AddUtilsCommand(app))
if err := c.Execute(); err != nil {
slog.Fatal(err)
}
}
func AddHCPVaultFlags(c *cli.ConvoyCli) {
c.Flags().String("hcp-client-id", "", "HCP Vault client ID")
c.Flags().String("hcp-client-secret", "", "HCP Vault client secret")
c.Flags().String("hcp-org-id", "", "HCP Vault organization ID")
c.Flags().String("hcp-project-id", "", "HCP Vault project ID")
c.Flags().String("hcp-app-name", "", "HCP Vault app name")
c.Flags().String("hcp-secret-name", "", "HCP Vault secret name")
// New flag for cache duration
c.Flags().Duration("hcp-cache-duration", 5*time.Minute, "HCP Vault key cache duration")
}