From feefa815b3f141878abf5f1bf79f470ad4031f08 Mon Sep 17 00:00:00 2001 From: Tolya Korniltsev Date: Mon, 22 Jul 2024 09:59:10 +0200 Subject: [PATCH] fix: readiness check for ingesters and frontend (#3435) --- Makefile | 9 +++------ cmd/pyroscope/frontend.Dockerfile | 2 +- pkg/phlare/modules.go | 2 ++ pkg/phlare/phlare.go | 18 +++++++++++++++++- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 64ead09beb..06daf99aa9 100644 --- a/Makefile +++ b/Makefile @@ -77,13 +77,10 @@ build: frontend/build go/bin ## Do a production build (requiring the frontend bu build-dev: ## Do a dev build (without requiring the frontend) $(MAKE) EMBEDASSETS="" go/bin -.PHONY: frontend/build -frontend/build: frontend/deps ## Do a production build for the frontend - yarn build -.PHONY: frontend/deps -frontend/deps: - yarn --frozen-lockfile +.PHONY: frontend/build +frontend/build: + docker build -f cmd/pyroscope/frontend.Dockerfile --output=public/build . .PHONY: release release/prereq: $(BIN)/goreleaser ## Ensure release pre requesites are met diff --git a/cmd/pyroscope/frontend.Dockerfile b/cmd/pyroscope/frontend.Dockerfile index d516e956d1..fffdffbe7e 100644 --- a/cmd/pyroscope/frontend.Dockerfile +++ b/cmd/pyroscope/frontend.Dockerfile @@ -1,4 +1,4 @@ -FROM node:18 as builder +FROM node:18 AS builder RUN apt-get update && apt-get install -y libpango1.0-dev libcairo2-dev WORKDIR /pyroscope COPY yarn.lock package.json tsconfig.json ./ diff --git a/pkg/phlare/modules.go b/pkg/phlare/modules.go index 5a5629978c..b8cd26563b 100644 --- a/pkg/phlare/modules.go +++ b/pkg/phlare/modules.go @@ -109,6 +109,7 @@ func (f *Phlare) initQueryFrontend() (services.Service, error) { f.API.RegisterPyroscopeHandlers(frontendSvc) f.API.RegisterQueryFrontend(frontendSvc) f.API.RegisterQuerier(frontendSvc) + f.frontend = frontendSvc return frontendSvc, nil } @@ -408,6 +409,7 @@ func (f *Phlare) initIngester() (_ services.Service, err error) { } f.API.RegisterIngester(svc) + f.ingester = svc return svc, nil } diff --git a/pkg/phlare/phlare.go b/pkg/phlare/phlare.go index ca12ce448b..df60bbd64b 100644 --- a/pkg/phlare/phlare.go +++ b/pkg/phlare/phlare.go @@ -239,7 +239,9 @@ type Phlare struct { grpcGatewayMux *grpcgw.ServeMux - auth connect.Option + auth connect.Option + ingester *ingester.Ingester + frontend *frontend.Frontend } func New(cfg Config) (*Phlare, error) { @@ -502,6 +504,20 @@ func (f *Phlare) readyHandler(sm *services.Manager) http.HandlerFunc { return } + if f.ingester != nil { + if err := f.ingester.CheckReady(r.Context()); err != nil { + http.Error(w, "Ingester not ready: "+err.Error(), http.StatusServiceUnavailable) + return + } + } + + if f.frontend != nil { + if err := f.frontend.CheckReady(r.Context()); err != nil { + http.Error(w, "Query Frontend not ready: "+err.Error(), http.StatusServiceUnavailable) + return + } + } + util.WriteTextResponse(w, "ready") } }