Skip to content

Commit cc98b92

Browse files
committed
partially fix ut
1 parent dd82de1 commit cc98b92

File tree

12 files changed

+46
-12
lines changed

12 files changed

+46
-12
lines changed

cmd/epp/runner/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ var (
148148
"The configuration specified as text, in lieu of a file")
149149

150150
modelServerMetricsPort = flag.Int("model-server-metrics-port", 0, "Port to scrape metrics from pods. "+
151-
"Default value will be set to InferencePool.Spec.TargetPortNumber if not set.")
151+
"Default value will be set to InferencePool.Spec.TargetPorts if not set.")
152152
modelServerMetricsPath = flag.String("model-server-metrics-path", "/metrics", "Path to scrape metrics from pods")
153153
modelServerMetricsScheme = flag.String("model-server-metrics-scheme", "http", "Scheme to scrape metrics from pods")
154154
modelServerMetricsHttpsInsecureSkipVerify = flag.Bool("model-server-metrics-https-insecure-skip-verify", true, "When using 'https' scheme for 'model-server-metrics-scheme', configure 'InsecureSkipVerify' (default to true)")

pkg/epp/backend/metrics/pod_metrics.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ func (pm *podMetrics) refreshMetrics() error {
116116
}
117117
ctx, cancel := context.WithTimeout(context.Background(), fetchMetricsTimeout)
118118
defer cancel()
119-
updated, err := pm.pmc.FetchMetrics(ctx, pm.GetPod(), pm.GetMetrics(), pool.Spec.TargetPortNumber)
119+
if len(pool.Spec.TargetPorts) != 1 {
120+
return fmt.Errorf("expected 1 target port, got %d", len(pool.Spec.TargetPorts))
121+
}
122+
updated, err := pm.pmc.FetchMetrics(ctx, pm.GetPod(), pm.GetMetrics(), pool.Spec.TargetPorts[0].PortNumber)
120123
if err != nil {
121124
pm.logger.V(logutil.TRACE).Info("Failed to refreshed metrics:", "err", err)
122125
}

pkg/epp/backend/metrics/pod_metrics_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func TestMetricsRefresh(t *testing.T) {
8888
type fakeDataStore struct{}
8989

9090
func (f *fakeDataStore) PoolGet() (*v1.InferencePool, error) {
91-
return &v1.InferencePool{Spec: v1.InferencePoolSpec{TargetPortNumber: 8000}}, nil
91+
return &v1.InferencePool{Spec: v1.InferencePoolSpec{TargetPorts: []v1.Port{{PortNumber: 8000}}}}, nil
9292
}
9393

9494
func (f *fakeDataStore) PodList(func(PodMetrics) bool) []PodMetrics {

pkg/epp/controller/inferencepool_reconciler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func TestInferencePoolReconciler(t *testing.T) {
8080
pool1 := utiltest.MakeInferencePool("pool1").
8181
Namespace("pool1-ns").
8282
Selector(selector_v1).
83-
TargetPortNumber(8080).ObjRef()
83+
TargetPorts(8080).ObjRef()
8484
pool1.SetGroupVersionKind(gvk)
8585
pool2 := utiltest.MakeInferencePool("pool2").Namespace("pool2-ns").ObjRef()
8686
pool2.SetGroupVersionKind(gvk)
@@ -145,7 +145,7 @@ func TestInferencePoolReconciler(t *testing.T) {
145145
if err := fakeClient.Get(ctx, req.NamespacedName, newPool1); err != nil {
146146
t.Errorf("Unexpected pool get error: %v", err)
147147
}
148-
newPool1.Spec.TargetPortNumber = 9090
148+
newPool1.Spec.TargetPorts = []v1.Port{{PortNumber: 9090}}
149149
if err := fakeClient.Update(ctx, newPool1, &client.UpdateOptions{}); err != nil {
150150
t.Errorf("Unexpected pool update error: %v", err)
151151
}

pkg/epp/controller/pod_reconciler_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ func TestPodReconciler(t *testing.T) {
6161
existingPods: []*corev1.Pod{basePod1, basePod2},
6262
pool: &v1.InferencePool{
6363
Spec: v1.InferencePoolSpec{
64+
TargetPorts: []v1.Port{{PortNumber: int32(8000)}},
65+
Selector: map[v1.LabelKey]v1.LabelValue{
66+
"some-key": "some-val",
6467
TargetPortNumber: int32(8000),
6568
Selector: v1.LabelSelector{
6669
MatchLabels: map[v1.LabelKey]v1.LabelValue{
@@ -79,6 +82,9 @@ func TestPodReconciler(t *testing.T) {
7982
existingPods: []*corev1.Pod{basePod1, basePod2},
8083
pool: &v1.InferencePool{
8184
Spec: v1.InferencePoolSpec{
85+
TargetPorts: []v1.Port{{PortNumber: int32(8000)}},
86+
Selector: map[v1.LabelKey]v1.LabelValue{
87+
"some-key": "some-val",
8288
TargetPortNumber: int32(8000),
8389
Selector: v1.LabelSelector{
8490
MatchLabels: map[v1.LabelKey]v1.LabelValue{
@@ -97,6 +103,9 @@ func TestPodReconciler(t *testing.T) {
97103
existingPods: []*corev1.Pod{basePod1, basePod2},
98104
pool: &v1.InferencePool{
99105
Spec: v1.InferencePoolSpec{
106+
TargetPorts: []v1.Port{{PortNumber: int32(8000)}},
107+
Selector: map[v1.LabelKey]v1.LabelValue{
108+
"some-key": "some-val",
100109
TargetPortNumber: int32(8000),
101110
Selector: v1.LabelSelector{
102111
MatchLabels: map[v1.LabelKey]v1.LabelValue{
@@ -116,6 +125,9 @@ func TestPodReconciler(t *testing.T) {
116125
existingPods: []*corev1.Pod{basePod1, basePod2},
117126
pool: &v1.InferencePool{
118127
Spec: v1.InferencePoolSpec{
128+
TargetPorts: []v1.Port{{PortNumber: int32(8000)}},
129+
Selector: map[v1.LabelKey]v1.LabelValue{
130+
"some-key": "some-val",
119131
TargetPortNumber: int32(8000),
120132
Selector: v1.LabelSelector{
121133
MatchLabels: map[v1.LabelKey]v1.LabelValue{
@@ -132,6 +144,9 @@ func TestPodReconciler(t *testing.T) {
132144
existingPods: []*corev1.Pod{basePod1, basePod2},
133145
pool: &v1.InferencePool{
134146
Spec: v1.InferencePoolSpec{
147+
TargetPorts: []v1.Port{{PortNumber: int32(8000)}},
148+
Selector: map[v1.LabelKey]v1.LabelValue{
149+
"some-key": "some-val",
135150
TargetPortNumber: int32(8000),
136151
Selector: v1.LabelSelector{
137152
MatchLabels: map[v1.LabelKey]v1.LabelValue{
@@ -149,6 +164,9 @@ func TestPodReconciler(t *testing.T) {
149164
existingPods: []*corev1.Pod{basePod1, basePod2},
150165
pool: &v1.InferencePool{
151166
Spec: v1.InferencePoolSpec{
167+
TargetPorts: []v1.Port{{PortNumber: int32(8000)}},
168+
Selector: map[v1.LabelKey]v1.LabelValue{
169+
"some-key": "some-val",
152170
TargetPortNumber: int32(8000),
153171
Selector: v1.LabelSelector{
154172
MatchLabels: map[v1.LabelKey]v1.LabelValue{
@@ -167,6 +185,9 @@ func TestPodReconciler(t *testing.T) {
167185
existingPods: []*corev1.Pod{basePod1, basePod2},
168186
pool: &v1.InferencePool{
169187
Spec: v1.InferencePoolSpec{
188+
TargetPorts: []v1.Port{{PortNumber: int32(8000)}},
189+
Selector: map[v1.LabelKey]v1.LabelValue{
190+
"some-key": "some-val",
170191
TargetPortNumber: int32(8000),
171192
Selector: v1.LabelSelector{
172193
MatchLabels: map[v1.LabelKey]v1.LabelValue{

pkg/epp/datastore/datastore_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ var (
245245
pod2NamespacedName = types.NamespacedName{Name: pod2.Name, Namespace: pod2.Namespace}
246246
inferencePool = &v1.InferencePool{
247247
Spec: v1.InferencePoolSpec{
248-
TargetPortNumber: 8000,
248+
TargetPorts: []v1.Port{{PortNumber: int32(8000)}},
249249
},
250250
}
251251
)

pkg/epp/handlers/request.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package handlers
1818

1919
import (
20+
"fmt"
2021
"strconv"
2122
"time"
2223

@@ -45,7 +46,10 @@ func (s *StreamingServer) HandleRequestHeaders(reqCtx *RequestContext, req *extP
4546
if err != nil {
4647
return err
4748
}
48-
reqCtx.TargetEndpoint = pod.Address + ":" + strconv.Itoa(int(pool.Spec.TargetPortNumber))
49+
if len(pool.Spec.TargetPorts) != 1 {
50+
return fmt.Errorf("expected 1 target port, got %d", len(pool.Spec.TargetPorts))
51+
}
52+
reqCtx.TargetEndpoint = pod.Address + ":" + strconv.Itoa(int(pool.Spec.TargetPorts[0].PortNumber))
4953
reqCtx.RequestSize = 0
5054
reqCtx.reqHeaderResp = s.generateRequestHeaderResponse(reqCtx)
5155
return nil

pkg/epp/metrics/collectors/inference_pool_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func TestMetricsCollected(t *testing.T) {
8080
Name: "test-pool",
8181
},
8282
Spec: v1.InferencePoolSpec{
83-
TargetPortNumber: 8000,
83+
TargetPorts: []v1.Port{{PortNumber: int32(8000)}},
8484
},
8585
}
8686
_ = ds.PoolSet(context.Background(), fakeClient, inferencePool)

pkg/epp/requestcontrol/director.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,10 @@ func (d *Director) prepareRequest(ctx context.Context, reqCtx *handlers.RequestC
240240
return reqCtx, err
241241
}
242242
targetPods := []*backend.Pod{}
243-
targetPort := int(pool.Spec.TargetPortNumber)
243+
if len(pool.Spec.TargetPorts) != 1 {
244+
return reqCtx, errutil.Error{Code: errutil.BadRequest, Msg: "targetPorts should have length 1"}
245+
}
246+
targetPort := int(pool.Spec.TargetPorts[0].PortNumber)
244247
targetEndpoints := []string{}
245248

246249
for _, pod := range result.ProfileResults[result.PrimaryProfileName].TargetPods {

pkg/epp/requestcontrol/director_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ func TestDirector_HandleRequest(t *testing.T) {
101101
pool := &v1.InferencePool{
102102
ObjectMeta: metav1.ObjectMeta{Name: "test-pool", Namespace: "default"},
103103
Spec: v1.InferencePoolSpec{
104+
TargetPorts: []v1.Port{{PortNumber: int32(8000)}},
105+
Selector: map[v1.LabelKey]v1.LabelValue{
106+
"app": "inference",
104107
TargetPortNumber: int32(8000),
105108
Selector: v1.LabelSelector{
106109
MatchLabels: map[v1.LabelKey]v1.LabelValue{

0 commit comments

Comments
 (0)