Repository: prometheus/prometheus
File: promql/engine.go (Go)

Code before:

		ev.logger.Error("runtime panic during query evaluation", "expr", expr.String(), "err", e, "stacktrace", string(buf))
		*errp = fmt.Errorf("unexpected error: %w", err)
	case errWithWarnings:
		*errp = err.err
		ws.Merge(err.warnings)
	case error:
		*errp = err
	default:
		*errp = fmt.Errorf("%v", err)
	}
}

func (ev *evaluator) Eval(ctx context.Context, expr parser.Expr) (v parser.Value, ws annotations.Annotations, err error) {
	defer ev.recover(expr, &ws, &err)

	v, ws = ev.eval(ctx, expr)
	if ev.enableDelayedNameRemoval {
		ev.cleanupMetricLabels(v)
	}
	return v, ws, nil
}

// EvalSeriesHelper stores extra information about a series.
type EvalSeriesHelper struct {
	// Ordinal number of join signature, used to map left-hand to right-hand in binary operations.
	sigOrdinal int
}

// EvalNodeHelper stores extra information and caches for evaluating a single node across steps.
type EvalNodeHelper struct {
	// Evaluation timestamp.
	Ts int64
	// Vector that can be used for output.
	Out Vector

	// Caches.
	// funcHistogramQuantile and funcHistogramFraction for classic histograms.
	signatureToMetricWithBuckets map[string]*metricWithBuckets
	nativeHistogramSamples       []Sample

	lb           *labels.Builder
	lblBuf       []byte
	lblResultBuf []byte

	// For binary vector matching.
	rightSigs    map[int]Sample
	matchedSigs  map[int]map[uint64]struct{}
	resultMetric map[string]labels.Labels
	numSigs      int


Review comment (suggestion):
nit: took me  a little while to decipher what it meant, maybe an example makes it easier.

```suggestion
	// Ordinal number of join signature, used to map left-hand to right-hand in
	// binary operations. For example given the following series, if
	// the join signature is job, instance then:
	// metric{job="a", instance="1", other="x"} -> sigOrdinal 0
	// metric{job="a", instance="1", other="y"} -> sigOrdinal 0
	// metric{job="a", instance="2", other="x"} -> sigOrdinal 1
```

Code after:

		ev.logger.Error("runtime panic during query evaluation", "expr", expr.String(), "err", e, "stacktrace", string(buf))
		*errp = fmt.Errorf("unexpected error: %w", err)
	case errWithWarnings:
		*errp = err.err
		ws.Merge(err.warnings)
	case error:
		*errp = err
	default:
		*errp = fmt.Errorf("%v", err)
	}
}

func (ev *evaluator) Eval(ctx context.Context, expr parser.Expr) (v parser.Value, ws annotations.Annotations, err error) {
	defer ev.recover(expr, &ws, &err)

	v, ws = ev.eval(ctx, expr)
	if ev.enableDelayedNameRemoval {
		ev.cleanupMetricLabels(v)
	}
	return v, ws, nil
}

// EvalSeriesHelper stores extra information about a series.
type EvalSeriesHelper struct {
	// Ordinal number of join signature, used to map left-hand to right-hand in
	// binary operations. For example given the following series, if
	// the join signature is job, instance then:
	// metric{job="a", instance="1", other="x"} -> sigOrdinal 0
	// metric{job="a", instance="1", other="y"} -> sigOrdinal 0
	// metric{job="a", instance="2", other="x"} -> sigOrdinal 1
	sigOrdinal int
}

// EvalNodeHelper stores extra information and caches for evaluating a single node across steps.
type EvalNodeHelper struct {
	// Evaluation timestamp.
	Ts int64
	// Vector that can be used for output.
	Out Vector

	// Caches.
	// funcHistogramQuantile and funcHistogramFraction for classic histograms.
	signatureToMetricWithBuckets map[string]*metricWithBuckets
	nativeHistogramSamples       []Sample

	lb           *labels.Builder
	lblBuf       []byte
	lblResultBuf []byte

	// For binary vector matching.