File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,10 @@ type TCPClientSettings struct {
33
33
type Config struct {
34
34
TCPClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
35
35
36
+ // SkipFailOnInvalidTCPEndpoint controls whether to fail if the endpoint is invalid.
37
+ // This is useful for cases where the collector is started before the endpoint becomes available.
38
+ SkipFailOnInvalidTCPEndpoint bool `mapstructure:"skip_fail_on_invalid_tcp_endpoint"`
39
+
36
40
// RequireAck enables the acknowledgement feature.
37
41
RequireAck bool `mapstructure:"require_ack"`
38
42
@@ -87,8 +91,11 @@ func (config *Config) Validate() error {
87
91
88
92
// Resolve TCP address just to ensure that it is a valid one. It is better
89
93
// to fail here than at when the exporter is started.
90
- if _ , err := net .ResolveTCPAddr ("tcp" , config .Endpoint ); err != nil {
91
- return fmt .Errorf ("exporter has an invalid TCP endpoint: %w" , err )
94
+ if ! config .SkipFailOnInvalidTCPEndpoint {
95
+ if _ , err := net .ResolveTCPAddr ("tcp" , config .Endpoint ); err != nil {
96
+ return fmt .Errorf ("exporter has an invalid TCP endpoint: %w" , err )
97
+ }
92
98
}
99
+
93
100
return nil
94
101
}
Original file line number Diff line number Diff line change @@ -110,6 +110,17 @@ func TestConfigValidate(t *testing.T) {
110
110
},
111
111
err : fmt .Errorf ("exporter has an invalid TCP endpoint: address http://localhost:24224: too many colons in address" ),
112
112
},
113
+ {
114
+ desc : "Endpoint is invalid but SkipFailOnInvalidTCPEndpoint is false" ,
115
+ cfg : & Config {
116
+ TCPClientSettings : TCPClientSettings {
117
+ Endpoint : "http://localhost:24224" ,
118
+ ConnectionTimeout : time .Second * 30 ,
119
+ },
120
+ SkipFailOnInvalidTCPEndpoint : true ,
121
+ },
122
+ err : nil ,
123
+ },
113
124
{
114
125
desc : "Config is valid" ,
115
126
cfg : & Config {
You can’t perform that action at this time.
0 commit comments