File tree Expand file tree Collapse file tree 8 files changed +89
-46
lines changed Expand file tree Collapse file tree 8 files changed +89
-46
lines changed Original file line number Diff line number Diff line change @@ -1124,6 +1124,22 @@ parameters:
1124
1124
x-example : 13
1125
1125
1126
1126
paths :
1127
+ /debug/gc :
1128
+ post :
1129
+ summary : Garbage collector
1130
+ description : Run the garbage collector
1131
+ responses :
1132
+ 204 :
1133
+ description : Successful "OK" reply
1134
+
1135
+ /debug/pprof/dump :
1136
+ post :
1137
+ summary : Dump pprof
1138
+ description : Dump pprof
1139
+ responses :
1140
+ 204 :
1141
+ description : Successful "OK" reply
1142
+
1127
1143
/ping :
1128
1144
get :
1129
1145
summary : PING test
Original file line number Diff line number Diff line change
1
+ package debug
2
+
3
+ import (
4
+ "net/http"
5
+ "runtime"
6
+ )
7
+
8
+ func GC (w http.ResponseWriter , r * http.Request ) {
9
+ runtime .GC ()
10
+ w .WriteHeader (http .StatusNoContent )
11
+ }
Original file line number Diff line number Diff line change
1
+ package debug
2
+
3
+ import (
4
+ "github.com/semaphoreui/semaphore/util"
5
+ log "github.com/sirupsen/logrus"
6
+ "net/http"
7
+ "os"
8
+ "path"
9
+ "runtime/pprof"
10
+ "strconv"
11
+ "time"
12
+ )
13
+
14
+ func Dump (w http.ResponseWriter , r * http.Request ) {
15
+
16
+ f , err := os .Create (path .Join (util .Config .Profiling .DumpsDir , "mem-" + strconv .Itoa (int (time .Now ().Unix ()))+ ".prof" ))
17
+
18
+ defer f .Close ()
19
+
20
+ if err != nil {
21
+ log .WithError (err ).WithFields (log.Fields {
22
+ "context" : "pprof" ,
23
+ }).Error ("error creating mem.prof" )
24
+ http .Error (w , err .Error (), http .StatusInternalServerError )
25
+ return
26
+ }
27
+
28
+ err = pprof .WriteHeapProfile (f )
29
+
30
+ if err != nil {
31
+ log .WithError (err ).WithFields (log.Fields {
32
+ "context" : "pprof" ,
33
+ }).Error ("Failed to write memory profile" )
34
+ http .Error (w , err .Error (), http .StatusInternalServerError )
35
+ return
36
+ }
37
+
38
+ w .WriteHeader (http .StatusNoContent )
39
+ }
Original file line number Diff line number Diff line change 4
4
"bytes"
5
5
"embed"
6
6
"fmt"
7
+ "github.com/semaphoreui/semaphore/api/debug"
7
8
"github.com/semaphoreui/semaphore/pkg/tz"
8
9
"net/http"
9
10
"os"
@@ -147,6 +148,10 @@ func Route() *mux.Router {
147
148
148
149
adminAPI .Path ("/cache" ).HandlerFunc (clearCache ).Methods ("DELETE" , "HEAD" )
149
150
151
+ debugAPI := adminAPI .PathPrefix ("/debug" ).Subrouter ()
152
+ debugAPI .Path ("/gc" ).HandlerFunc (debug .GC ).Methods ("POST" )
153
+ debugAPI .Path ("/pprof/dump" ).HandlerFunc (debug .Dump ).Methods ("POST" )
154
+
150
155
globalRunnersAPI := adminAPI .PathPrefix ("/runners" ).Subrouter ()
151
156
globalRunnersAPI .Use (globalRunnerMiddleware )
152
157
globalRunnersAPI .Path ("/{runner_id}" ).HandlerFunc (getGlobalRunner ).Methods ("GET" , "HEAD" )
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ package cmd
2
2
3
3
import (
4
4
"fmt"
5
- "github.com/semaphoreui/semaphore/services/profiling"
6
5
"net/http"
7
6
"net/url"
8
7
"os"
@@ -84,7 +83,6 @@ func runService() {
84
83
go sockets .StartWS ()
85
84
go schedulePool .Run ()
86
85
go taskPool .Run ()
87
- go profiling .StartProfiling ()
88
86
89
87
route := api .Route ()
90
88
Original file line number Diff line number Diff line change 23
23
- name : integration
24
24
description : Integration API
25
25
paths :
26
+ /debug/gc :
27
+ post :
28
+ summary : Garbage collector
29
+ description : Run the garbage collector
30
+ responses :
31
+ ' 204 ' :
32
+ description : Successful "OK" reply
33
+
34
+ /debug/pprof/dump :
35
+ post :
36
+ summary : Dump pprof
37
+ description : Dump pprof
38
+ responses :
39
+ ' 204 ' :
40
+ description : Successful "OK" reply
41
+
26
42
" /ping " :
27
43
get :
28
44
summary : PING test
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -208,8 +208,8 @@ type ScheduleConfig struct {
208
208
}
209
209
210
210
type ProfilingConfig struct {
211
- Enabled bool `json:"enabled,omitempty" env:"SEMAPHORE_PROFILING_ENABLED"`
212
- Port int `json:"port ,omitempty" env:"SEMAPHORE_PROFILING_PORT " default:"6060 "`
211
+ Enabled bool `json:"enabled,omitempty" env:"SEMAPHORE_PROFILING_ENABLED"`
212
+ DumpsDir string `json:"dumps_dir ,omitempty" env:"SEMAPHORE_PROFILING_DUMPS_DIR " default:"/tmp/semaphore/profiler "`
213
213
}
214
214
215
215
// ConfigType mapping between Config and the json file that sets it
You can’t perform that action at this time.
0 commit comments