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:
@@ -17,15 +17,17 @@ limitations under the License.
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
builder "github.com/fission/fission/pkg/builder"
|
||||
"github.com/fission/fission/pkg/utils/httpserver"
|
||||
)
|
||||
|
||||
// Usage: builder <shared volume path>
|
||||
func Run(logger *zap.Logger, shareVolume string) error {
|
||||
func Run(ctx context.Context, logger *zap.Logger, shareVolume string) {
|
||||
builder := builder.MakeBuilder(logger, shareVolume)
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", builder.Handler)
|
||||
@@ -33,5 +35,5 @@ func Run(logger *zap.Logger, shareVolume string) error {
|
||||
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
return http.ListenAndServe(":8001", mux)
|
||||
httpserver.StartServer(ctx, logger, "builder", "8001", mux)
|
||||
}
|
||||
|
||||
+4
-6
@@ -24,15 +24,15 @@ import (
|
||||
"github.com/fission/fission/cmd/builder/app"
|
||||
"github.com/fission/fission/pkg/utils/loggerfactory"
|
||||
"github.com/fission/fission/pkg/utils/profile"
|
||||
"github.com/fission/fission/pkg/utils/signals"
|
||||
)
|
||||
|
||||
// Usage: builder <shared volume path>
|
||||
func main() {
|
||||
logger := loggerfactory.GetLogger()
|
||||
defer logger.Sync()
|
||||
|
||||
profile.ProfileIfEnabled(logger)
|
||||
|
||||
ctx := signals.SetupSignalHandlerWithContext(logger)
|
||||
profile.ProfileIfEnabled(ctx, logger)
|
||||
shareVolume := os.Args[1]
|
||||
if _, err := os.Stat(shareVolume); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
@@ -42,7 +42,5 @@ func main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err := app.Run(logger, shareVolume)
|
||||
logger.Error("error running builder", zap.Error(err))
|
||||
app.Run(ctx, logger, shareVolume)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"sync/atomic"
|
||||
@@ -31,6 +30,7 @@ import (
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/fission/fission/pkg/fetcher"
|
||||
"github.com/fission/fission/pkg/utils/httpserver"
|
||||
otelUtils "github.com/fission/fission/pkg/utils/otel"
|
||||
"github.com/fission/fission/pkg/utils/tracing"
|
||||
)
|
||||
@@ -135,9 +135,7 @@ func Run(ctx context.Context, logger *zap.Logger) {
|
||||
} else {
|
||||
handler = otelUtils.GetHandlerWithOTEL(mux, "fission-fetcher", otelUtils.UrlsToIgnore("/healthz", "/readiness-healthz"))
|
||||
}
|
||||
if err = http.ListenAndServe(":8000", handler); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
httpserver.StartServer(ctx, logger, "fetcher", "8000", handler)
|
||||
}
|
||||
|
||||
func fetcherUsage() {
|
||||
|
||||
+1
-2
@@ -28,8 +28,7 @@ func main() {
|
||||
logger := loggerfactory.GetLogger()
|
||||
defer logger.Sync()
|
||||
|
||||
profile.ProfileIfEnabled(logger)
|
||||
|
||||
ctx := signals.SetupSignalHandlerWithContext(logger)
|
||||
profile.ProfileIfEnabled(ctx, logger)
|
||||
app.Run(ctx, logger)
|
||||
}
|
||||
|
||||
@@ -200,7 +200,8 @@ Options:
|
||||
logger := loggerfactory.GetLogger()
|
||||
defer exitWithSync(logger)
|
||||
|
||||
profile.ProfileIfEnabled(logger)
|
||||
ctx := signals.SetupSignalHandlerWithContext(logger)
|
||||
profile.ProfileIfEnabled(ctx, logger)
|
||||
|
||||
version := fmt.Sprintf("Fission Bundle Version: %v", info.BuildInfo().String())
|
||||
arguments, err := docopt.ParseArgs(usage, nil, version)
|
||||
@@ -209,8 +210,6 @@ Options:
|
||||
return
|
||||
}
|
||||
|
||||
ctx := signals.SetupSignalHandlerWithContext(logger)
|
||||
|
||||
openTracingEnabled := tracing.TracingEnabled(logger)
|
||||
if openTracingEnabled {
|
||||
err = tracing.RegisterTraceExporter(logger, os.Getenv("TRACE_JAEGER_COLLECTOR_ENDPOINT"), getServiceName(arguments))
|
||||
|
||||
Reference in New Issue
Block a user