Skip to content

Commit 9203bd6

Browse files
authored
Fix validation of toggling batch ensembling (#119)
* Fix validation of toggling batch ensembling, disable endpoints if not enabled * Change validator logic, add nil checks. * Fix validation. * update comment.
1 parent fae6d50 commit 9203bd6

File tree

8 files changed

+114
-40
lines changed

8 files changed

+114
-40
lines changed

api/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/antihax/optional v1.0.0
1010
github.com/getkin/kin-openapi v0.75.0
1111
github.com/ghodss/yaml v1.0.0
12-
github.com/go-playground/validator/v10 v10.3.0
12+
github.com/go-playground/validator/v10 v10.9.0
1313
github.com/gojek/fiber v0.0.0-20201008181849-4f0f8284dc84
1414
github.com/gojek/merlin v0.0.0
1515
github.com/gojek/mlp v1.4.7
@@ -29,7 +29,7 @@ require (
2929
github.com/patrickmn/go-cache v2.1.0+incompatible
3030
github.com/pkg/errors v0.9.1
3131
github.com/rs/cors v1.7.0
32-
github.com/stretchr/testify v1.6.1
32+
github.com/stretchr/testify v1.7.0
3333
github.com/tidwall/gjson v1.6.5
3434
github.com/xanzy/go-gitlab v0.31.0
3535
go.uber.org/zap v1.15.0

api/go.sum

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,13 +522,18 @@ github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBY
522522
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
523523
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
524524
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
525+
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
526+
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
525527
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
526528
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
529+
github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
530+
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
527531
github.com/go-playground/validator v9.30.0+incompatible/go.mod h1:yrEkQXlcI+PugkyDjY2bRrL/UBU4f3rvrgkN3V8JEig=
528532
github.com/go-playground/validator v9.31.0+incompatible h1:UA72EPEogEnq76ehGdEDp4Mit+3FDh548oRqwVgNsHA=
529533
github.com/go-playground/validator v9.31.0+incompatible/go.mod h1:yrEkQXlcI+PugkyDjY2bRrL/UBU4f3rvrgkN3V8JEig=
530-
github.com/go-playground/validator/v10 v10.3.0 h1:nZU+7q+yJoFmwvNgv/LnPUkwPal62+b2xXj0AU1Es7o=
531534
github.com/go-playground/validator/v10 v10.3.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
535+
github.com/go-playground/validator/v10 v10.9.0 h1:NgTtmN58D0m8+UuxtYmGztBJB7VnPgjj221I1QHci2A=
536+
github.com/go-playground/validator/v10 v10.9.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos=
532537
github.com/go-redis/redis v6.14.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
533538
github.com/go-sql-driver/mysql v0.0.0-20160411075031-7ebe0a500653/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
534539
github.com/go-sql-driver/mysql v0.0.0-20180308100310-1a676ac6e4dc/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
@@ -898,6 +903,9 @@ github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFB
898903
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
899904
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
900905
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
906+
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
907+
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
908+
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
901909
github.com/kr/pty v1.0.0/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
902910
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
903911
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
@@ -910,6 +918,8 @@ github.com/kubernetes-incubator/custom-metrics-apiserver v0.0.0-20190918110929-3
910918
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
911919
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
912920
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
921+
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
922+
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
913923
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
914924
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
915925
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
@@ -1109,6 +1119,7 @@ github.com/pierrec/lz4 v2.2.6+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi
11091119
github.com/pierrec/lz4 v2.4.1+incompatible h1:mFe7ttWaflA46Mhqh+jUfjp2qTbPYxLB2/OyBppH9dg=
11101120
github.com/pierrec/lz4 v2.4.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
11111121
github.com/pilagod/gorm-cursor-paginator v1.3.0/go.mod h1:j8Bc6Ik1CZJxn/UpwWOa9ncFncy7GWfRB+WxHM0ot8o=
1122+
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
11121123
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
11131124
github.com/pkg/errors v0.8.1-0.20171018195549-f15c970de5b7/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
11141125
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -1191,6 +1202,9 @@ github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYe
11911202
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
11921203
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
11931204
github.com/rogpeppe/go-internal v1.3.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
1205+
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
1206+
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
1207+
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
11941208
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
11951209
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
11961210
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
@@ -1285,6 +1299,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
12851299
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
12861300
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
12871301
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
1302+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
1303+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
12881304
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
12891305
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
12901306
github.com/syndtr/gocapability v0.0.0-20160928074757-e7cb7fa329f4/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
@@ -1442,6 +1458,8 @@ golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPh
14421458
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
14431459
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
14441460
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
1461+
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI=
1462+
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
14451463
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
14461464
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
14471465
golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@@ -1539,6 +1557,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
15391557
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
15401558
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11 h1:lwlPPsmjDKK0J6eG6xDWd5XPehI0R024zxjDnw3esPA=
15411559
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
1560+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
1561+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
15421562
golang.org/x/oauth2 v0.0.0-20180603041954-1e0a3fa8ba9a/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
15431563
golang.org/x/oauth2 v0.0.0-20180724155351-3d292e4d0cdc/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
15441564
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@@ -1643,6 +1663,10 @@ golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7w
16431663
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
16441664
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 h1:JWgyZ1qgdTaF3N3oxC+MdTV7qvEEgHo3otj+HB5CM7Q=
16451665
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1666+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1667+
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069 h1:siQdpVirKtzPhKl3lZWozZraCFObP8S1v6PRp0bLrtU=
1668+
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1669+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
16461670
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
16471671
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
16481672
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -1654,6 +1678,8 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
16541678
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
16551679
golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc=
16561680
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
1681+
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
1682+
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
16571683
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
16581684
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
16591685
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
@@ -1902,6 +1928,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
19021928
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
19031929
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
19041930
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1931+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
1932+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
19051933
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
19061934
gopkg.in/confluentinc/confluent-kafka-go.v1 v1.4.2/go.mod h1:ZdI3yfYmdNSLQPNCpO1y00EHyWaHG5EnQEyL/ntAegY=
19071935
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
@@ -1953,6 +1981,8 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
19531981
gopkg.in/yaml.v3 v3.0.0-20190709130402-674ba3eaed22/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
19541982
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
19551983
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
1984+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
1985+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
19561986
gotest.tools v2.1.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
19571987
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
19581988
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=

api/turing/api/appcontext.go

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,37 @@ func NewAppContext(
8383
cfg.KubernetesLabelConfigs.Environment,
8484
)
8585

86-
// Initialise Ensembling Job Service
87-
ensemblingJobService := service.NewEnsemblingJobService(
88-
db,
89-
cfg.BatchEnsemblingConfig.JobConfig.DefaultEnvironment,
90-
cfg.BatchEnsemblingConfig.ImageBuildingConfig.BuildNamespace,
91-
cfg.BatchEnsemblingConfig.LoggingURLFormat,
92-
cfg.BatchEnsemblingConfig.MonitoringURLFormat,
93-
cfg.BatchEnsemblingConfig.JobConfig.DefaultConfigurations,
94-
mlpSvc,
95-
)
96-
9786
// Initialise Batch components
9887
// Since there is only the default environment, we will not create multiple batch runners.
9988
var batchJobRunners []batchrunner.BatchJobRunner
10089

90+
var ensemblingJobService service.EnsemblingJobService
10191
if cfg.BatchEnsemblingConfig.Enabled {
92+
if cfg.BatchEnsemblingConfig.JobConfig == nil {
93+
return nil, errors.Wrapf(err, "BatchEnsemblingConfig.JobConfig was not set")
94+
}
95+
if cfg.BatchEnsemblingConfig.RunnerConfig == nil {
96+
return nil, errors.Wrapf(err, "BatchEnsemblingConfig.RunnerConfig was not set")
97+
}
98+
if cfg.BatchEnsemblingConfig.ImageBuildingConfig == nil {
99+
return nil, errors.Wrapf(err, "BatchEnsemblingConfig.ImageBuildingConfig was not set")
100+
}
101+
102+
// Initialise Ensembling Job Service
103+
ensemblingJobService = service.NewEnsemblingJobService(
104+
db,
105+
cfg.BatchEnsemblingConfig.JobConfig.DefaultEnvironment,
106+
cfg.BatchEnsemblingConfig.ImageBuildingConfig.BuildNamespace,
107+
cfg.BatchEnsemblingConfig.LoggingURLFormat,
108+
cfg.BatchEnsemblingConfig.MonitoringURLFormat,
109+
cfg.BatchEnsemblingConfig.JobConfig.DefaultConfigurations,
110+
mlpSvc,
111+
)
112+
102113
batchClusterController := clusterControllers[cfg.BatchEnsemblingConfig.JobConfig.DefaultEnvironment]
103114
ensemblingImageBuilder, err := imagebuilder.NewEnsemblerJobImageBuilder(
104115
batchClusterController,
105-
cfg.BatchEnsemblingConfig.ImageBuildingConfig,
116+
*cfg.BatchEnsemblingConfig.ImageBuildingConfig,
106117
)
107118
if err != nil {
108119
return nil, errors.Wrapf(err, "Failed initializing ensembling image builder")

api/turing/api/appcontext_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ func TestNewAppContext(t *testing.T) {
4646

4747
testCfg := &config.Config{
4848
Port: 8080,
49-
BatchEnsemblingConfig: &config.BatchEnsemblingConfig{
49+
BatchEnsemblingConfig: config.BatchEnsemblingConfig{
5050
Enabled: true,
51-
JobConfig: config.JobConfig{
51+
JobConfig: &config.JobConfig{
5252
DefaultEnvironment: "dev",
5353
DefaultConfigurations: config.DefaultEnsemblingJobConfigurations{
5454
BatchEnsemblingJobResources: openapi.EnsemblingResources{
@@ -63,12 +63,12 @@ func TestNewAppContext(t *testing.T) {
6363
},
6464
},
6565
},
66-
RunnerConfig: config.RunnerConfig{
66+
RunnerConfig: &config.RunnerConfig{
6767
TimeInterval: 3 * time.Minute,
6868
RecordsToProcessInOneIteration: 10,
6969
MaxRetryCount: 3,
7070
},
71-
ImageBuildingConfig: config.ImageBuildingConfig{
71+
ImageBuildingConfig: &config.ImageBuildingConfig{
7272
DestinationRegistry: "ghcr.io",
7373
BaseImageRef: "ghcr.io/gojek/turing/batch-ensembler:0.0.0-build.1-98b071d",
7474
BuildNamespace: "default",
@@ -254,7 +254,7 @@ func TestNewAppContext(t *testing.T) {
254254

255255
ensemblingImageBuilder, err := imagebuilder.NewEnsemblerJobImageBuilder(
256256
nil,
257-
testCfg.BatchEnsemblingConfig.ImageBuildingConfig,
257+
*testCfg.BatchEnsemblingConfig.ImageBuildingConfig,
258258
)
259259
assert.Nil(t, err)
260260

api/turing/api/ensembling_job_api_it_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,11 @@ func TestIntegrationEnsemblingJobController_CreateEnsemblingJob(t *testing.T) {
284284
EnsemblingJobService: ensemblingJobService,
285285
MLPService: mlpService,
286286
}
287-
_ = server.AddAPIRoutesHandler(router, "/", appCtx, &config.Config{})
287+
_ = server.AddAPIRoutesHandler(router, "/", appCtx, &config.Config{
288+
BatchEnsemblingConfig: config.BatchEnsemblingConfig{
289+
Enabled: true,
290+
},
291+
})
288292

289293
actual := httptest.NewRecorder()
290294

@@ -351,7 +355,11 @@ func TestIntegrationEnsemblingJobController_GetEnsemblingJob(t *testing.T) {
351355
appCtx := &api.AppContext{
352356
EnsemblingJobService: svc,
353357
}
354-
_ = server.AddAPIRoutesHandler(router, "/", appCtx, &config.Config{})
358+
_ = server.AddAPIRoutesHandler(router, "/", appCtx, &config.Config{
359+
BatchEnsemblingConfig: config.BatchEnsemblingConfig{
360+
Enabled: true,
361+
},
362+
})
355363

356364
actual := httptest.NewRecorder()
357365
request, err := http.NewRequest(tt.method, tt.path, nil)
@@ -513,7 +521,11 @@ func TestIntegrationEnsemblingJobController_ListEnsemblingJob(t *testing.T) {
513521
appCtx := &api.AppContext{
514522
EnsemblingJobService: svc,
515523
}
516-
_ = server.AddAPIRoutesHandler(router, "/", appCtx, &config.Config{})
524+
_ = server.AddAPIRoutesHandler(router, "/", appCtx, &config.Config{
525+
BatchEnsemblingConfig: config.BatchEnsemblingConfig{
526+
Enabled: true,
527+
},
528+
})
517529

518530
actual := httptest.NewRecorder()
519531

api/turing/config/config.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type Config struct {
5454
LogLevel string
5555
AllowedOrigins []string
5656
AuthConfig *AuthorizationConfig
57-
BatchEnsemblingConfig *BatchEnsemblingConfig `validate:"required"`
57+
BatchEnsemblingConfig BatchEnsemblingConfig `validate:"required"`
5858
DbConfig *DatabaseConfig `validate:"required"`
5959
DeployConfig *DeploymentConfig `validate:"required"`
6060
SparkAppConfig *SparkAppConfig `validate:"required"`
@@ -95,10 +95,12 @@ func (c *Config) Validate() error {
9595

9696
// BatchEnsemblingConfig captures the config related to the running of batch runners
9797
type BatchEnsemblingConfig struct {
98-
Enabled bool `validate:"required"`
99-
JobConfig JobConfig `validate:"required"`
100-
RunnerConfig RunnerConfig `validate:"required"`
101-
ImageBuildingConfig ImageBuildingConfig `validate:"required"`
98+
// Unfortunately if Enabled is false and user sets JobConfig/RunnerConfig/ImageBuildingConfig wrongly
99+
// it will still error out.
100+
Enabled bool
101+
JobConfig *JobConfig `validate:"required_if=Enabled True"`
102+
RunnerConfig *RunnerConfig `validate:"required_if=Enabled True"`
103+
ImageBuildingConfig *ImageBuildingConfig `validate:"required_if=Enabled True"`
102104
LoggingURLFormat *string
103105
MonitoringURLFormat *string
104106
}

0 commit comments

Comments
 (0)