Skip to content

Commit ac40736

Browse files
authored
test: add GetNodePoolCost func for perf testing (kubernetes-sigs#2602)
1 parent d23d143 commit ac40736

File tree

12 files changed

+149
-20
lines changed

12 files changed

+149
-20
lines changed

.github/actions/install-prometheus/action.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ description: 'Installs prometheus'
33
runs:
44
using: "composite"
55
steps:
6-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
76
- name: install
87
shell: bash
98
run: |

.github/actions/install-pyroscope/action.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ description: 'Installs Pyroscope'
33
runs:
44
using: "composite"
55
steps:
6-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
76
- name: download pyroscope
87
shell: bash
98
run: |

.github/workflows/e2e.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ jobs:
4848
uses: ./.github/actions/install-prometheus
4949
- name: install pyroscope
5050
uses: ./.github/actions/install-pyroscope
51+
- name: install ko
52+
shell: bash
53+
run: |
54+
go install github.com/google/ko@latest
5155
- name: install kwok and controller
5256
shell: bash
5357
run: |

go.mod

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ require (
6464
github.com/spf13/cobra v1.10.1 // indirect
6565
github.com/spf13/pflag v1.0.10 // indirect
6666
github.com/x448/float16 v0.8.4 // indirect
67-
golang.org/x/net v0.46.0 // indirect
67+
golang.org/x/net v0.47.0 // indirect
6868
golang.org/x/oauth2 v0.30.0 // indirect
6969
golang.org/x/sys v0.38.0 // indirect
70-
golang.org/x/term v0.36.0 // indirect
71-
golang.org/x/tools v0.38.0 // indirect
70+
golang.org/x/term v0.37.0 // indirect
71+
golang.org/x/tools v0.39.0 // indirect
7272
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
7373
google.golang.org/protobuf v1.36.8 // indirect
7474
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
@@ -172,6 +172,7 @@ require (
172172
github.com/google/go-licenses v1.6.0 // indirect
173173
github.com/google/licenseclassifier v0.0.0-20210722185704-3043a050f148 // indirect
174174
github.com/gordonklaus/ineffassign v0.2.0 // indirect
175+
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect
175176
github.com/gostaticanalysis/analysisutil v0.7.1 // indirect
176177
github.com/gostaticanalysis/comment v1.5.0 // indirect
177178
github.com/gostaticanalysis/forcetypeassert v0.2.0 // indirect
@@ -214,8 +215,10 @@ require (
214215
github.com/mitchellh/copystructure v1.2.0 // indirect
215216
github.com/mitchellh/go-homedir v1.1.0 // indirect
216217
github.com/mitchellh/reflectwalk v1.0.2 // indirect
218+
github.com/moby/spdystream v0.5.0 // indirect
217219
github.com/moricho/tparallel v0.3.2 // indirect
218220
github.com/muesli/termenv v0.16.0 // indirect
221+
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
219222
github.com/nakabonne/nestif v0.3.1 // indirect
220223
github.com/nishanths/exhaustive v0.12.0 // indirect
221224
github.com/nishanths/predeclared v0.2.2 // indirect
@@ -283,11 +286,11 @@ require (
283286
go.yaml.in/yaml/v2 v2.4.3 // indirect
284287
go.yaml.in/yaml/v3 v3.0.4 // indirect
285288
go.yaml.in/yaml/v4 v4.0.0-rc.3 // indirect
286-
golang.org/x/crypto v0.43.0 // indirect
289+
golang.org/x/crypto v0.44.0 // indirect
287290
golang.org/x/exp/typeparams v0.0.0-20250911091902-df9299821621 // indirect
288-
golang.org/x/mod v0.29.0 // indirect
291+
golang.org/x/mod v0.30.0 // indirect
289292
golang.org/x/sync v0.18.0 // indirect
290-
golang.org/x/telemetry v0.0.0-20251008203120-078029d740a8 // indirect
293+
golang.org/x/telemetry v0.0.0-20251111182119-bc8e575c7b54 // indirect
291294
golang.org/x/vuln v1.1.4 // indirect
292295
gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect
293296
gopkg.in/src-d/go-git.v4 v4.13.1 // indirect

go.sum

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,8 @@ github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+
922922
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
923923
github.com/gordonklaus/ineffassign v0.2.0 h1:Uths4KnmwxNJNzq87fwQQDDnbNb7De00VOk9Nu0TySs=
924924
github.com/gordonklaus/ineffassign v0.2.0/go.mod h1:TIpymnagPSexySzs7F9FnO1XFTy8IT3a59vmZp5Y9Lw=
925+
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 h1:JeSE6pjso5THxAzdVpqr6/geYxZytqFMBCOtn/ujyeo=
926+
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674/go.mod h1:r4w70xmWCQKmi1ONH4KIaBptdivuRPyosB9RmPlGEwA=
925927
github.com/gostaticanalysis/analysisutil v0.7.1 h1:ZMCjoue3DtDWQ5WyU16YbjbQEQ3VuzwxALrpYd+HeKk=
926928
github.com/gostaticanalysis/analysisutil v0.7.1/go.mod h1:v21E3hY37WKMGSnbsw2S/ojApNWb6C1//mXO48CXbVc=
927929
github.com/gostaticanalysis/comment v1.4.2/go.mod h1:KLUTGDv6HOCotCH8h2erHKmpci2ZoR8VPu34YA2uzdM=
@@ -1098,6 +1100,8 @@ github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR
10981100
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
10991101
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
11001102
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
1103+
github.com/moby/spdystream v0.5.0 h1:7r0J1Si3QO/kjRitvSLVVFUjxMEb/YLj6S9FF62JBCU=
1104+
github.com/moby/spdystream v0.5.0/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVOwrfMgdI=
11011105
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
11021106
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
11031107
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -1110,6 +1114,8 @@ github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc
11101114
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
11111115
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
11121116
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
1117+
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
1118+
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
11131119
github.com/nakabonne/nestif v0.3.1 h1:wm28nZjhQY5HyYPx+weN3Q65k6ilSBxDb8v5S81B81U=
11141120
github.com/nakabonne/nestif v0.3.1/go.mod h1:9EtoZochLn5iUprVDmDjqGKPofoUEBL8U4Ngq6aY7OE=
11151121
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
@@ -1541,8 +1547,8 @@ golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0Y
15411547
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
15421548
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
15431549
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
1544-
golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04=
1545-
golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=
1550+
golang.org/x/crypto v0.44.0 h1:A97SsFvM3AIwEEmTBiaxPPTYpDC47w720rdiiUvgoAU=
1551+
golang.org/x/crypto v0.44.0/go.mod h1:013i+Nw79BMiQiMsOPcVCB5ZIJbYkerPrGnOa00tvmc=
15461552
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
15471553
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
15481554
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@@ -1619,8 +1625,8 @@ golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
16191625
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
16201626
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
16211627
golang.org/x/mod v0.23.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
1622-
golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA=
1623-
golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w=
1628+
golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk=
1629+
golang.org/x/mod v0.30.0/go.mod h1:lAsf5O2EvJeSFMiBxXDki7sCgAxEUcZHXoXMKT4GJKc=
16241630
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
16251631
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
16261632
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -1707,8 +1713,8 @@ golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
17071713
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
17081714
golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E=
17091715
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
1710-
golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=
1711-
golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=
1716+
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
1717+
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
17121718
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
17131719
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
17141720
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -1905,8 +1911,8 @@ golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
19051911
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
19061912
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
19071913
golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0=
1908-
golang.org/x/telemetry v0.0.0-20251008203120-078029d740a8 h1:LvzTn0GQhWuvKH/kVRS3R3bVAsdQWI7hvfLHGgh9+lU=
1909-
golang.org/x/telemetry v0.0.0-20251008203120-078029d740a8/go.mod h1:Pi4ztBfryZoJEkyFTI5/Ocsu2jXyDr6iSdgJiYE/uwE=
1914+
golang.org/x/telemetry v0.0.0-20251111182119-bc8e575c7b54 h1:E2/AqCUMZGgd73TQkxUMcMla25GB9i/5HOdLr+uH7Vo=
1915+
golang.org/x/telemetry v0.0.0-20251111182119-bc8e575c7b54/go.mod h1:hKdjCMrbv9skySur+Nek8Hd0uJ0GuxJIoIX2payrIdQ=
19101916
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
19111917
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
19121918
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
@@ -1941,8 +1947,8 @@ golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
19411947
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
19421948
golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw=
19431949
golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
1944-
golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q=
1945-
golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss=
1950+
golang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU=
1951+
golang.org/x/term v0.37.0/go.mod h1:5pB4lxRNYYVZuTLmy8oR2BH8dflOR+IbTYFD8fi3254=
19461952
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
19471953
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
19481954
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -2070,8 +2076,8 @@ golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxb
20702076
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
20712077
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
20722078
golang.org/x/tools v0.30.0/go.mod h1:c347cR/OJfw5TI+GfX7RUPNMdDRRbjvYTS0jPyvsVtY=
2073-
golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ=
2074-
golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs=
2079+
golang.org/x/tools v0.39.0 h1:ik4ho21kwuQln40uelmciQPp9SipgNDdrafrYA4TmQQ=
2080+
golang.org/x/tools v0.39.0/go.mod h1:JnefbkDPyD8UU2kI5fuf8ZX4/yUeh9W877ZeBONxUqQ=
20752081
golang.org/x/tools/go/expect v0.1.1-deprecated h1:jpBZDwmgPhXsKZC6WhL20P4b/wmnpsEAGHaNy0n/rJM=
20762082
golang.org/x/tools/go/expect v0.1.1-deprecated/go.mod h1:eihoPOH+FgIqa3FpoTwguz/bVUSGBlGQU67vpBeOrBY=
20772083
golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated h1:1h2MnaIAIXISqTFKdENegdpAgUXz6NrPEsbIeWaBRvM=

test/pkg/environment/common/expectations.go

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@ limitations under the License.
1717
package common
1818

1919
import (
20+
"bufio"
2021
"bytes"
22+
"context"
2123
"encoding/base64"
2224
"fmt"
2325
"io"
2426
"math"
27+
"net/http"
28+
"regexp"
29+
"strconv"
2530
"strings"
2631
"time"
2732

33+
"k8s.io/client-go/transport/spdy"
34+
2835
"github.com/awslabs/operatorpkg/object"
2936
. "github.com/onsi/ginkgo/v2"
3037
. "github.com/onsi/gomega"
@@ -39,7 +46,9 @@ import (
3946
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
4047
"k8s.io/apimachinery/pkg/labels"
4148
"k8s.io/apimachinery/pkg/types"
49+
"k8s.io/apimachinery/pkg/util/rand"
4250
"k8s.io/apimachinery/pkg/util/sets"
51+
"k8s.io/client-go/tools/portforward"
4352
"k8s.io/client-go/transport"
4453
"sigs.k8s.io/controller-runtime/pkg/client"
4554
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
@@ -1262,3 +1271,107 @@ func (env *Environment) GetDaemonSetOverhead(np *v1.NodePool) corev1.ResourceLis
12621271
return p, true
12631272
})...)
12641273
}
1274+
1275+
type PrometheusMetric struct {
1276+
Name string
1277+
Labels map[string]string
1278+
Value float64
1279+
}
1280+
1281+
func (env *Environment) ExpectPodMetrics() (res []PrometheusMetric) {
1282+
GinkgoHelper()
1283+
1284+
ctx, cancel := context.WithCancel(env.Context)
1285+
defer cancel()
1286+
1287+
localPort := rand.IntnRange(1024, 49151)
1288+
env.ExpectPodPortForwarded(ctx, env.ExpectActiveKarpenterPod(), 8080, localPort)
1289+
1290+
resp, err := http.Get(fmt.Sprintf("http://127.0.0.1:%d/metrics", localPort))
1291+
Expect(err).ToNot(HaveOccurred())
1292+
reader := bufio.NewReader(resp.Body)
1293+
defer resp.Body.Close()
1294+
for {
1295+
line, err := reader.ReadBytes('\n')
1296+
if err != nil {
1297+
//nolint:errorlint
1298+
if err == io.EOF {
1299+
break
1300+
}
1301+
continue
1302+
}
1303+
metric, err := parseMetricsLine(string(line))
1304+
if err != nil {
1305+
continue
1306+
}
1307+
res = append(res, metric)
1308+
}
1309+
return res
1310+
}
1311+
1312+
var (
1313+
prometheusMetricRegex = regexp.MustCompile(`(?P<Name>.*){(?P<Labels>.*)} (?P<Value>\d*(?:\.\d*)?)`)
1314+
)
1315+
1316+
func parseMetricsLine(line string) (metric PrometheusMetric, err error) {
1317+
groups := prometheusMetricRegex.FindStringSubmatch(line)
1318+
if len(groups) != 4 {
1319+
return PrometheusMetric{}, fmt.Errorf("metrics line doesn't match known prometheus syntax")
1320+
}
1321+
1322+
elems := strings.Split(groups[2], ",")
1323+
l := lo.SliceToMap(elems, func(elem string) (string, string) {
1324+
temp := strings.Split(elem, "=")
1325+
k, v := temp[0], temp[1]
1326+
return k, strings.Trim(v, "\"")
1327+
})
1328+
v, err := strconv.ParseFloat(groups[3], 64)
1329+
if err != nil {
1330+
return PrometheusMetric{}, fmt.Errorf("converting metrics value to an integer, %w", err)
1331+
}
1332+
return PrometheusMetric{Name: groups[1], Labels: l, Value: v}, nil
1333+
}
1334+
1335+
func (env *Environment) ExpectPodPortForwarded(ctx context.Context, pod *corev1.Pod, podPort, localPort int) {
1336+
GinkgoHelper()
1337+
1338+
roundTripper, upgrader, err := spdy.RoundTripperFor(env.Config)
1339+
Expect(err).ToNot(HaveOccurred())
1340+
1341+
serverURL := env.KubeClient.CoreV1().RESTClient().Post().
1342+
Resource("pods").
1343+
Namespace(pod.Namespace).
1344+
Name(pod.Name).
1345+
SubResource("portforward").URL()
1346+
1347+
dialer := spdy.NewDialer(upgrader, &http.Client{Transport: roundTripper}, http.MethodPost, serverURL)
1348+
1349+
ready := make(chan struct{})
1350+
stop := make(chan struct{})
1351+
go func() {
1352+
GinkgoRecover()
1353+
<-ctx.Done()
1354+
close(stop)
1355+
}()
1356+
go func() {
1357+
fw, err := portforward.New(dialer, []string{fmt.Sprintf("%d:%d", localPort, podPort)}, stop, ready, io.Discard, io.Discard)
1358+
Expect(err).ToNot(HaveOccurred())
1359+
Expect(fw.ForwardPorts())
1360+
}()
1361+
<-ready
1362+
}
1363+
1364+
func (env *Environment) GetNodePoolCost(nodePoolName string) float64 {
1365+
GinkgoHelper()
1366+
var cost float64
1367+
Eventually(func(g Gomega) {
1368+
defer GinkgoRecover()
1369+
podMetrics := env.ExpectPodMetrics()
1370+
priceMetrics := lo.Filter(podMetrics, func(p PrometheusMetric, _ int) bool {
1371+
return p.Name == "karpenter_nodepools_cost_total" && p.Labels["nodepool"] == nodePoolName
1372+
})
1373+
g.Expect(priceMetrics).ToNot(BeEmpty())
1374+
cost = priceMetrics[0].Value
1375+
}, 2*time.Minute, time.Second*5).Should(Succeed())
1376+
return cost
1377+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)