Browse Source

Merge remote-tracking branch 'upstream/master'

Eugene Fryntov 9 năm trước cách đây
mục cha
commit
0e82819479

+ 3 - 2
Server/Dockerfile-binary-builder

@@ -8,10 +8,11 @@ RUN set -ex \
 		bash \
 		ca-certificates \
 		gcc \
-    git \
+		git \
+		go \
 		musl-dev \
 		openssl \
-		go \
+		perl \
 	\
 	&& export GOROOT_BOOTSTRAP="$(go env GOROOT)" \
 	\

+ 5 - 0
psiphon/common/buildinfo.go

@@ -63,6 +63,7 @@ type BuildInfo struct {
 
 // Convert 'BuildInfo' struct to 'map[string]interface{}'
 func (bi *BuildInfo) ToMap() *map[string]interface{} {
+
 	var dependenciesMap map[string]interface{}
 	json.Unmarshal([]byte(bi.Dependencies), &dependenciesMap)
 
@@ -79,6 +80,10 @@ func (bi *BuildInfo) ToMap() *map[string]interface{} {
 
 // Return an instance of the BuildInfo struct
 func GetBuildInfo() *BuildInfo {
+	if strings.TrimSpace(dependencies) == "" {
+		dependencies = "{}"
+	}
+
 	buildInfo := BuildInfo{
 		BuildDate:       strings.TrimSpace(buildDate),
 		BuildRepo:       strings.TrimSpace(buildRepo),

+ 4 - 0
psiphon/server/server_test.go

@@ -169,6 +169,10 @@ func runServer(t *testing.T, runConfig *runServerConfig) {
 	serverConfig.(map[string]interface{})["TrafficRulesFilename"] = ""
 	serverConfig.(map[string]interface{})["LogLevel"] = "debug"
 
+	// 1 second is the minimum period; should be small enough to emit a log during the
+	// test run, but not guaranteed
+	serverConfig.(map[string]interface{})["LoadMonitorPeriodSeconds"] = 1
+
 	serverConfigJSON, _ = json.Marshal(serverConfig)
 
 	// run server

+ 4 - 7
psiphon/server/services.go

@@ -153,7 +153,9 @@ func logServerLoad(server *TunnelServer) {
 	var memStats runtime.MemStats
 	runtime.ReadMemStats(&memStats)
 	fields := LogFields{
+		"event_type":   "server_load",
 		"BuildRev":     common.GetBuildInfo().BuildRev,
+		"HostID":       server.sshServer.support.Config.HostID,
 		"NumGoroutine": runtime.NumGoroutine(),
 		"MemStats": map[string]interface{}{
 			"Alloc":         memStats.Alloc,
@@ -168,15 +170,10 @@ func logServerLoad(server *TunnelServer) {
 
 	// tunnel server stats
 	for tunnelProtocol, stats := range server.GetLoadStats() {
-		tempMap := make(map[string]interface{})
-		for stat, value := range stats {
-			tempMap[stat] = value
-		}
-
-		fields[tunnelProtocol] = tempMap
+		fields[tunnelProtocol] = stats
 	}
 
-	log.WithContextFields(fields).Info("load")
+	log.LogRawFieldsWithTimestamp(fields)
 }
 
 // SupportServices carries common and shared data components

+ 11 - 0
psiphon/server/tunnelServer.go

@@ -385,6 +385,17 @@ func (sshServer *sshServer) getLoadStats() map[string]map[string]int64 {
 		client.Unlock()
 	}
 
+	// Calculate and report totals across all protocols. It's easier to do this here
+	// than futher down the stats stack. Also useful for glancing at log files.
+
+	allProtocolsStats := make(map[string]int64)
+	for _, stats := range loadStats {
+		for name, value := range stats {
+			allProtocolsStats[name] += value
+		}
+	}
+	loadStats["ALL"] = allProtocolsStats
+
 	return loadStats
 }