Просмотр исходного кода

Log additional metrics for remote server list downloads

- Log bytes transferred and download duration.
- Add duration to NoticeRemoteServerListResourceDownloadedBytes.
- Additional metrics may be used to calculate transfer
  rates. Logging base values enables excluding outliers.
Rod Hynes 5 лет назад
Родитель
Сommit
eb144551bb
4 измененных файлов с 31 добавлено и 16 удалено
  1. 4 3
      psiphon/notice.go
  2. 7 3
      psiphon/remoteServerList.go
  3. 8 6
      psiphon/server/api.go
  4. 12 4
      psiphon/serverApi.go

+ 4 - 3
psiphon/notice.go

@@ -745,14 +745,15 @@ func NoticeExiting() {
 }
 }
 
 
 // NoticeRemoteServerListResourceDownloadedBytes reports remote server list download progress.
 // NoticeRemoteServerListResourceDownloadedBytes reports remote server list download progress.
-func NoticeRemoteServerListResourceDownloadedBytes(url string, bytes int64) {
+func NoticeRemoteServerListResourceDownloadedBytes(url string, bytes int64, duration time.Duration) {
 	if !GetEmitNetworkParameters() {
 	if !GetEmitNetworkParameters() {
 		url = "[redacted]"
 		url = "[redacted]"
 	}
 	}
 	singletonNoticeLogger.outputNotice(
 	singletonNoticeLogger.outputNotice(
 		"RemoteServerListResourceDownloadedBytes", noticeIsDiagnostic,
 		"RemoteServerListResourceDownloadedBytes", noticeIsDiagnostic,
 		"url", url,
 		"url", url,
-		"bytes", bytes)
+		"bytes", bytes,
+		"duration", duration.String())
 }
 }
 
 
 // NoticeRemoteServerListResourceDownloaded indicates that a remote server list download
 // NoticeRemoteServerListResourceDownloaded indicates that a remote server list download
@@ -843,7 +844,7 @@ func NoticePruneServerEntry(serverEntryTag string) {
 func NoticeEstablishTunnelTimeout(timeout time.Duration) {
 func NoticeEstablishTunnelTimeout(timeout time.Duration) {
 	singletonNoticeLogger.outputNotice(
 	singletonNoticeLogger.outputNotice(
 		"EstablishTunnelTimeout", 0,
 		"EstablishTunnelTimeout", 0,
-		"timeout", timeout)
+		"timeout", timeout.String())
 }
 }
 
 
 func NoticeFragmentor(diagnosticID string, message string) {
 func NoticeFragmentor(diagnosticID string, message string) {

+ 7 - 3
psiphon/remoteServerList.go

@@ -460,7 +460,9 @@ func downloadRemoteServerListFile(
 		return "", nil, errors.Trace(err)
 		return "", nil, errors.Trace(err)
 	}
 	}
 
 
-	n, responseETag, err := ResumeDownload(
+	startTime := time.Now()
+
+	bytes, responseETag, err := ResumeDownload(
 		ctx,
 		ctx,
 		httpClient,
 		httpClient,
 		sourceURL,
 		sourceURL,
@@ -468,7 +470,9 @@ func downloadRemoteServerListFile(
 		destinationFilename,
 		destinationFilename,
 		lastETag)
 		lastETag)
 
 
-	NoticeRemoteServerListResourceDownloadedBytes(sourceURL, n)
+	duration := time.Since(startTime)
+
+	NoticeRemoteServerListResourceDownloadedBytes(sourceURL, bytes, duration)
 
 
 	if err != nil {
 	if err != nil {
 		return "", nil, errors.Trace(err)
 		return "", nil, errors.Trace(err)
@@ -482,7 +486,7 @@ func downloadRemoteServerListFile(
 
 
 	downloadStatRecorder := func(authenticated bool) {
 	downloadStatRecorder := func(authenticated bool) {
 		_ = RecordRemoteServerListStat(
 		_ = RecordRemoteServerListStat(
-			config, tunneled, sourceURL, responseETag, authenticated)
+			config, tunneled, sourceURL, responseETag, bytes, duration, authenticated)
 	}
 	}
 
 
 	return responseETag, downloadStatRecorder, nil
 	return responseETag, downloadStatRecorder, nil

+ 8 - 6
psiphon/server/api.go

@@ -466,6 +466,8 @@ var remoteServerListStatParams = append(
 		{"tunneled", isBooleanFlag, requestParamOptional | requestParamLogFlagAsBool},
 		{"tunneled", isBooleanFlag, requestParamOptional | requestParamLogFlagAsBool},
 		{"url", isAnyString, 0},
 		{"url", isAnyString, 0},
 		{"etag", isAnyString, 0},
 		{"etag", isAnyString, 0},
+		{"bytes", isIntString, requestParamOptional | requestParamLogStringAsInt},
+		{"duration", isIntString, requestParamOptional | requestParamLogStringAsInt},
 		{"authenticated", isBooleanFlag, requestParamOptional | requestParamLogFlagAsBool}},
 		{"authenticated", isBooleanFlag, requestParamOptional | requestParamLogFlagAsBool}},
 	baseSessionParams...)
 	baseSessionParams...)
 
 
@@ -491,12 +493,12 @@ var failedTunnelStatParams = append(
 		{"session_id", isHexDigits, 0},
 		{"session_id", isHexDigits, 0},
 		{"last_connected", isLastConnected, 0},
 		{"last_connected", isLastConnected, 0},
 		{"client_failed_timestamp", isISO8601Date, 0},
 		{"client_failed_timestamp", isISO8601Date, 0},
-		{"liveness_test_upstream_bytes", isIntString, requestParamOptional},
-		{"liveness_test_sent_upstream_bytes", isIntString, requestParamOptional},
-		{"liveness_test_downstream_bytes", isIntString, requestParamOptional},
-		{"liveness_test_received_downstream_bytes", isIntString, requestParamOptional},
-		{"bytes_up", isIntString, requestParamOptional},
-		{"bytes_down", isIntString, requestParamOptional},
+		{"liveness_test_upstream_bytes", isIntString, requestParamOptional | requestParamLogStringAsInt},
+		{"liveness_test_sent_upstream_bytes", isIntString, requestParamOptional | requestParamLogStringAsInt},
+		{"liveness_test_downstream_bytes", isIntString, requestParamOptional | requestParamLogStringAsInt},
+		{"liveness_test_received_downstream_bytes", isIntString, requestParamOptional | requestParamLogStringAsInt},
+		{"bytes_up", isIntString, requestParamOptional | requestParamLogStringAsInt},
+		{"bytes_down", isIntString, requestParamOptional | requestParamLogStringAsInt},
 		{"tunnel_error", isAnyString, 0}},
 		{"tunnel_error", isAnyString, 0}},
 	baseSessionAndDialParams...)
 	baseSessionAndDialParams...)
 
 

+ 12 - 4
psiphon/serverApi.go

@@ -33,6 +33,7 @@ import (
 	"net/url"
 	"net/url"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
+	"time"
 
 
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo"
@@ -383,9 +384,9 @@ func (serverContext *ServerContext) DoConnectedRequest() error {
 
 
 	params["last_connected"] = lastConnected
 	params["last_connected"] = lastConnected
 
 
-	// serverContext.tunnel.establishDuration is nanoseconds; divide to get to milliseconds
+	// serverContext.tunnel.establishDuration is nanoseconds; report milliseconds
 	params["establishment_duration"] =
 	params["establishment_duration"] =
-		fmt.Sprintf("%d", serverContext.tunnel.establishDuration/1000000)
+		fmt.Sprintf("%d", serverContext.tunnel.establishDuration/time.Millisecond)
 
 
 	var response []byte
 	var response []byte
 	if serverContext.psiphonHttpsClient == nil {
 	if serverContext.psiphonHttpsClient == nil {
@@ -628,6 +629,8 @@ func RecordRemoteServerListStat(
 	tunneled bool,
 	tunneled bool,
 	url string,
 	url string,
 	etag string,
 	etag string,
+	bytes int64,
+	duration time.Duration,
 	authenticated bool) error {
 	authenticated bool) error {
 
 
 	if !config.GetClientParameters().Get().WeightedCoinFlip(
 	if !config.GetClientParameters().Get().WeightedCoinFlip(
@@ -655,6 +658,11 @@ func RecordRemoteServerListStat(
 	params["tunneled"] = tunneledStr
 	params["tunneled"] = tunneledStr
 	params["url"] = url
 	params["url"] = url
 	params["etag"] = etag
 	params["etag"] = etag
+	params["bytes"] = fmt.Sprintf("%d", bytes)
+
+	// duration is nanoseconds; report milliseconds
+	params["duration"] = fmt.Sprintf("%d", duration/time.Millisecond)
+
 	authenticatedStr := "0"
 	authenticatedStr := "0"
 	if authenticated {
 	if authenticated {
 		authenticatedStr = "1"
 		authenticatedStr = "1"
@@ -964,8 +972,8 @@ func getBaseAPIParameters(
 			params["egress_region"] = config.EgressRegion
 			params["egress_region"] = config.EgressRegion
 		}
 		}
 
 
-		// dialParams.DialDuration is nanoseconds; divide to get to milliseconds
-		params["dial_duration"] = fmt.Sprintf("%d", dialParams.DialDuration/1000000)
+		// dialParams.DialDuration is nanoseconds; report milliseconds
+		params["dial_duration"] = fmt.Sprintf("%d", dialParams.DialDuration/time.Millisecond)
 
 
 		params["candidate_number"] = strconv.Itoa(dialParams.CandidateNumber)
 		params["candidate_number"] = strconv.Itoa(dialParams.CandidateNumber)