Skip to content

Commit 0f67df5

Browse files
authored
fix inference extension not correctly scrape pod metrics (#366)
Signed-off-by: Kuromesi <[email protected]>
1 parent 435a40d commit 0f67df5

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
@@ -61,7 +61,7 @@ func (p *PodMetricsClientImpl) FetchMetrics(
6161

6262
// Currently the metrics endpoint is hard-coded, which works with vLLM.
6363
// TODO(https://github.com/kubernetes-sigs/gateway-api-inference-extension/issues/16): Consume this from InferencePool config.
64-
url := fmt.Sprintf("http://%s/metrics", existing.Address)
64+
url := existing.BuildScrapeEndpoint()
6565
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
6666
if err != nil {
6767
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
@@ -36,10 +36,10 @@ import (
3636
)
3737

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

4545
func TestUpdateDatastore_PodReconciler(t *testing.T) {
@@ -278,7 +278,7 @@ func TestUpdateDatastore_PodReconciler(t *testing.T) {
278278
func populateMap(pods ...*datastore.PodMetrics) *sync.Map {
279279
newMap := &sync.Map{}
280280
for _, pod := range pods {
281-
newMap.Store(pod.NamespacedName, &datastore.PodMetrics{Pod: datastore.Pod{NamespacedName: pod.NamespacedName, Address: pod.Address}})
281+
newMap.Store(pod.NamespacedName, &datastore.PodMetrics{Pod: datastore.Pod{NamespacedName: pod.NamespacedName, Address: pod.Address, ScrapePort: pod.ScrapePort, ScrapePath: pod.ScrapePath}})
282282
}
283283
return newMap
284284
}

pkg/ext-proc/datastore/datastore.go

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

184184
func (ds *datastore) PodUpdateOrAddIfNotExist(pod *corev1.Pod) bool {
185+
pool, _ := ds.PoolGet()
185186
new := &PodMetrics{
186187
Pod: Pod{
187188
NamespacedName: types.NamespacedName{
188189
Name: pod.Name,
189190
Namespace: pod.Namespace,
190191
},
191-
Address: pod.Status.PodIP,
192+
Address: pod.Status.PodIP,
193+
ScrapePath: "/metrics",
194+
ScrapePort: pool.Spec.TargetPortNumber,
192195
},
193196
Metrics: Metrics{
194197
ActiveModels: make(map[string]int),

pkg/ext-proc/datastore/types.go

+10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ import (
2626
type Pod struct {
2727
NamespacedName types.NamespacedName
2828
Address string
29+
30+
// metrics scrape options
31+
ScrapePort int32
32+
ScrapePath string
2933
}
3034

3135
type Metrics struct {
@@ -57,6 +61,8 @@ func (pm *PodMetrics) Clone() *PodMetrics {
5761
Pod: Pod{
5862
NamespacedName: pm.NamespacedName,
5963
Address: pm.Address,
64+
ScrapePort: pm.ScrapePort,
65+
ScrapePath: pm.ScrapePath,
6066
},
6167
Metrics: Metrics{
6268
ActiveModels: cm,
@@ -68,3 +74,7 @@ func (pm *PodMetrics) Clone() *PodMetrics {
6874
}
6975
return clone
7076
}
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)