Repository: vllm-project/aibrix
File: pkg/cache/cache_trace.go (Go)

Code before:
	"time"

	"github.com/vllm-project/aibrix/pkg/metrics"
	"github.com/vllm-project/aibrix/pkg/types"
	"github.com/vllm-project/aibrix/pkg/utils"
	"k8s.io/klog/v2"
)

const (
	expireWriteRequestTraceIntervalInMins = 10
)

func (c *Store) getRequestTrace(modelName string) *RequestTrace {
	trace := NewRequestTrace(time.Now().UnixNano())
	newer, loaded := c.requestTrace.LoadOrStore(modelName, trace)
	if loaded {
		trace.Recycle()
	} else {
		atomic.AddInt32(&c.numRequestsTraces, 1)
	}
	return newer
}

func (c *Store) addPodStats(ctx *types.RoutingContext) {
	if !ctx.HasRouted() {
		klog.Warning("request has not been routed, please route request first")
		return
	}
	pod := ctx.TargetPod()

	metaPod, ok := c.metaPods.Load(pod.Name)
	if !ok {
		klog.Warningf("can't find routing pod: %s", pod.Name)
		return
	}
	requests := atomic.AddInt32(&metaPod.runningRequests, 1)
	if err := c.updatePodRecord(metaPod, ctx.Model, metrics.RealtimeNumRequestsRunning, metrics.PodMetricScope, &metrics.SimpleMetricValue{Value: float64(requests)}); err != nil {
		klog.Warningf("can't update realtime metric: %s", metrics.RealtimeNumRequestsRunning)
	}
}

func (c *Store) donePodStats(ctx *types.RoutingContext) {
	if !ctx.HasRouted() {
		klog.Warning("request has not been routed, please route request first")
		return
	}
	pod := ctx.TargetPod()

	// Now that pendingLoadProvider must be set.
	metaPod, ok := c.metaPods.Load(pod.Name)
	if !ok {

Review comment (suggestion):
For the log messages, you can add the requestID (add to routing context if not present) and pod name. Without these two fields, log message is not useful.

Comment applies to all log messages in this function.

Code after:
	"time"

	"github.com/vllm-project/aibrix/pkg/metrics"
	"github.com/vllm-project/aibrix/pkg/types"
	"github.com/vllm-project/aibrix/pkg/utils"
	"k8s.io/klog/v2"
)

const (
	expireWriteRequestTraceIntervalInMins = 10
)

func (c *Store) getRequestTrace(modelName string) *RequestTrace {
	trace := NewRequestTrace(time.Now().UnixNano())
	newer, loaded := c.requestTrace.LoadOrStore(modelName, trace)
	if loaded {
		trace.Recycle()
	} else {
		atomic.AddInt32(&c.numRequestsTraces, 1)
	}
	return newer
}

func (c *Store) addPodStats(ctx *types.RoutingContext, requestID string) {
	if !ctx.HasRouted() {
		klog.Warningf("request has not been routed, please route request first, requestID: %s", requestID)
		return
	}
	pod := ctx.TargetPod()

	metaPod, ok := c.metaPods.Load(pod.Name)
	if !ok {
		klog.Warningf("can't find routing pod: %s, requestID: %s", pod.Name, requestID)
		return
	}
	requests := atomic.AddInt32(&metaPod.runningRequests, 1)
	if err := c.updatePodRecord(metaPod, ctx.Model, metrics.RealtimeNumRequestsRunning, metrics.PodMetricScope, &metrics.SimpleMetricValue{Value: float64(requests)}); err != nil {
		klog.Warningf("can't update realtime metric: %s, pod: %s, requestID: %s", metrics.RealtimeNumRequestsRunning, pod.Name, requestID)
	}
}

func (c *Store) donePodStats(ctx *types.RoutingContext, requestID string) {
	if !ctx.HasRouted() {
		klog.Warningf("request has not been routed, please route request first, requestID: %s", requestID)
		return
	}
	pod := ctx.TargetPod()

	// Now that pendingLoadProvider must be set.
	metaPod, ok := c.metaPods.Load(pod.Name)
	if !ok {