From 5b3c5a9697b9e058516a9d8eeae9239b330dcc88 Mon Sep 17 00:00:00 2001 From: Noah S-C Date: Thu, 4 Aug 2022 14:21:45 -0700 Subject: [PATCH] worker: actually track error metrics on worker handle error (#39978) --- internal/workerutil/worker.go | 13 ++++++++++--- sg.config.yaml | 8 ++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/internal/workerutil/worker.go b/internal/workerutil/worker.go index 87cb362452d..4fca1dcb28e 100644 --- a/internal/workerutil/worker.go +++ b/internal/workerutil/worker.go @@ -372,8 +372,15 @@ func (w *Worker) dequeueAndHandle() (dequeued bool, err error) { // handle processes the given record. This method returns an error only if there is an issue updating // the record to a terminal state - no handler errors will bubble up. func (w *Worker) handle(ctx, workerContext context.Context, record Record) (err error) { - ctx, handleLog, endOperation := w.options.Metrics.operations.handle.With(ctx, &err, observation.Args{}) - defer endOperation(1, observation.Args{}) + var handleErr error + ctx, handleLog, endOperation := w.options.Metrics.operations.handle.With(ctx, &handleErr, observation.Args{}) + defer func() { + // prioritize handleErr in `operations.handle.With` without bubbling handleErr up if non-nil + if handleErr == nil && err != nil { + handleErr = err + } + endOperation(1, observation.Args{}) + }() // If a maximum runtime is configured, set a deadline on the handle context. if w.options.MaximumRuntimePerJob > 0 { @@ -383,7 +390,7 @@ func (w *Worker) handle(ctx, workerContext context.Context, record Record) (err } // Open namespace for logger to avoid key collisions on fields - handleErr := w.handler.Handle(ctx, handleLog.With(log.Namespace("handle")), record) + handleErr = w.handler.Handle(ctx, handleLog.With(log.Namespace("handle")), record) if w.options.MaximumRuntimePerJob > 0 && errors.Is(handleErr, context.DeadlineExceeded) { handleErr = errors.Wrap(handleErr, fmt.Sprintf("job exceeded maximum execution time of %s", w.options.MaximumRuntimePerJob)) diff --git a/sg.config.yaml b/sg.config.yaml index 56151ff76e2..2f05badb272 100644 --- a/sg.config.yaml +++ b/sg.config.yaml @@ -432,13 +432,13 @@ commands: cmd: env PATH="${PWD}/.bin:$PATH" .bin/zoekt-webserver -index "$HOME/.sourcegraph/zoekt/index-1" -pprof -rpc -listen "127.0.0.1:3071" codeintel-worker: - cmd: .bin/precise-code-intel-worker + cmd: .bin/codeintel-worker install: | if [ -n "$DELVE" ]; then export GCFLAGS='all=-N -l' fi - go build -gcflags="$GCFLAGS" -o .bin/precise-code-intel-worker github.com/sourcegraph/sourcegraph/enterprise/cmd/precise-code-intel-worker - checkBinary: .bin/precise-code-intel-worker + go build -gcflags="$GCFLAGS" -o .bin/codeintel-worker github.com/sourcegraph/sourcegraph/enterprise/cmd/precise-code-intel-worker + checkBinary: .bin/codeintel-worker watch: - lib - internal @@ -573,7 +573,7 @@ commands: install: | mkdir -p "${GRAFANA_DISK}" mkdir -p "$(dirname ${GRAFANA_LOG_FILE})" - + export CACHE=true docker inspect $CONTAINER >/dev/null 2>&1 && docker rm -f $CONTAINER ./docker-images/grafana/build.sh env: