Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit 5b18626

Browse files
committed
503 for /metrics/import if no bulk importer configured
1 parent 9c44e77 commit 5b18626

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

cmd/mt-gateway/api.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,26 @@ func NewApi(urls Urls) Api {
2727
})
2828
api.graphiteHandler = newProxyWithLogging("graphite", urls.graphite)
2929
api.metrictankHandler = newProxyWithLogging("metrictank", urls.metrictank)
30-
api.bulkImportHandler = newProxyWithLogging("bulk-importer", urls.bulkImporter)
30+
api.bulkImportHandler = bulkImportHandler(urls)
3131
return api
3232
}
3333

34+
func bulkImportHandler(urls Urls) http.Handler {
35+
if urls.bulkImporter.String() != "" {
36+
log.WithField("url", urls.bulkImporter.String()).Info("bulk importer configured")
37+
return newProxyWithLogging("bulk-importer", urls.bulkImporter)
38+
}
39+
log.Warn("no url configured for bulk importer service")
40+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
41+
log.WithField("service", "bulk-importer").
42+
WithField("method", r.Method).
43+
WithField("path", r.URL.Path).
44+
WithField("status", http.StatusServiceUnavailable).Info()
45+
w.WriteHeader(http.StatusServiceUnavailable)
46+
_, _ = fmt.Fprintln(w, "no url configured for bulk importer service")
47+
})
48+
}
49+
3450
//Builds an http.ServeMux based on the handlers defined in the Api
3551
func (api Api) Mux() *http.ServeMux {
3652
mux := http.NewServeMux()

0 commit comments

Comments
 (0)