Skip to content

Commit bdf0552

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

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

pkg/ext-proc/backend/datastore.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,16 @@ func (ds *datastore) PodDelete(namespacedName types.NamespacedName) {
151151
}
152152

153153
func (ds *datastore) PodUpdateOrAddIfNotExist(pod *corev1.Pod) bool {
154+
pool, _ := ds.PoolGet()
154155
new := &PodMetrics{
155156
Pod: Pod{
156157
NamespacedName: types.NamespacedName{
157158
Name: pod.Name,
158159
Namespace: pod.Namespace,
159160
},
160-
Address: pod.Status.PodIP,
161+
Address: pod.Status.PodIP,
162+
ScrapePath: "/metrics",
163+
ScrapePort: pool.Spec.TargetPortNumber,
161164
},
162165
Metrics: Metrics{
163166
ActiveModels: make(map[string]int),

pkg/ext-proc/backend/types.go

Lines changed: 8 additions & 0 deletions
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 {
@@ -52,3 +56,7 @@ func (pm *PodMetrics) Clone() *PodMetrics {
5256
}
5357
return clone
5458
}
59+
60+
func (pm *PodMetrics) BuildScrapeEndpoint() string {
61+
return fmt.Sprintf("http://%s:%d%s", pm.Address, pm.ScrapePort, pm.ScrapePath)
62+
}

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

Lines changed: 1 addition & 1 deletion
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)

0 commit comments

Comments
 (0)