Skip to content

Commit 0789e84

Browse files
committed
fix metric scrape port not updated when inference pool target port updated
Signed-off-by: Kuromesi <[email protected]>
1 parent 7ed54a4 commit 0789e84

File tree

6 files changed

+13
-22
lines changed

6 files changed

+13
-22
lines changed

pkg/epp/backend/fake.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type FakePodMetricsClient struct {
3131
Res map[types.NamespacedName]*datastore.PodMetrics
3232
}
3333

34-
func (f *FakePodMetricsClient) FetchMetrics(ctx context.Context, existing *datastore.PodMetrics) (*datastore.PodMetrics, error) {
34+
func (f *FakePodMetricsClient) FetchMetrics(ctx context.Context, existing *datastore.PodMetrics, port int32) (*datastore.PodMetrics, error) {
3535
if err, ok := f.Err[existing.NamespacedName]; ok {
3636
return nil, err
3737
}

pkg/epp/backend/provider.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type Provider struct {
4949
}
5050

5151
type PodMetricsClient interface {
52-
FetchMetrics(ctx context.Context, existing *datastore.PodMetrics) (*datastore.PodMetrics, error)
52+
FetchMetrics(ctx context.Context, existing *datastore.PodMetrics, port int32) (*datastore.PodMetrics, error)
5353
}
5454

5555
func (p *Provider) Init(ctx context.Context, refreshMetricsInterval, refreshPrometheusMetricsInterval time.Duration) error {
@@ -121,7 +121,8 @@ func (p *Provider) refreshMetricsOnce(logger logr.Logger) error {
121121
wg.Add(1)
122122
go func() {
123123
defer wg.Done()
124-
updated, err := p.pmc.FetchMetrics(ctx, existing)
124+
pool, _ := p.datastore.PoolGet()
125+
updated, err := p.pmc.FetchMetrics(ctx, existing, pool.Spec.TargetPortNumber)
125126
if err != nil {
126127
errCh <- fmt.Errorf("failed to parse metrics from %s: %v", existing.NamespacedName, err)
127128
return

pkg/epp/backend/vllm/metrics.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ type PodMetricsClientImpl struct{}
5555
func (p *PodMetricsClientImpl) FetchMetrics(
5656
ctx context.Context,
5757
existing *datastore.PodMetrics,
58+
port int32,
5859
) (*datastore.PodMetrics, error) {
5960
logger := log.FromContext(ctx)
6061
loggerDefault := logger.V(logutil.DEFAULT)
6162

6263
// Currently the metrics endpoint is hard-coded, which works with vLLM.
6364
// TODO(https://github.com/kubernetes-sigs/gateway-api-inference-extension/issues/16): Consume this from InferencePool config.
64-
url := existing.BuildScrapeEndpoint()
65+
url := existing.Address + ":" + strconv.Itoa(int(port))
66+
6567
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
6668
if err != nil {
6769
loggerDefault.Error(err, "Failed create HTTP request", "method", http.MethodGet, "url", url)

pkg/epp/controller/pod_reconciler_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ import (
3535
)
3636

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

4444
func TestPodReconciler(t *testing.T) {

pkg/epp/datastore/datastore.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,16 +265,13 @@ func (ds *datastore) PodDelete(namespacedName types.NamespacedName) {
265265
}
266266

267267
func (ds *datastore) PodUpdateOrAddIfNotExist(pod *corev1.Pod) bool {
268-
pool, _ := ds.PoolGet()
269268
new := &PodMetrics{
270269
Pod: Pod{
271270
NamespacedName: types.NamespacedName{
272271
Name: pod.Name,
273272
Namespace: pod.Namespace,
274273
},
275-
Address: pod.Status.PodIP,
276-
ScrapePath: "/metrics",
277-
ScrapePort: pool.Spec.TargetPortNumber,
274+
Address: pod.Status.PodIP,
278275
},
279276
Metrics: Metrics{
280277
ActiveModels: make(map[string]int),

pkg/epp/datastore/types.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ import (
2626
type Pod struct {
2727
NamespacedName types.NamespacedName
2828
Address string
29-
30-
// metrics scrape options
31-
ScrapePort int32
32-
ScrapePath string
3329
}
3430

3531
type Metrics struct {
@@ -61,11 +57,10 @@ func (pm *PodMetrics) Clone() *PodMetrics {
6157
Pod: Pod{
6258
NamespacedName: pm.NamespacedName,
6359
Address: pm.Address,
64-
ScrapePort: pm.ScrapePort,
65-
ScrapePath: pm.ScrapePath,
6660
},
6761
Metrics: Metrics{
6862
ActiveModels: cm,
63+
MaxActiveModels: pm.MaxActiveModels,
6964
RunningQueueSize: pm.RunningQueueSize,
7065
WaitingQueueSize: pm.WaitingQueueSize,
7166
KVCacheUsagePercent: pm.KVCacheUsagePercent,
@@ -74,7 +69,3 @@ func (pm *PodMetrics) Clone() *PodMetrics {
7469
}
7570
return clone
7671
}
77-
78-
func (pm *PodMetrics) BuildScrapeEndpoint() string {
79-
return fmt.Sprintf("http://%s:%d%s", pm.Address, pm.ScrapePort, pm.ScrapePath)
80-
}

0 commit comments

Comments
 (0)