generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathhermetic_test.go
649 lines (601 loc) · 20.3 KB
/
hermetic_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
/*
Copyright 2025 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package test contains e2e tests for the ext proc while faking the backend pods.
package integration
import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"io"
"net"
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
"testing"
"time"
configPb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
extProcPb "github.com/envoyproxy/go-control-plane/envoy/service/ext_proc/v3"
envoyTypePb "github.com/envoyproxy/go-control-plane/envoy/type/v3"
"github.com/google/go-cmp/cmp"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/protobuf/testing/protocmp"
"google.golang.org/protobuf/types/known/structpb"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
k8syaml "k8s.io/apimachinery/pkg/util/yaml"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/component-base/metrics/legacyregistry"
metricsutils "k8s.io/component-base/metrics/testutil"
ctrl "sigs.k8s.io/controller-runtime"
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/gateway-api-inference-extension/api/v1alpha2"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/datastore"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metrics"
runserver "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/server"
extprocutils "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/test"
logutil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/logging"
utiltesting "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/testing"
"sigs.k8s.io/yaml"
)
const (
port = runserver.DefaultGrpcPort
metricsPort = 8888
)
var (
serverRunner *runserver.ExtProcServerRunner
k8sClient k8sclient.Client
testEnv *envtest.Environment
scheme = runtime.NewScheme()
logger = logutil.NewTestLogger().V(logutil.VERBOSE)
)
func TestKubeInferenceModelRequest(t *testing.T) {
tests := []struct {
name string
req *extProcPb.ProcessingRequest
pods []*datastore.PodMetrics
wantHeaders []*configPb.HeaderValueOption
wantMetadata *structpb.Struct
wantBody []byte
wantMetrics string
wantErr bool
immediateResponse *extProcPb.ImmediateResponse
}{
{
name: "select lower queue and kv cache, no active lora",
req: extprocutils.GenerateRequest(logger, "test1", "my-model"),
// pod-1 will be picked because it has relatively low queue size and low KV cache.
pods: []*datastore.PodMetrics{
extprocutils.FakePodMetrics(0, datastore.Metrics{
WaitingQueueSize: 3,
KVCacheUsagePercent: 0.2,
}),
extprocutils.FakePodMetrics(1, datastore.Metrics{
WaitingQueueSize: 0,
KVCacheUsagePercent: 0.1,
}),
extprocutils.FakePodMetrics(2, datastore.Metrics{
WaitingQueueSize: 10,
KVCacheUsagePercent: 0.2,
}),
},
wantHeaders: []*configPb.HeaderValueOption{
{
Header: &configPb.HeaderValue{
Key: runserver.DefaultDestinationEndpointHintKey,
RawValue: []byte("192.168.1.2:8000"),
},
},
{
Header: &configPb.HeaderValue{
Key: "Content-Length",
RawValue: []byte("76"),
},
},
},
wantMetadata: makeMetadata("192.168.1.2:8000"),
wantBody: []byte("{\"max_tokens\":100,\"model\":\"my-model-12345\",\"prompt\":\"test1\",\"temperature\":0}"),
wantMetrics: `
# HELP inference_model_request_total [ALPHA] Counter of inference model requests broken out for each model and target model.
# TYPE inference_model_request_total counter
inference_model_request_total{model_name="my-model",target_model_name="my-model-12345"} 1
`,
wantErr: false,
},
{
name: "select active lora, low queue",
req: extprocutils.GenerateRequest(logger, "test2", "sql-lora"),
// pod-1 will be picked because it has relatively low queue size, with the requested
// model being active, and has low KV cache.
pods: []*datastore.PodMetrics{
extprocutils.FakePodMetrics(0, datastore.Metrics{
WaitingQueueSize: 0,
KVCacheUsagePercent: 0.2,
ActiveModels: map[string]int{
"foo": 1,
"bar": 1,
},
}),
extprocutils.FakePodMetrics(1, datastore.Metrics{
WaitingQueueSize: 0,
KVCacheUsagePercent: 0.1,
ActiveModels: map[string]int{
"foo": 1,
"sql-lora-1fdg2": 1,
},
}),
extprocutils.FakePodMetrics(2, datastore.Metrics{
WaitingQueueSize: 10,
KVCacheUsagePercent: 0.2,
ActiveModels: map[string]int{
"foo": 1,
},
}),
},
wantHeaders: []*configPb.HeaderValueOption{
{
Header: &configPb.HeaderValue{
Key: runserver.DefaultDestinationEndpointHintKey,
RawValue: []byte("192.168.1.2:8000"),
},
},
{
Header: &configPb.HeaderValue{
Key: "Content-Length",
RawValue: []byte("76"),
},
},
},
wantMetadata: makeMetadata("192.168.1.2:8000"),
wantBody: []byte("{\"max_tokens\":100,\"model\":\"sql-lora-1fdg2\",\"prompt\":\"test2\",\"temperature\":0}"),
wantMetrics: `
# HELP inference_model_request_total [ALPHA] Counter of inference model requests broken out for each model and target model.
# TYPE inference_model_request_total counter
inference_model_request_total{model_name="sql-lora",target_model_name="sql-lora-1fdg2"} 1
`,
wantErr: false,
},
{
name: "select no lora despite active model, avoid excessive queue size",
req: extprocutils.GenerateRequest(logger, "test3", "sql-lora"),
// pod-2 will be picked despite it NOT having the requested model being active
// as it's above the affinity for queue size. Also is critical, so we should
// still honor request despite all queues > 5
pods: []*datastore.PodMetrics{
extprocutils.FakePodMetrics(0, datastore.Metrics{
WaitingQueueSize: 10,
KVCacheUsagePercent: 0.2,
ActiveModels: map[string]int{
"foo": 1,
"bar": 1,
},
}),
extprocutils.FakePodMetrics(1, datastore.Metrics{
WaitingQueueSize: 50,
KVCacheUsagePercent: 0.1,
ActiveModels: map[string]int{
"foo": 1,
"sql-lora-1fdg2": 1,
},
}),
extprocutils.FakePodMetrics(2, datastore.Metrics{
WaitingQueueSize: 6,
KVCacheUsagePercent: 0.2,
ActiveModels: map[string]int{
"foo": 1,
},
}),
},
wantHeaders: []*configPb.HeaderValueOption{
{
Header: &configPb.HeaderValue{
Key: runserver.DefaultDestinationEndpointHintKey,
RawValue: []byte("192.168.1.3:8000"),
},
},
{
Header: &configPb.HeaderValue{
Key: "Content-Length",
RawValue: []byte("76"),
},
},
},
wantMetadata: makeMetadata("192.168.1.3:8000"),
wantBody: []byte("{\"max_tokens\":100,\"model\":\"sql-lora-1fdg2\",\"prompt\":\"test3\",\"temperature\":0}"),
wantMetrics: `
# HELP inference_model_request_total [ALPHA] Counter of inference model requests broken out for each model and target model.
# TYPE inference_model_request_total counter
inference_model_request_total{model_name="sql-lora",target_model_name="sql-lora-1fdg2"} 1
`,
wantErr: false,
},
{
name: "noncritical and all models past threshold, shed request",
req: extprocutils.GenerateRequest(logger, "test4", "sql-lora-sheddable"),
// no pods will be picked as all models are either above kv threshold,
// queue threshold, or both.
pods: []*datastore.PodMetrics{
extprocutils.FakePodMetrics(0, datastore.Metrics{
WaitingQueueSize: 6,
KVCacheUsagePercent: 0.2,
ActiveModels: map[string]int{
"foo": 1,
"bar": 1,
"sql-lora-1fdg3": 1,
},
}),
extprocutils.FakePodMetrics(1, datastore.Metrics{
WaitingQueueSize: 0,
KVCacheUsagePercent: 0.85,
ActiveModels: map[string]int{
"foo": 1,
"sql-lora-1fdg3": 1,
},
}),
extprocutils.FakePodMetrics(2, datastore.Metrics{
WaitingQueueSize: 10,
KVCacheUsagePercent: 0.9,
ActiveModels: map[string]int{
"foo": 1,
"sql-lora-1fdg3": 1,
},
}),
},
wantHeaders: []*configPb.HeaderValueOption{},
wantMetadata: &structpb.Struct{},
wantBody: []byte(""),
wantErr: false,
immediateResponse: &extProcPb.ImmediateResponse{
Status: &envoyTypePb.HttpStatus{
Code: envoyTypePb.StatusCode_TooManyRequests,
},
},
wantMetrics: "",
},
{
name: "noncritical, but one server has capacity, do not shed",
req: extprocutils.GenerateRequest(logger, "test5", "sql-lora-sheddable"),
// pod 0 will be picked as all other models are above threshold
pods: []*datastore.PodMetrics{
extprocutils.FakePodMetrics(0, datastore.Metrics{
WaitingQueueSize: 4,
KVCacheUsagePercent: 0.2,
ActiveModels: map[string]int{
"foo": 1,
"bar": 1,
"sql-lora-1fdg3": 1,
},
}),
extprocutils.FakePodMetrics(1, datastore.Metrics{
WaitingQueueSize: 0,
KVCacheUsagePercent: 0.85,
ActiveModels: map[string]int{
"foo": 1,
"sql-lora-1fdg3": 1,
},
}),
extprocutils.FakePodMetrics(2, datastore.Metrics{
WaitingQueueSize: 10,
KVCacheUsagePercent: 0.9,
ActiveModels: map[string]int{
"foo": 1,
"sql-lora-1fdg3": 1,
},
}),
},
wantHeaders: []*configPb.HeaderValueOption{
{
Header: &configPb.HeaderValue{
Key: runserver.DefaultDestinationEndpointHintKey,
RawValue: []byte("192.168.1.1:8000"),
},
},
{
Header: &configPb.HeaderValue{
Key: "Content-Length",
RawValue: []byte("76"),
},
},
},
wantMetadata: makeMetadata("192.168.1.1:8000"),
wantBody: []byte("{\"max_tokens\":100,\"model\":\"sql-lora-1fdg3\",\"prompt\":\"test5\",\"temperature\":0}"),
wantMetrics: `
# HELP inference_model_request_total [ALPHA] Counter of inference model requests broken out for each model and target model.
# TYPE inference_model_request_total counter
inference_model_request_total{model_name="sql-lora-sheddable",target_model_name="sql-lora-1fdg3"} 1
`,
wantErr: false,
},
}
// Set up global k8sclient and extproc server runner with test environment config
cleanup := BeforeSuit(t)
defer cleanup()
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
client, cleanup := setUpHermeticServer(t, test.pods)
t.Cleanup(cleanup)
want := &extProcPb.ProcessingResponse{
Response: &extProcPb.ProcessingResponse_RequestBody{
RequestBody: &extProcPb.BodyResponse{
Response: &extProcPb.CommonResponse{
HeaderMutation: &extProcPb.HeaderMutation{
SetHeaders: test.wantHeaders,
},
BodyMutation: &extProcPb.BodyMutation{
Mutation: &extProcPb.BodyMutation_Body{
Body: test.wantBody,
},
},
},
},
},
DynamicMetadata: test.wantMetadata,
}
res, err := sendRequest(t, client, test.req)
if err != nil && !test.wantErr {
t.Errorf("Unexpected error, got: %v, want error: %v", err, test.wantErr)
}
if test.immediateResponse != nil {
want = &extProcPb.ProcessingResponse{
Response: &extProcPb.ProcessingResponse_ImmediateResponse{
ImmediateResponse: test.immediateResponse,
},
}
}
if diff := cmp.Diff(want, res, protocmp.Transform()); diff != "" {
t.Errorf("Unexpected response, (-want +got): %v", diff)
}
if test.wantMetrics != "" {
if err := metricsutils.GatherAndCompare(legacyregistry.DefaultGatherer, strings.NewReader(test.wantMetrics), "inference_model_request_total"); err != nil {
t.Error(err)
}
}
legacyregistry.Reset()
})
}
}
func setUpHermeticServer(t *testing.T, podMetrics []*datastore.PodMetrics) (client extProcPb.ExternalProcessor_ProcessClient, cleanup func()) {
pms := make(map[types.NamespacedName]*datastore.PodMetrics)
for _, pm := range podMetrics {
pms[pm.NamespacedName] = pm
}
pmc := &backend.FakePodMetricsClient{Res: pms}
serverCtx, stopServer := context.WithCancel(context.Background())
// TODO: this should be consistent with the inference pool
podLabels := map[string]string{
"app": "vllm-llama2-7b-pool",
}
for _, pm := range podMetrics {
pod := utiltesting.MakePod(pm.NamespacedName.Name).
Namespace(pm.NamespacedName.Namespace).
ReadyCondition().
Labels(podLabels).
IP(pm.Address).
Complete().
ObjRef()
copy := pod.DeepCopy()
if err := k8sClient.Create(context.Background(), copy); err != nil {
logutil.Fatal(logger, err, "Failed to create pod", "pod", pm.NamespacedName)
}
// since no pod controllers deployed in fake environment, we manually update pod status
copy.Status = pod.Status
if err := k8sClient.Status().Update(context.Background(), copy); err != nil {
logutil.Fatal(logger, err, "Failed to update pod status", "pod", pm.NamespacedName)
}
}
serverRunner.Provider = backend.NewProvider(pmc, serverRunner.Datastore)
go func() {
if err := serverRunner.AsRunnable(logger.WithName("ext-proc")).Start(serverCtx); err != nil {
logutil.Fatal(logger, err, "Failed to start ext-proc server")
}
}()
// check if all pods are synced to datastore
assert.EventuallyWithT(t, func(t *assert.CollectT) {
assert.Len(t, serverRunner.Datastore.PodGetAll(), len(podMetrics), "Datastore not synced")
}, 10*time.Second, time.Second)
address := fmt.Sprintf("localhost:%v", port)
// Create a grpc connection
conn, err := grpc.NewClient(address, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
logutil.Fatal(logger, err, "Failed to connect", "address", address)
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
client, err = extProcPb.NewExternalProcessorClient(conn).Process(ctx)
if err != nil {
logutil.Fatal(logger, err, "Failed to create client")
}
return client, func() {
cancel()
conn.Close()
stopServer()
// clear created pods
for _, pm := range podMetrics {
pod := utiltesting.MakePod(pm.NamespacedName.Name).
Namespace(pm.NamespacedName.Namespace).Complete().ObjRef()
if err := k8sClient.Delete(context.Background(), pod); err != nil {
logutil.Fatal(logger, err, "Failed to delete pod", "pod", pm.NamespacedName)
}
}
// wait a little until the goroutines actually exit
time.Sleep(5 * time.Second)
}
}
// Sets up a test environment and returns the runner struct
func BeforeSuit(t *testing.T) func() {
// Set up mock k8s API Client
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: true,
}
cfg, err := testEnv.Start()
if err != nil {
logutil.Fatal(logger, err, "Failed to start test environment", "config", cfg)
}
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(v1alpha2.AddToScheme(scheme))
k8sClient, err = k8sclient.New(cfg, k8sclient.Options{Scheme: scheme})
if err != nil {
logutil.Fatal(logger, err, "Failed to start k8s Client")
} else if k8sClient == nil {
logutil.Fatal(logger, nil, "No error, but returned kubernetes client is nil", "config", cfg)
}
// Init runtime.
ctrl.SetLogger(logger)
mgr, err := ctrl.NewManager(cfg, ctrl.Options{Scheme: scheme})
if err != nil {
logutil.Fatal(logger, err, "Failed to create controller manager")
}
if err := registerMetricsHandler(mgr, metricsPort); err != nil {
logutil.Fatal(logger, err, "Failed to register metrics handler")
}
serverRunner = runserver.NewDefaultExtProcServerRunner()
// Adjust from defaults
serverRunner.PoolName = "vllm-llama2-7b-pool"
serverRunner.Datastore = datastore.NewDatastore()
serverRunner.SecureServing = false
if err := serverRunner.SetupWithManager(context.Background(), mgr); err != nil {
logutil.Fatal(logger, err, "Failed to setup server runner")
}
// Start the controller manager in go routine, not blocking
go func() {
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
logutil.Fatal(logger, err, "Failed to start manager")
}
}()
logger.Info("Setting up hermetic ExtProc server")
// Unmarshal CRDs from file into structs
manifestsPath := filepath.Join("..", "testdata", "inferencepool-with-model-hermetic.yaml")
docs, err := readDocuments(manifestsPath)
if err != nil {
logutil.Fatal(logger, err, "Can't read object manifests", "path", manifestsPath)
}
for _, doc := range docs {
inferenceModel := &v1alpha2.InferenceModel{}
if err = yaml.Unmarshal(doc, inferenceModel); err != nil {
logutil.Fatal(logger, err, "Can't unmarshal object", "document", doc)
}
if inferenceModel.Kind == "InferenceModel" {
logger.Info("Creating inference model", "model", inferenceModel)
if err := k8sClient.Create(context.Background(), inferenceModel); err != nil {
logutil.Fatal(logger, err, "Unable to create inferenceModel", "modelName", inferenceModel.Name)
}
}
}
for _, doc := range docs {
inferencePool := &v1alpha2.InferencePool{}
if err = yaml.Unmarshal(doc, inferencePool); err != nil {
logutil.Fatal(logger, err, "Can't unmarshal object", "document", doc)
}
if inferencePool.Kind == "InferencePool" {
logger.Info("Creating inference pool", "pool", inferencePool)
if err := k8sClient.Create(context.Background(), inferencePool); err != nil {
logutil.Fatal(logger, err, "Unable to create inferencePool", "poolName", inferencePool.Name)
}
}
}
assert.EventuallyWithT(t, func(t *assert.CollectT) {
modelExist := serverRunner.Datastore.ModelGet("my-model")
synced := serverRunner.Datastore.PoolHasSynced() && modelExist != nil
assert.True(t, synced, "Timeout waiting for the pool and models to sync")
}, 10*time.Second, 10*time.Millisecond)
return func() {
_ = testEnv.Stop()
}
}
func sendRequest(t *testing.T, client extProcPb.ExternalProcessor_ProcessClient, req *extProcPb.ProcessingRequest) (*extProcPb.ProcessingResponse, error) {
t.Logf("Sending request: %v", req)
if err := client.Send(req); err != nil {
t.Logf("Failed to send request %+v: %v", req, err)
return nil, err
}
res, err := client.Recv()
if err != nil {
t.Logf("Failed to receive: %v", err)
return nil, err
}
t.Logf("Received request %+v", res)
return res, err
}
// readDocuments reads documents from file.
func readDocuments(fp string) ([][]byte, error) {
b, err := os.ReadFile(fp)
if err != nil {
return nil, err
}
docs := [][]byte{}
reader := k8syaml.NewYAMLReader(bufio.NewReader(bytes.NewReader(b)))
for {
// Read document
doc, err := reader.Read()
if err != nil {
if errors.Is(err, io.EOF) {
break
}
return nil, err
}
docs = append(docs, doc)
}
return docs, nil
}
func makeMetadata(endpoint string) *structpb.Struct {
return &structpb.Struct{
Fields: map[string]*structpb.Value{
runserver.DefaultDestinationEndpointHintMetadataNamespace: {
Kind: &structpb.Value_StructValue{
StructValue: &structpb.Struct{
Fields: map[string]*structpb.Value{
runserver.DefaultDestinationEndpointHintKey: {
Kind: &structpb.Value_StringValue{
StringValue: endpoint,
},
},
},
},
},
},
},
}
}
// registerMetricsHandler is a simplified version of metrics endpoint handler
// without Authentication for integration tests.
func registerMetricsHandler(mgr manager.Manager, port int) error {
metrics.Register()
// Init HTTP server.
h := promhttp.HandlerFor(
legacyregistry.DefaultGatherer,
promhttp.HandlerOpts{},
)
mux := http.NewServeMux()
mux.Handle("/metrics", h)
srv := &http.Server{
Addr: net.JoinHostPort("", strconv.Itoa(port)),
Handler: mux,
}
if err := mgr.Add(&manager.Server{
Name: "metrics",
Server: srv,
}); err != nil {
return err
}
return nil
}