@@ -20,6 +20,7 @@ import (
20
20
"github.com/corvus-ch/rabbitmq-cli-consumer/consumer"
21
21
"github.com/corvus-ch/rabbitmq-cli-consumer/log"
22
22
"github.com/corvus-ch/rabbitmq-cli-consumer/processor"
23
+ "github.com/pkg/errors"
23
24
"github.com/prometheus/client_golang/prometheus"
24
25
"github.com/prometheus/client_golang/prometheus/promhttp"
25
26
"github.com/streadway/amqp"
@@ -145,17 +146,25 @@ func Action(c *cli.Context) error {
145
146
}
146
147
defer client .Close ()
147
148
149
+ errs := make (chan error )
150
+
148
151
if c .Bool ("metrics" ) {
149
152
ll .Infof ("Registering metrics server at %v" , c .String ("web.listen-address" ))
150
- setupAndServeMetrics (c .String ("web.listen-address" ), c .String ("web.telemetry-path" ))
153
+ go func () {
154
+ errs <- setupAndServeMetrics (c .String ("web.listen-address" ), c .String ("web.telemetry-path" ))
155
+ }()
151
156
} else {
152
157
ll .Infof ("Metrics disabled." )
153
158
}
154
159
155
- return consume (client , l )
160
+ go func () {
161
+ errs <- consume (client , l )
162
+ }()
163
+
164
+ return <- errs
156
165
}
157
166
158
- func setupAndServeMetrics (addr string , path string ) {
167
+ func setupAndServeMetrics (addr string , path string ) error {
159
168
srv := & http.Server {
160
169
Addr : addr ,
161
170
// Good practice to set timeouts to avoid Slowloris attacks.
@@ -178,11 +187,12 @@ func setupAndServeMetrics(addr string, path string) {
178
187
</body>
179
188
</html>` ))
180
189
})
181
- go func () {
182
- if err := srv .ListenAndServe (); err != nil {
183
- panic (err )
184
- }
185
- }()
190
+
191
+ if err := srv .ListenAndServe (); err != nil {
192
+ return errors .Wrap (err , "failed to serve metrics" )
193
+ }
194
+
195
+ return nil
186
196
}
187
197
188
198
func consume (client * consumer.Consumer , l logr.Logger ) error {
0 commit comments