Skip to content

Commit

Permalink
Add 5s timeout to request upload, set debug logging to a configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
features-not-bugs committed Feb 23, 2021
1 parent 789e23e commit a3ed07a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/RustServerMetrics/Config/ConfigData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ class ConfigData

[JsonProperty(PropertyName = "Server Tag")]
public string serverTag = DEFAULT_SERVER_TAG;

[JsonProperty(PropertyName = "Debug Logging")]
public bool debugLogging = true;
}
}
1 change: 1 addition & 0 deletions src/RustServerMetrics/MetricsLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class MetricsLogger : SingletonComponent<MetricsLogger>
Message.Type _lastMessageType;
Uri _baseUri;

public bool DebugLogging => _configuration?.debugLogging == true;
public Uri BaseUri
{
get
Expand Down
11 changes: 7 additions & 4 deletions src/RustServerMetrics/ReportUploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,18 @@ IEnumerator SendRequest()
var request = new UnityWebRequest(_uri, UnityWebRequest.kHttpVerbPOST)
{
uploadHandler = new UploadHandlerRaw(_data),
downloadHandler = new DownloadHandlerBuffer()
downloadHandler = new DownloadHandlerBuffer(),
timeout = 5,
useHttpContinue = true,
redirectLimit = 5
};
yield return request.SendWebRequest();

if (request.isNetworkError)
{
if (_attempt >= 5)
if (_attempt >= 2)
{
Debug.LogError($"Error submitting metric: 5 consecutive network failures");
Debug.LogError($"Error submitting metric: 2 consecutive network failures");
yield break;
}

Expand All @@ -93,7 +96,7 @@ IEnumerator SendRequest()
if (request.isHttpError)
{
Debug.LogError($"Error submitting metric: {request.error}");
Debug.LogError(request.downloadHandler.text);
if (_metricsLogger.DebugLogging) Debug.LogError(request.downloadHandler.text);
yield break;
}
}
Expand Down

0 comments on commit a3ed07a

Please sign in to comment.