Skip to content

Commit

Permalink
Implement metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaboxer committed Sep 27, 2024
1 parent ab6e3a0 commit 1d03c21
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Bloxstrap/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,9 @@ private async Task DownloadPackage(Package package)

const int maxTries = 5;

bool statIsRetrying = false;
bool statIsHttp = false;

App.Logger.WriteLine(LOG_IDENT, "Downloading...");

var buffer = new byte[4096];
Expand Down Expand Up @@ -1002,8 +1005,12 @@ private async Task DownloadPackage(Package package)
App.Logger.WriteLine(LOG_IDENT, $"An exception occurred after downloading {totalBytesRead} bytes. ({i}/{maxTries})");
App.Logger.WriteException(LOG_IDENT, ex);

statIsRetrying = true;

if (ex.GetType() == typeof(ChecksumFailedException))
{
_ = App.HttpClient.GetAsync($"http://bloxstraplabs.com/metrics/post?key=packageDownloadState&value=httpFail");

Frontend.ShowConnectivityDialog(
Strings.Dialog_Connectivity_UnableToDownload,
String.Format(Strings.Dialog_Connectivity_UnableToDownloadReason, "[https://github.com/pizzaboxer/bloxstrap/wiki/Bloxstrap-is-unable-to-download-Roblox](https://github.com/pizzaboxer/bloxstrap/wiki/Bloxstrap-is-unable-to-download-Roblox)"),
Expand All @@ -1029,9 +1036,16 @@ private async Task DownloadPackage(Package package)
{
App.Logger.WriteLine(LOG_IDENT, "Retrying download over HTTP...");
packageUrl = packageUrl.Replace("https://", "http://");
statIsHttp = true;
}
}
}

if (statIsRetrying)
{
string stat = statIsHttp ? "httpSuccess" : "retrySuccess";
_ = App.HttpClient.GetAsync($"http://bloxstraplabs.com/metrics/post?key=packageDownloadState&value={stat}");
}
}

private void ExtractPackage(Package package, List<string>? files = null)
Expand Down

0 comments on commit 1d03c21

Please sign in to comment.