mirror of
https://github.com/coder/coder.git
synced 2025-07-30 22:19:53 +00:00
feat: add debug endpoint for single tailnet (#10485)
This commit is contained in:
22
coderd/apidoc/docs.go
generated
22
coderd/apidoc/docs.go
generated
@@ -422,6 +422,28 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/debug/tailnet": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"CoderSessionToken": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"text/html"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Debug"
|
||||||
|
],
|
||||||
|
"summary": "Debug Info Tailnet",
|
||||||
|
"operationId": "debug-info-tailnet",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/debug/ws": {
|
"/debug/ws": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
|
18
coderd/apidoc/swagger.json
generated
18
coderd/apidoc/swagger.json
generated
@@ -358,6 +358,24 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/debug/tailnet": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"CoderSessionToken": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"produces": ["text/html"],
|
||||||
|
"tags": ["Debug"],
|
||||||
|
"summary": "Debug Info Tailnet",
|
||||||
|
"operationId": "debug-info-tailnet",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/debug/ws": {
|
"/debug/ws": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
|
@@ -955,6 +955,7 @@ func New(options *Options) *API {
|
|||||||
)
|
)
|
||||||
|
|
||||||
r.Get("/coordinator", api.debugCoordinator)
|
r.Get("/coordinator", api.debugCoordinator)
|
||||||
|
r.Get("/tailnet", api.debugTailnet)
|
||||||
r.Get("/health", api.debugDeploymentHealth)
|
r.Get("/health", api.debugDeploymentHealth)
|
||||||
r.Get("/ws", (&healthcheck.WebsocketEchoServer{}).ServeHTTP)
|
r.Get("/ws", (&healthcheck.WebsocketEchoServer{}).ServeHTTP)
|
||||||
})
|
})
|
||||||
|
@@ -352,7 +352,8 @@ func assertProduce(t *testing.T, comment SwaggerComment) {
|
|||||||
(comment.router == "/workspaceagents/me/startup" && comment.method == "post") ||
|
(comment.router == "/workspaceagents/me/startup" && comment.method == "post") ||
|
||||||
(comment.router == "/workspaceagents/me/startup/logs" && comment.method == "patch") ||
|
(comment.router == "/workspaceagents/me/startup/logs" && comment.method == "patch") ||
|
||||||
(comment.router == "/licenses/{id}" && comment.method == "delete") ||
|
(comment.router == "/licenses/{id}" && comment.method == "delete") ||
|
||||||
(comment.router == "/debug/coordinator" && comment.method == "get") {
|
(comment.router == "/debug/coordinator" && comment.method == "get") ||
|
||||||
|
(comment.router == "/debug/tailnet" && comment.method == "get") {
|
||||||
return // Exception: HTTP 200 is returned without response entity
|
return // Exception: HTTP 200 is returned without response entity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -23,6 +23,17 @@ func (api *API) debugCoordinator(rw http.ResponseWriter, r *http.Request) {
|
|||||||
(*api.TailnetCoordinator.Load()).ServeHTTPDebug(rw, r)
|
(*api.TailnetCoordinator.Load()).ServeHTTPDebug(rw, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Summary Debug Info Tailnet
|
||||||
|
// @ID debug-info-tailnet
|
||||||
|
// @Security CoderSessionToken
|
||||||
|
// @Produce text/html
|
||||||
|
// @Tags Debug
|
||||||
|
// @Success 200
|
||||||
|
// @Router /debug/tailnet [get]
|
||||||
|
func (api *API) debugTailnet(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
api.agentProvider.ServeHTTPDebug(rw, r)
|
||||||
|
}
|
||||||
|
|
||||||
// @Summary Debug Info Deployment Health
|
// @Summary Debug Info Deployment Health
|
||||||
// @ID debug-info-deployment-health
|
// @ID debug-info-deployment-health
|
||||||
// @Security CoderSessionToken
|
// @Security CoderSessionToken
|
||||||
|
@@ -21,6 +21,7 @@ import (
|
|||||||
|
|
||||||
"cdr.dev/slog"
|
"cdr.dev/slog"
|
||||||
"github.com/coder/coder/v2/coderd/tracing"
|
"github.com/coder/coder/v2/coderd/tracing"
|
||||||
|
"github.com/coder/coder/v2/coderd/workspaceapps"
|
||||||
"github.com/coder/coder/v2/coderd/wsconncache"
|
"github.com/coder/coder/v2/coderd/wsconncache"
|
||||||
"github.com/coder/coder/v2/codersdk"
|
"github.com/coder/coder/v2/codersdk"
|
||||||
"github.com/coder/coder/v2/site"
|
"github.com/coder/coder/v2/site"
|
||||||
@@ -38,6 +39,8 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ workspaceapps.AgentProvider = (*ServerTailnet)(nil)
|
||||||
|
|
||||||
// NewServerTailnet creates a new tailnet intended for use by coderd. It
|
// NewServerTailnet creates a new tailnet intended for use by coderd. It
|
||||||
// automatically falls back to wsconncache if a legacy agent is encountered.
|
// automatically falls back to wsconncache if a legacy agent is encountered.
|
||||||
func NewServerTailnet(
|
func NewServerTailnet(
|
||||||
@@ -419,6 +422,10 @@ func (s *ServerTailnet) DialAgentNetConn(ctx context.Context, agentID uuid.UUID,
|
|||||||
}}, err
|
}}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ServerTailnet) ServeHTTPDebug(w http.ResponseWriter, r *http.Request) {
|
||||||
|
s.conn.MagicsockServeHTTPDebug(w, r)
|
||||||
|
}
|
||||||
|
|
||||||
type netConnCloser struct {
|
type netConnCloser struct {
|
||||||
net.Conn
|
net.Conn
|
||||||
close func()
|
close func()
|
||||||
|
@@ -74,6 +74,8 @@ type AgentProvider interface {
|
|||||||
// func.
|
// func.
|
||||||
AgentConn(ctx context.Context, agentID uuid.UUID) (_ *codersdk.WorkspaceAgentConn, release func(), _ error)
|
AgentConn(ctx context.Context, agentID uuid.UUID) (_ *codersdk.WorkspaceAgentConn, release func(), _ error)
|
||||||
|
|
||||||
|
ServeHTTPDebug(w http.ResponseWriter, r *http.Request)
|
||||||
|
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,10 +16,13 @@ import (
|
|||||||
"golang.org/x/sync/singleflight"
|
"golang.org/x/sync/singleflight"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/coder/coder/v2/coderd/workspaceapps"
|
||||||
"github.com/coder/coder/v2/codersdk"
|
"github.com/coder/coder/v2/codersdk"
|
||||||
"github.com/coder/coder/v2/site"
|
"github.com/coder/coder/v2/site"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ workspaceapps.AgentProvider = (*AgentProvider)(nil)
|
||||||
|
|
||||||
type AgentProvider struct {
|
type AgentProvider struct {
|
||||||
Cache *Cache
|
Cache *Cache
|
||||||
}
|
}
|
||||||
@@ -56,6 +59,8 @@ func (a *AgentProvider) ReverseProxy(targetURL *url.URL, dashboardURL *url.URL,
|
|||||||
return proxy, release, nil
|
return proxy, release, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*AgentProvider) ServeHTTPDebug(http.ResponseWriter, *http.Request) {}
|
||||||
|
|
||||||
func (a *AgentProvider) Close() error {
|
func (a *AgentProvider) Close() error {
|
||||||
return a.Cache.Close()
|
return a.Cache.Close()
|
||||||
}
|
}
|
||||||
|
20
docs/api/debug.md
generated
20
docs/api/debug.md
generated
@@ -241,3 +241,23 @@ curl -X GET http://coder-server:8080/api/v2/debug/health \
|
|||||||
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [healthcheck.Report](schemas.md#healthcheckreport) |
|
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [healthcheck.Report](schemas.md#healthcheckreport) |
|
||||||
|
|
||||||
To perform this operation, you must be authenticated. [Learn more](authentication.md).
|
To perform this operation, you must be authenticated. [Learn more](authentication.md).
|
||||||
|
|
||||||
|
## Debug Info Tailnet
|
||||||
|
|
||||||
|
### Code samples
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# Example request using curl
|
||||||
|
curl -X GET http://coder-server:8080/api/v2/debug/tailnet \
|
||||||
|
-H 'Coder-Session-Token: API_KEY'
|
||||||
|
```
|
||||||
|
|
||||||
|
`GET /debug/tailnet`
|
||||||
|
|
||||||
|
### Responses
|
||||||
|
|
||||||
|
| Status | Meaning | Description | Schema |
|
||||||
|
| ------ | ------------------------------------------------------- | ----------- | ------ |
|
||||||
|
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | |
|
||||||
|
|
||||||
|
To perform this operation, you must be authenticated. [Learn more](authentication.md).
|
||||||
|
Reference in New Issue
Block a user