Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Log long stages of cache population (#49)
Browse files Browse the repository at this point in the history
* Log long stages of cache population

* Fixed linting issues
  • Loading branch information
fkorotkov committed Oct 7, 2020
1 parent ec41fbb commit 7211cde
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/executor/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func tryToDownloadAndPopulateCache(
return false, false
}
_, _ = logUploader.Write([]byte(fmt.Sprintf("\nCache hit for %s!", cacheKey)))
unarchiveStartTime := time.Now()
err = unarchiveCache(cacheFile, folderToCache)
if err != nil {
logUploader.Write([]byte(fmt.Sprintf("\nFailed to unarchive %s cache because of %s! Retrying...\n", commandName, err)))
Expand All @@ -144,6 +145,11 @@ func tryToDownloadAndPopulateCache(
EnsureFolderExists(folderToCache)
return false, true
}
} else {
unarchiveDuration := time.Since(unarchiveStartTime)
if unarchiveDuration > 10*time.Second {
logUploader.Write([]byte(fmt.Sprintf("\nUnarchived %s cache entry in %f seconds!\n", commandName, unarchiveDuration.Seconds())))
}
}
return true, true
}
Expand All @@ -168,6 +174,7 @@ func FetchCache(logUploader *LogUploader, commandName string, cacheHost string,
httpClient := http.Client{
Timeout: 5 * time.Minute,
}
downloadStartTime := time.Now()
resp, err := httpClient.Get(fmt.Sprintf("http://%s/%s", cacheHost, cacheKey))
if err != nil {
return nil, err
Expand All @@ -187,12 +194,13 @@ func FetchCache(logUploader *LogUploader, commandName string, cacheHost string,
if err != nil {
return nil, err
}
downloadDuration := time.Since(downloadStartTime)
if bytesDownloaded < 1024 {
logUploader.Write([]byte(fmt.Sprintf("\nDownloaded %d bytes.", bytesDownloaded)))
} else if bytesDownloaded < 1024*1024 {
logUploader.Write([]byte(fmt.Sprintf("\nDownloaded %dKb.", bytesDownloaded/1024)))
} else {
logUploader.Write([]byte(fmt.Sprintf("\nDownloaded %dMb.", bytesDownloaded/1024/1024)))
logUploader.Write([]byte(fmt.Sprintf("\nDownloaded %dMb in %fs.", bytesDownloaded/1024/1024, downloadDuration.Seconds())))
}
return cacheFile, nil
}
Expand Down

0 comments on commit 7211cde

Please sign in to comment.