worker: actually track error metrics on worker handle error (#39978)

This commit is contained in:
Noah S-C 2022-08-04 14:21:45 -07:00 committed by GitHub
parent 1bc8fedeb8
commit 5b3c5a9697
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

View File

@ -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))

View File

@ -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: