-
Notifications
You must be signed in to change notification settings - Fork 22
/
server_init_route.go
101 lines (85 loc) · 3.12 KB
/
server_init_route.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
package server
import (
"github.com/gin-gonic/gin"
swaggerfiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
_ "github.com/tensorchord/openmodelz/agent/pkg/docs"
"github.com/tensorchord/openmodelz/agent/pkg/metrics"
)
const (
endpointInferencePlural = "/inferences"
endpointInference = "/inference"
endpointServerPlural = "/servers"
endpointServer = "/server"
endpointScaleInference = "/scale-inference"
endpointInfo = "/info"
endpointLogPlural = "/logs"
endpointNamespacePlural = "/namespaces"
endpointHealthz = "/healthz"
endpointBuild = "/build"
)
func (s *Server) registerRoutes() {
root := s.router.Group("/")
// swagger
root.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
// dataplane
root.Any("/inference/:name",
WrapHandler(s.middlewareCallID),
WrapHandler(s.handleInferenceProxy))
root.Any("/inference/:name/*proxyPath",
WrapHandler(s.middlewareCallID),
WrapHandler(s.handleInferenceProxy))
// healthz
root.GET(endpointHealthz, WrapHandler(s.handleHealthz))
// landing page
root.GET("/", WrapHandler(s.handleRoot))
// control plane
controlPlane := root.Group("/system")
// inferences
controlPlane.GET(endpointInferencePlural,
WrapHandler(s.handleInferenceList))
controlPlane.POST(endpointInferencePlural,
WrapHandler(s.handleInferenceCreate))
controlPlane.PUT(endpointInferencePlural,
WrapHandler(s.handleInferenceUpdate))
controlPlane.DELETE(endpointInferencePlural,
WrapHandler(s.handleInferenceDelete))
controlPlane.POST(endpointScaleInference,
WrapHandler(s.handleInferenceScale))
controlPlane.GET(endpointInference+"/:name",
WrapHandler(s.handleInferenceGet))
// instances
controlPlane.GET(endpointInference+"/:name/instances",
WrapHandler(s.handleInferenceInstance))
controlPlane.GET(endpointInference+"/:name/instance/:instance/exec",
WrapHandler(s.handleInferenceInstanceExec))
// info
controlPlane.GET(endpointInfo, WrapHandler(s.handleInfo))
// servers
controlPlane.GET(endpointServerPlural, WrapHandler(s.handleServerList))
controlPlane.POST(endpointServer+"/:name/labels", WrapHandler(s.handleServerLabelCreate))
// logs
controlPlane.GET(endpointLogPlural+endpointInference,
WrapHandler(s.handleInferenceLogs))
controlPlane.GET(endpointLogPlural+endpointBuild, WrapHandler(s.handleBuildLogs))
// namespaces
controlPlane.GET(endpointNamespacePlural,
WrapHandler(s.handleNamespaceList))
controlPlane.POST(endpointNamespacePlural,
WrapHandler(s.handleNamespaceCreate))
// TODO(gaocegege): Support secrets
// controlPlane.GET("/secrets")
// builds
if s.config.Build.BuildEnabled {
controlPlane.GET(endpointBuild, WrapHandler(s.handleBuildList))
controlPlane.GET(endpointBuild+"/:name", WrapHandler(s.handleBuildGet))
controlPlane.POST(endpointBuild, WrapHandler(s.handleBuildCreate))
}
// TODO(gaocegege): Support metrics
// metrics
}
// registerMetricsRoutes registers the metrics routes.
func (s *Server) registerMetricsRoutes() {
s.metricsRouter.GET("/metrics", gin.WrapH(metrics.PrometheusHandler()))
s.metricsRouter.GET(endpointHealthz, WrapHandler(s.handleHealthz))
}