Skip to content

Commit

Permalink
fix stack overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
cottand committed Aug 23, 2024
1 parent a54ad2a commit b8e6fca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
8 changes: 2 additions & 6 deletions services/lib/bedrock/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@ func (c *BaseConfig) HttpBind() string {

func Serve(ctx context.Context, mux *http.ServeMux) {

muxWithMetrics := http.NewServeMux()
// instrument the root
muxWithMetrics.Handle("/", otelhttp.NewHandler(mux, "/"))
// add un-instrumented metrics endpoint
muxWithMetrics.Handle("/metrics/", promhttp.Handler())
mux.Handle("/metrics", promhttp.Handler())

config, err := GetBaseConfig()
if err != nil {
Expand All @@ -103,7 +99,7 @@ func Serve(ctx context.Context, mux *http.ServeMux) {
BaseContext: func(_ net.Listener) context.Context { return ctx },
ReadTimeout: time.Second,
WriteTimeout: 10 * time.Second,
Handler: muxWithMetrics,
Handler: otelhttp.NewHandler(mux, "http"),
}

err = srv.ListenAndServe()
Expand Down
8 changes: 7 additions & 1 deletion services/s-web-portfolio/job.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ in
lib.mkServiceJob {
upstream."s-portfolio-stats-grpc".localBindPort = 9083;
name = "s-web-portfolio";
version = "3489df4";
version = "3b4d4ca";
cpu = 80;
memMb = 200;
ports.http = 8080;
httpTags = [
"traefik.enable=true"
"traefik.consulcatalog.connect=true"
"traefik.http.routers.\${NOMAD_GROUP_NAME}.tls=true"
"traefik.http.routers.\${NOMAD_GROUP_NAME}.entrypoints=web, websecure"
];
}
19 changes: 9 additions & 10 deletions services/s-web-portfolio/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
s_portfolio_stats "github.com/cottand/selfhosted/services/lib/proto/s-portfolio-stats"
"github.com/monzo/terrors"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"log"
Expand Down Expand Up @@ -41,16 +40,16 @@ func main() {
defer conn.Close()
stats := s_portfolio_stats.NewPortfolioStatsClient(conn)

mux := http.NewServeMux()

fs := http.FileServer(http.Dir(root + "/srv"))
fs = http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
fs.ServeHTTP(writer, request)
fsWithNoCache := http.FileServer(http.Dir(root + "/srv"))
fs := http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
fsWithNoCache.ServeHTTP(writer, request)
writer.Header().Set("Cache-Control", "max-age=600")
})
mux.Handle("/static/", otelhttp.WithRouteTag("/static/", fs))
mux.Handle("/assets/", otelhttp.WithRouteTag("/assets/", fs))
mux.Handle("/", otelhttp.WithRouteTag("/", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {

mux := http.NewServeMux()
mux.Handle("/static/", fs)
mux.Handle("/assets/", fs)
mux.Handle("/", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
originalPath := req.URL.Path
req.URL.Path = "/"
fs.ServeHTTP(rw, req)
Expand All @@ -64,7 +63,7 @@ func main() {
})
}
}()
})))
}))

bedrock.Serve(ctx, mux)
}

0 comments on commit b8e6fca

Please sign in to comment.