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:
@@ -209,7 +209,7 @@ func TestLocalStorageService(t *testing.T) {
|
||||
storage := storagesvc.NewLocalStorage(localPath)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
os.Setenv("METRICS_ADDR", ":8083")
|
||||
os.Setenv("METRICS_ADDR", "8083")
|
||||
_ = storagesvc.Start(ctx, logger, storage, port, true)
|
||||
|
||||
time.Sleep(time.Second)
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"go.opencensus.io/plugin/ochttp"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/fission/fission/pkg/utils/httpserver"
|
||||
"github.com/fission/fission/pkg/utils/metrics"
|
||||
"github.com/fission/fission/pkg/utils/otel"
|
||||
)
|
||||
@@ -214,7 +215,7 @@ func MakeStorageService(logger *zap.Logger, storageClient *StowClient, port int)
|
||||
}
|
||||
}
|
||||
|
||||
func (ss *StorageService) Start(port int, openTracingEnabled bool) {
|
||||
func (ss *StorageService) Start(ctx context.Context, port int, openTracingEnabled bool) {
|
||||
r := mux.NewRouter()
|
||||
r.Use(metrics.HTTPMetricMiddleware())
|
||||
r.HandleFunc("/v1/archive", ss.uploadHandler).Methods("POST")
|
||||
@@ -222,8 +223,6 @@ func (ss *StorageService) Start(port int, openTracingEnabled bool) {
|
||||
r.HandleFunc("/v1/archive", ss.deleteHandler).Methods("DELETE")
|
||||
r.HandleFunc("/healthz", ss.healthHandler).Methods("GET")
|
||||
|
||||
address := fmt.Sprintf(":%v", port)
|
||||
|
||||
var handler http.Handler
|
||||
if openTracingEnabled {
|
||||
handler = &ochttp.Handler{
|
||||
@@ -232,8 +231,7 @@ func (ss *StorageService) Start(port int, openTracingEnabled bool) {
|
||||
} else {
|
||||
handler = otel.GetHandlerWithOTEL(r, "fission-storagesvc", otel.UrlsToIgnore("/healthz"))
|
||||
}
|
||||
err := http.ListenAndServe(address, handler)
|
||||
ss.logger.Fatal("done listening", zap.Error(err))
|
||||
httpserver.StartServer(ctx, ss.logger, "storagesvc", fmt.Sprintf("%d", port), handler)
|
||||
}
|
||||
|
||||
// Start runs storage service
|
||||
@@ -248,7 +246,7 @@ func Start(ctx context.Context, logger *zap.Logger, storage Storage, port int, o
|
||||
// create http handlers
|
||||
storageService := MakeStorageService(logger, storageClient, port)
|
||||
go metrics.ServeMetrics(ctx, logger)
|
||||
go storageService.Start(port, openTracingEnabled)
|
||||
go storageService.Start(ctx, port, openTracingEnabled)
|
||||
|
||||
// enablePruner prevents storagesvc unit test from needing to talk to kubernetes
|
||||
if enablePruner {
|
||||
|
||||
Reference in New Issue
Block a user