@@ -58,6 +58,17 @@ type BitcoinConfig struct {
5858 TLSPath string `long:"tlspath" description:"Path to btcd's TLS certificate, if TLS is enabled"`
5959}
6060
61+ // PrometheusGatewayConfig defines exported config options for connecting to the
62+ // Prometheus PushGateway.
63+ type PrometheusGatewayConfig struct {
64+ // nolint: lll
65+ Enabled bool `long:"enabled" description:"Enable pushing metrics to Prometheus PushGateway"`
66+ // nolint: lll
67+ Host string `long:"host" description:"Prometheus PushGateway host address"`
68+ Port int `long:"port" description:"Prometheus PushGateway port"`
69+ PushURL string
70+ }
71+
6172// Config holds the main configuration for the performance testing binary.
6273type Config struct {
6374 // TestCases is a comma separated list of test cases that will be
@@ -97,6 +108,12 @@ type Config struct {
97108
98109 // TestTimeout is the timeout for each test.
99110 TestTimeout time.Duration `long:"test-timeout" description:"the timeout for each test"`
111+
112+ // PrometheusGateway is the configuration for the Prometheus
113+ // PushGateway.
114+ //
115+ // nolint: lll
116+ PrometheusGateway * PrometheusGatewayConfig `group:"prometheus-gateway" namespace:"prometheus-gateway" description:"Prometheus PushGateway configuration"`
100117}
101118
102119// DefaultConfig returns the default configuration for the performance testing
@@ -120,6 +137,11 @@ func DefaultConfig() Config {
120137 SendType : taprpc .AssetType_COLLECTIBLE ,
121138 TestSuiteTimeout : defaultSuiteTimeout ,
122139 TestTimeout : defaultTestTimeout ,
140+ PrometheusGateway : & PrometheusGatewayConfig {
141+ Enabled : false ,
142+ Host : "localhost" ,
143+ Port : 9091 ,
144+ },
123145 }
124146}
125147
@@ -156,6 +178,28 @@ func LoadConfig() (*Config, error) {
156178// of it with sane defaults.
157179func ValidateConfig (cfg Config ) (* Config , error ) {
158180 // TODO (positiveblue): add validation logic.
181+
182+ // Validate Prometheus PushGateway configuration.
183+ if cfg .PrometheusGateway .Enabled {
184+ gatewayHost := cfg .PrometheusGateway .Host
185+ gatewayPort := cfg .PrometheusGateway .Port
186+
187+ if gatewayHost == "" {
188+ return nil , fmt .Errorf (
189+ "gateway hostname may not be empty" ,
190+ )
191+ }
192+
193+ if gatewayPort == 0 {
194+ return nil , fmt .Errorf ("gateway port is not set" )
195+ }
196+
197+ // Construct the endpoint for Prometheus PushGateway.
198+ cfg .PrometheusGateway .PushURL = fmt .Sprintf (
199+ "%s:%d" , gatewayHost , gatewayPort ,
200+ )
201+ }
202+
159203 return & cfg , nil
160204}
161205
0 commit comments