Skip to content

Commit 4e0f9d7

Browse files
committed
fix inference extension not correctly scrape pod metrics
Signed-off-by: Kuromesi <[email protected]>
1 parent cab2472 commit 4e0f9d7

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

pkg/ext-proc/backend/vllm/metrics.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (p *PodMetricsClientImpl) FetchMetrics(
4545

4646
// Currently the metrics endpoint is hard-coded, which works with vLLM.
4747
// TODO(https://github.com/kubernetes-sigs/gateway-api-inference-extension/issues/16): Consume this from InferencePool config.
48-
url := fmt.Sprintf("http://%s/metrics", existing.Address)
48+
url := existing.BuildScrapeEndpoint()
4949
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
5050
if err != nil {
5151
loggerDefault.Error(err, "Failed create HTTP request", "method", http.MethodGet, "url", url)

pkg/ext-proc/controller/pod_reconciler_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import (
2020
)
2121

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

2929
func TestUpdateDatastore_PodReconciler(t *testing.T) {
@@ -262,7 +262,7 @@ func TestUpdateDatastore_PodReconciler(t *testing.T) {
262262
func populateMap(pods ...*datastore.PodMetrics) *sync.Map {
263263
newMap := &sync.Map{}
264264
for _, pod := range pods {
265-
newMap.Store(pod.NamespacedName, &datastore.PodMetrics{Pod: datastore.Pod{NamespacedName: pod.NamespacedName, Address: pod.Address}})
265+
newMap.Store(pod.NamespacedName, &datastore.PodMetrics{Pod: datastore.Pod{NamespacedName: pod.NamespacedName, Address: pod.Address, ScrapePort: pod.ScrapePort, ScrapePath: pod.ScrapePath}})
266266
}
267267
return newMap
268268
}

pkg/ext-proc/datastore/datastore.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,16 @@ func (ds *datastore) PodDelete(namespacedName types.NamespacedName) {
166166
}
167167

168168
func (ds *datastore) PodUpdateOrAddIfNotExist(pod *corev1.Pod) bool {
169+
pool, _ := ds.PoolGet()
169170
new := &PodMetrics{
170171
Pod: Pod{
171172
NamespacedName: types.NamespacedName{
172173
Name: pod.Name,
173174
Namespace: pod.Namespace,
174175
},
175-
Address: pod.Status.PodIP,
176+
Address: pod.Status.PodIP,
177+
ScrapePath: "/metrics",
178+
ScrapePort: pool.Spec.TargetPortNumber,
176179
},
177180
Metrics: Metrics{
178181
ActiveModels: make(map[string]int),

pkg/ext-proc/datastore/types.go

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import (
1010
type Pod struct {
1111
NamespacedName types.NamespacedName
1212
Address string
13+
14+
// metrics scrape options
15+
ScrapePort int32
16+
ScrapePath string
1317
}
1418

1519
type Metrics struct {
@@ -41,6 +45,8 @@ func (pm *PodMetrics) Clone() *PodMetrics {
4145
Pod: Pod{
4246
NamespacedName: pm.NamespacedName,
4347
Address: pm.Address,
48+
ScrapePort: pm.ScrapePort,
49+
ScrapePath: pm.ScrapePath,
4450
},
4551
Metrics: Metrics{
4652
ActiveModels: cm,
@@ -52,3 +58,7 @@ func (pm *PodMetrics) Clone() *PodMetrics {
5258
}
5359
return clone
5460
}
61+
62+
func (pm *PodMetrics) BuildScrapeEndpoint() string {
63+
return fmt.Sprintf("http://%s:%d%s", pm.Address, pm.ScrapePort, pm.ScrapePath)
64+
}

0 commit comments

Comments
 (0)