Skip to content

Commit 9193330

Browse files
committed
fixing config
Signed-off-by: Chengxuan Xing <chengxuan.xing@kaleido.io>
1 parent 186d052 commit 9193330

File tree

4 files changed

+71
-33
lines changed

4 files changed

+71
-33
lines changed

config.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,41 @@
174174

175175
|Key|Description|Type|Default Value|
176176
|---|-----------|----|-------------|
177+
|address|The IP address on which the metrics HTTP API should listen|`int`|`127.0.0.1`
177178
|enabled|Deprecated: Please use 'monitoring.enabled' instead|`boolean`|`false`
178179
|path|The path from which to serve the Prometheus metrics|`string`|`/metrics`
180+
|port|The port on which the metrics HTTP API should listen|`int`|`6000`
181+
|publicURL|The fully qualified public URL for the metrics API. This is used for building URLs in HTTP responses and in OpenAPI Spec generation|URL `string`|`<nil>`
182+
|readTimeout|The maximum time to wait when reading from an HTTP connection|[`time.Duration`](https://pkg.go.dev/time#Duration)|`15s`
183+
|shutdownTimeout|The maximum amount of time to wait for any open HTTP requests to finish before shutting down the HTTP server|[`time.Duration`](https://pkg.go.dev/time#Duration)|`10s`
184+
|writeTimeout|The maximum time to wait when writing to an HTTP connection|[`time.Duration`](https://pkg.go.dev/time#Duration)|`15s`
185+
186+
## metrics.auth
187+
188+
|Key|Description|Type|Default Value|
189+
|---|-----------|----|-------------|
190+
|type|The auth plugin to use for server side authentication of requests|`string`|`<nil>`
191+
192+
## metrics.auth.basic
193+
194+
|Key|Description|Type|Default Value|
195+
|---|-----------|----|-------------|
196+
|passwordfile|The path to a .htpasswd file to use for authenticating requests. Passwords should be hashed with bcrypt.|`string`|`<nil>`
197+
198+
## metrics.tls
199+
200+
|Key|Description|Type|Default Value|
201+
|---|-----------|----|-------------|
202+
|ca|The TLS certificate authority in PEM format (this option is ignored if caFile is also set)|`string`|`<nil>`
203+
|caFile|The path to the CA file for TLS on this API|`string`|`<nil>`
204+
|cert|The TLS certificate in PEM format (this option is ignored if certFile is also set)|`string`|`<nil>`
205+
|certFile|The path to the certificate file for TLS on this API|`string`|`<nil>`
206+
|clientAuth|Enables or disables client auth for TLS on this API|`string`|`<nil>`
207+
|enabled|Enables or disables TLS on this API|`boolean`|`false`
208+
|insecureSkipHostVerify|When to true in unit test development environments to disable TLS verification. Use with extreme caution|`boolean`|`<nil>`
209+
|key|The TLS certificate key in PEM format (this option is ignored if keyFile is also set)|`string`|`<nil>`
210+
|keyFile|The path to the private key file for TLS on this API|`string`|`<nil>`
211+
|requiredDNAttributes|A set of required subject DN attributes. Each entry is a regular expression, and the subject certificate must have a matching attribute of the specified type (CN, C, O, OU, ST, L, STREET, POSTALCODE, SERIALNUMBER are valid attributes)|`map[string]string`|`<nil>`
179212

180213
## monitoring
181214

internal/tmconfig/tmconfig.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ var WebhookPrefix config.Section
9191

9292
var MonitoringConfig config.Section
9393

94+
var DeprecatedMetricsConfig config.Section
95+
9496
func setDefaults() {
9597
viper.SetDefault(string(TransactionsMaxHistoryCount), 50)
9698
viper.SetDefault(string(ConfirmationsRequired), 20)
@@ -165,12 +167,7 @@ func Reset() {
165167
TransactionHandlerBaseConfig = config.RootSection("transactions.handler") // Transaction handler must be registered outside of this package
166168

167169
MonitoringConfig = config.RootSection("monitoring")
168-
MetricsConfig := config.RootSection("metrics")
169-
if MetricsConfig.GetBool("enabled") && !MonitoringConfig.GetBool("enabled") {
170-
// only use the deprecated metrics config if the monitoring config is not enabled
171-
httpserver.InitHTTPConfig(MetricsConfig, 6000)
172-
} else {
173-
httpserver.InitHTTPConfig(MonitoringConfig, 6000)
174-
}
175-
170+
DeprecatedMetricsConfig = config.RootSection("metrics")
171+
httpserver.InitHTTPConfig(DeprecatedMetricsConfig, 6000)
172+
httpserver.InitHTTPConfig(MonitoringConfig, 6000)
176173
}

pkg/fftm/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,6 @@ func (m *manager) runAPIServer() {
9090
m.apiServer.ServeHTTP(m.ctx)
9191
}
9292

93-
func (m *manager) runMetricsServer() {
94-
m.metricsServer.ServeHTTP(m.ctx)
93+
func (m *manager) runMonitoringServer() {
94+
m.monitoringServer.ServeHTTP(m.ctx)
9595
}

pkg/fftm/manager.go

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,25 @@ type manager struct {
5151
confirmations confirmations.Manager
5252
txHandler txhandler.TransactionHandler
5353
apiServer httpserver.HTTPServer
54-
metricsServer httpserver.HTTPServer
54+
monitoringServer httpserver.HTTPServer
5555
wsServer ws.WebSocketServer
5656
persistence persistence.Persistence
5757
richQueryEnabled bool
5858

5959
connector ffcapi.API
6060
toolkit *txhandler.Toolkit
6161

62-
mux sync.Mutex
63-
eventStreams map[fftypes.UUID]events.Stream
64-
streamsByName map[string]*fftypes.UUID
65-
blockListenerDone chan struct{}
66-
txHandlerDone <-chan struct{}
67-
started bool
68-
apiServerDone chan error
69-
monitoringServerDone chan error
70-
monitoringEnabled bool
71-
metricsManager metrics.Metrics
62+
mux sync.Mutex
63+
eventStreams map[fftypes.UUID]events.Stream
64+
streamsByName map[string]*fftypes.UUID
65+
blockListenerDone chan struct{}
66+
txHandlerDone <-chan struct{}
67+
started bool
68+
apiServerDone chan error
69+
monitoringServerDone chan error
70+
monitoringEnabled bool
71+
deprecatedMetricsEnabled bool
72+
metricsManager metrics.Metrics
7273
}
7374

7475
func InitConfig() {
@@ -90,13 +91,14 @@ func NewManager(ctx context.Context, connector ffcapi.API) (Manager, error) {
9091

9192
func newManager(ctx context.Context, connector ffcapi.API) *manager {
9293
m := &manager{
93-
connector: connector,
94-
apiServerDone: make(chan error),
95-
monitoringServerDone: make(chan error),
96-
monitoringEnabled: config.GetBool(tmconfig.DeprecatedMetricsEnabled) || config.GetBool(tmconfig.MonitoringEnabled),
97-
eventStreams: make(map[fftypes.UUID]events.Stream),
98-
streamsByName: make(map[string]*fftypes.UUID),
99-
metricsManager: metrics.NewMetricsManager(ctx),
94+
connector: connector,
95+
apiServerDone: make(chan error),
96+
monitoringServerDone: make(chan error),
97+
deprecatedMetricsEnabled: config.GetBool(tmconfig.DeprecatedMetricsEnabled),
98+
monitoringEnabled: config.GetBool(tmconfig.MonitoringEnabled),
99+
eventStreams: make(map[fftypes.UUID]events.Stream),
100+
streamsByName: make(map[string]*fftypes.UUID),
101+
metricsManager: metrics.NewMetricsManager(ctx),
100102
}
101103
m.toolkit = &txhandler.Toolkit{
102104
Connector: m.connector,
@@ -109,7 +111,7 @@ func newManager(ctx context.Context, connector ffcapi.API) *manager {
109111
func (m *manager) initServices(ctx context.Context) (err error) {
110112
m.confirmations = confirmations.NewBlockConfirmationManager(ctx, m.connector, "receipts", m.metricsManager)
111113
m.wsServer = ws.NewWebSocketServer(ctx)
112-
m.apiServer, err = httpserver.NewHTTPServer(ctx, "api", m.router(m.monitoringEnabled), m.apiServerDone, tmconfig.APIConfig, tmconfig.CorsConfig)
114+
m.apiServer, err = httpserver.NewHTTPServer(ctx, "api", m.router(m.monitoringEnabled || m.deprecatedMetricsEnabled), m.apiServerDone, tmconfig.APIConfig, tmconfig.CorsConfig)
113115
if err != nil {
114116
return err
115117
}
@@ -133,10 +135,16 @@ func (m *manager) initServices(ctx context.Context) (err error) {
133135
// in case the transaction handler has logic in the Init function
134136
// to add more metrics
135137
if m.monitoringEnabled {
136-
m.metricsServer, err = httpserver.NewHTTPServer(ctx, "metrics", m.createMonitoringMuxRouter(), m.monitoringServerDone, tmconfig.MonitoringConfig, tmconfig.CorsConfig)
138+
m.monitoringServer, err = httpserver.NewHTTPServer(ctx, "monitoring", m.createMonitoringMuxRouter(), m.monitoringServerDone, tmconfig.MonitoringConfig, tmconfig.CorsConfig)
137139
if err != nil {
138140
return err
139141
}
142+
} else if m.deprecatedMetricsEnabled {
143+
m.monitoringServer, err = httpserver.NewHTTPServer(ctx, "metrics", m.createMonitoringMuxRouter(), m.monitoringServerDone, tmconfig.DeprecatedMetricsConfig, tmconfig.CorsConfig)
144+
if err != nil {
145+
return err
146+
}
147+
140148
}
141149
return nil
142150
}
@@ -180,8 +188,8 @@ func (m *manager) Start() error {
180188
}
181189

182190
go m.runAPIServer()
183-
if m.monitoringEnabled {
184-
go m.runMetricsServer()
191+
if m.monitoringEnabled || m.deprecatedMetricsEnabled {
192+
go m.runMonitoringServer()
185193
}
186194
go m.confirmations.Start()
187195

@@ -198,7 +206,7 @@ func (m *manager) Close() {
198206
if m.started {
199207
m.started = false
200208
<-m.apiServerDone
201-
if m.monitoringEnabled {
209+
if m.monitoringEnabled || m.deprecatedMetricsEnabled {
202210
<-m.monitoringServerDone
203211
}
204212
<-m.txHandlerDone

0 commit comments

Comments
 (0)