Use common httpserver across fission (#2409)

* Defining httpserver package to capture httpserver shutdown and
introduces uniform running of http server across codebase.
* Add unit tests for httpserver

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
Sanket Sudake
2022-04-14 11:35:58 +05:30
committed by GitHub
parent b638a6d047
commit 8442e21621
18 changed files with 139 additions and 93 deletions
+2 -5
View File
@@ -35,6 +35,7 @@ import (
ferror "github.com/fission/fission/pkg/error"
"github.com/fission/fission/pkg/fission-cli/logdb"
"github.com/fission/fission/pkg/info"
"github.com/fission/fission/pkg/utils/httpserver"
"github.com/fission/fission/pkg/utils/metrics"
"github.com/fission/fission/pkg/utils/otel"
)
@@ -270,9 +271,6 @@ func (api *API) GetHandler() http.Handler {
}
func (api *API) Serve(ctx context.Context, port int, openTracingEnabled bool) {
address := fmt.Sprintf(":%v", port)
api.logger.Info("server started", zap.Int("port", port))
var handler http.Handler
if openTracingEnabled {
handler = &ochttp.Handler{Handler: api.GetHandler()}
@@ -281,6 +279,5 @@ func (api *API) Serve(ctx context.Context, port int, openTracingEnabled bool) {
}
go metrics.ServeMetrics(ctx, api.logger)
err := http.ListenAndServe(address, handler)
api.logger.Fatal("done listening", zap.Error(err))
httpserver.StartServer(ctx, api.logger, "controller", fmt.Sprintf("%d", port), handler)
}