Skip to content

fix metric scrape port not updated when inference pool target port updated #417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/epp/backend/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type FakePodMetricsClient struct {
Res map[types.NamespacedName]*datastore.PodMetrics
}

func (f *FakePodMetricsClient) FetchMetrics(ctx context.Context, existing *datastore.PodMetrics) (*datastore.PodMetrics, error) {
func (f *FakePodMetricsClient) FetchMetrics(ctx context.Context, existing *datastore.PodMetrics, port int32) (*datastore.PodMetrics, error) {
if err, ok := f.Err[existing.NamespacedName]; ok {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/epp/backend/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type Provider struct {
}

type PodMetricsClient interface {
FetchMetrics(ctx context.Context, existing *datastore.PodMetrics) (*datastore.PodMetrics, error)
FetchMetrics(ctx context.Context, existing *datastore.PodMetrics, port int32) (*datastore.PodMetrics, error)
}

func (p *Provider) Init(ctx context.Context, refreshMetricsInterval, refreshPrometheusMetricsInterval time.Duration) error {
Expand Down Expand Up @@ -121,7 +121,8 @@ func (p *Provider) refreshMetricsOnce(logger logr.Logger) error {
wg.Add(1)
go func() {
defer wg.Done()
updated, err := p.pmc.FetchMetrics(ctx, existing)
pool, _ := p.datastore.PoolGet()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to check for the error here and skip updating if the pool wasn't set yet.

updated, err := p.pmc.FetchMetrics(ctx, existing, pool.Spec.TargetPortNumber)
if err != nil {
errCh <- fmt.Errorf("failed to parse metrics from %s: %v", existing.NamespacedName, err)
return
Expand Down
4 changes: 3 additions & 1 deletion pkg/epp/backend/vllm/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ type PodMetricsClientImpl struct{}
func (p *PodMetricsClientImpl) FetchMetrics(
ctx context.Context,
existing *datastore.PodMetrics,
port int32,
) (*datastore.PodMetrics, error) {
logger := log.FromContext(ctx)
loggerDefault := logger.V(logutil.DEFAULT)

// Currently the metrics endpoint is hard-coded, which works with vLLM.
// TODO(https://github.com/kubernetes-sigs/gateway-api-inference-extension/issues/16): Consume this from InferencePool config.
url := existing.BuildScrapeEndpoint()
url := existing.Address + ":" + strconv.Itoa(int(port))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to set the scrape path, /metrics

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry my bad.


req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
loggerDefault.Error(err, "Failed create HTTP request", "method", http.MethodGet, "url", url)
Expand Down
8 changes: 4 additions & 4 deletions pkg/epp/controller/pod_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ import (
)

var (
basePod1 = &datastore.PodMetrics{Pod: datastore.Pod{NamespacedName: types.NamespacedName{Name: "pod1"}, Address: "address-1", ScrapePath: "/metrics", ScrapePort: 8000}}
basePod2 = &datastore.PodMetrics{Pod: datastore.Pod{NamespacedName: types.NamespacedName{Name: "pod2"}, Address: "address-2", ScrapePath: "/metrics", ScrapePort: 8000}}
basePod3 = &datastore.PodMetrics{Pod: datastore.Pod{NamespacedName: types.NamespacedName{Name: "pod3"}, Address: "address-3", ScrapePath: "/metrics", ScrapePort: 8000}}
basePod11 = &datastore.PodMetrics{Pod: datastore.Pod{NamespacedName: types.NamespacedName{Name: "pod1"}, Address: "address-11", ScrapePath: "/metrics", ScrapePort: 8000}}
basePod1 = &datastore.PodMetrics{Pod: datastore.Pod{NamespacedName: types.NamespacedName{Name: "pod1"}, Address: "address-1"}}
basePod2 = &datastore.PodMetrics{Pod: datastore.Pod{NamespacedName: types.NamespacedName{Name: "pod2"}, Address: "address-2"}}
basePod3 = &datastore.PodMetrics{Pod: datastore.Pod{NamespacedName: types.NamespacedName{Name: "pod3"}, Address: "address-3"}}
basePod11 = &datastore.PodMetrics{Pod: datastore.Pod{NamespacedName: types.NamespacedName{Name: "pod1"}, Address: "address-11"}}
)

func TestPodReconciler(t *testing.T) {
Expand Down
5 changes: 1 addition & 4 deletions pkg/epp/datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,13 @@ func (ds *datastore) PodDelete(namespacedName types.NamespacedName) {
}

func (ds *datastore) PodUpdateOrAddIfNotExist(pod *corev1.Pod) bool {
pool, _ := ds.PoolGet()
new := &PodMetrics{
Pod: Pod{
NamespacedName: types.NamespacedName{
Name: pod.Name,
Namespace: pod.Namespace,
},
Address: pod.Status.PodIP,
ScrapePath: "/metrics",
ScrapePort: pool.Spec.TargetPortNumber,
Address: pod.Status.PodIP,
},
Metrics: Metrics{
ActiveModels: make(map[string]int),
Expand Down
11 changes: 1 addition & 10 deletions pkg/epp/datastore/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ import (
type Pod struct {
NamespacedName types.NamespacedName
Address string

// metrics scrape options
ScrapePort int32
ScrapePath string
}

type Metrics struct {
Expand Down Expand Up @@ -61,11 +57,10 @@ func (pm *PodMetrics) Clone() *PodMetrics {
Pod: Pod{
NamespacedName: pm.NamespacedName,
Address: pm.Address,
ScrapePort: pm.ScrapePort,
ScrapePath: pm.ScrapePath,
},
Metrics: Metrics{
ActiveModels: cm,
MaxActiveModels: pm.MaxActiveModels,
RunningQueueSize: pm.RunningQueueSize,
WaitingQueueSize: pm.WaitingQueueSize,
KVCacheUsagePercent: pm.KVCacheUsagePercent,
Expand All @@ -74,7 +69,3 @@ func (pm *PodMetrics) Clone() *PodMetrics {
}
return clone
}

func (pm *PodMetrics) BuildScrapeEndpoint() string {
return fmt.Sprintf("http://%s:%d%s", pm.Address, pm.ScrapePort, pm.ScrapePath)
}