Skip to content

Commit ac9b202

Browse files
authored
Add supervisor logs (#131)
* Update devcontainer config * Add supervisor logs proxy
1 parent 67abf8b commit ac9b202

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

.devcontainer.json

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@
77
"containerEnv": {
88
"DEVELOPMENT": "True"
99
},
10-
"settings": {
11-
"terminal.integrated.shell.linux": "/bin/bash",
12-
"go.useGoProxyToCheckForToolUpdates": false,
13-
"go.useLanguageServer": true,
14-
"go.gopath": "/go",
15-
"go.goroot": "/usr/local/go",
16-
"go.toolsGopath": "/go/bin",
17-
"go.lintTool":"golangci-lint",
18-
"go.lintFlags": [
19-
"--fast"
20-
]
21-
},
22-
"extensions": [
23-
"golang.Go"
24-
]
10+
"customizations": {
11+
"vscode": {
12+
"settings": {
13+
"terminal.integrated.shell.linux": "/bin/bash",
14+
"go.useGoProxyToCheckForToolUpdates": false,
15+
"go.useLanguageServer": true,
16+
"go.gopath": "/go",
17+
"go.goroot": "/usr/local/go",
18+
"go.toolsGopath": "/go/bin",
19+
"go.lintTool":"golangci-lint",
20+
"go.lintFlags": [
21+
"--fast"
22+
]
23+
},
24+
"extensions": ["golang.Go"]
25+
}
26+
}
2527
}

http.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ func httpSupervisorProxy(w http.ResponseWriter, r *http.Request) {
5757
log.Printf("Proxy request: %s", r.URL.Path)
5858

5959
// Base Supervisor URL
60-
u, err := url.Parse("http://supervisor/")
60+
supervisorHost := "supervisor"
61+
62+
if development && os.Getenv("SUPERVISOR_HOST") != "" {
63+
supervisorHost = os.Getenv("SUPERVISOR_HOST")
64+
}
65+
66+
u, err := url.Parse("http://" + supervisorHost + "/")
6167
if err != nil {
6268
// Handle error in parsing URL
6369
w.Write([]byte(err.Error()))
@@ -100,6 +106,14 @@ func httpSupervisorProxy(w http.ResponseWriter, r *http.Request) {
100106
// Add authorization header
101107
r.Header.Add("Authorization", "Bearer "+os.Getenv("SUPERVISOR_TOKEN"))
102108

109+
if cleanPath == "/logs" {
110+
// for logs download add text/plain headers
111+
r.Header.Add("Accept", "text/plain")
112+
} else if cleanPath == "/logs/follow" {
113+
// Set FlushInterval to enable streaming
114+
proxy.FlushInterval = -1
115+
}
116+
103117
// Forward the request
104118
proxy.ServeHTTP(w, r)
105119
}

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ var development bool
1717
func main() {
1818
development = (os.Getenv("DEVELOPMENT") == "True")
1919

20-
if development {
20+
if development && os.Getenv("FRONTEND_PATH") != "" {
21+
wwwRoot = os.Getenv("FRONTEND_PATH") + "/landing-page/dist/"
22+
} else if development {
2123
wwwRoot = "./rootfs/usr/share/www/"
2224
} else {
2325
wwwRoot = "/usr/share/www/"
@@ -27,6 +29,8 @@ func main() {
2729
http.HandleFunc("/api/", httpUnauthorized)
2830
http.HandleFunc("/auth/token", httpBad)
2931
http.HandleFunc("/observer/logs", httpLogs)
32+
http.HandleFunc("/supervisor/supervisor/logs", httpSupervisorProxy)
33+
http.HandleFunc("/supervisor/supervisor/logs/follow", httpSupervisorProxy)
3034
http.HandleFunc("/supervisor/resolution/", httpSupervisorProxy)
3135
http.HandleFunc("/supervisor/network/", httpSupervisorProxy)
3236

0 commit comments

Comments
 (0)