Преглед изворни кода

Include failed_tunnel probability in event log

Rod Hynes пре 3 година
родитељ
комит
ac4735b6e6
3 измењених фајлова са 11 додато и 5 уклоњено
  1. 1 1
      psiphon/server/api.go
  2. 1 1
      psiphon/server/server_test.go
  3. 9 3
      psiphon/serverApi.go

+ 1 - 1
psiphon/server/api.go

@@ -59,7 +59,6 @@ const (
 // psi_web protocol and naming conventions. The API is compatible with
 // all tunnel-core clients but are not backwards compatible with all
 // legacy clients.
-//
 func sshAPIRequestHandler(
 	support *SupportServices,
 	clientAddr string,
@@ -549,6 +548,7 @@ var failedTunnelStatParams = append(
 		{"session_id", isHexDigits, 0},
 		{"last_connected", isLastConnected, 0},
 		{"client_failed_timestamp", isISO8601Date, 0},
+		{"record_probability", isFloatString, requestParamOptional | requestParamLogStringAsFloat},
 		{"liveness_test_upstream_bytes", isIntString, requestParamOptional | requestParamLogStringAsInt},
 		{"liveness_test_sent_upstream_bytes", isIntString, requestParamOptional | requestParamLogStringAsInt},
 		{"liveness_test_downstream_bytes", isIntString, requestParamOptional | requestParamLogStringAsInt},

+ 1 - 1
psiphon/server/server_test.go

@@ -1536,7 +1536,7 @@ func runServer(t *testing.T, runConfig *runServerConfig) {
 		// after the SLOK notice.
 		select {
 		case <-untunneledPortForward:
-			t.Fatalf("unexpected untunnedl port forward")
+			t.Fatalf("unexpected untunneled port forward")
 		default:
 		}
 	}

+ 9 - 3
psiphon/serverApi.go

@@ -741,8 +741,10 @@ func RecordFailedTunnelStat(
 	bytesDown int64,
 	tunnelErr error) error {
 
-	if !config.GetParameters().Get().WeightedCoinFlip(
-		parameters.RecordFailedTunnelPersistentStatsProbability) {
+	probability := config.GetParameters().Get().Float(
+		parameters.RecordFailedTunnelPersistentStatsProbability)
+
+	if !prng.FlipWeightedCoin(probability) {
 		return nil
 	}
 
@@ -780,11 +782,15 @@ func RecordFailedTunnelStat(
 		params["bytes_down"] = fmt.Sprintf("%d", bytesDown)
 	}
 
+	// Log RecordFailedTunnelPersistentStatsProbability to indicate the
+	// proportion of failed tunnel events being recorded at the time of
+	// this log event.
+	params["record_probability"] = fmt.Sprintf("%f", probability)
+
 	// Ensure direct server IPs are not exposed in logs. The "net" package, and
 	// possibly other 3rd party packages, will include destination addresses in
 	// I/O error messages.
 	tunnelError := common.RedactIPAddressesString(tunnelErr.Error())
-
 	params["tunnel_error"] = tunnelError
 
 	failedTunnelStatJson, err := json.Marshal(params)