-
Notifications
You must be signed in to change notification settings - Fork 108
Add Archive source option #841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2585,6 +2585,39 @@ private static async Task RetrieveSourceAsync(Source source, string destinationF | |||||||||||||||||||||||||||
| await Git.InitSubModulesAsync(targetDir); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| else if (!String.IsNullOrEmpty(source.Archive)) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| // If archive is remote, download it first | ||||||||||||||||||||||||||||
| var archivePath = source.Archive; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (archivePath.StartsWith("http", StringComparison.OrdinalIgnoreCase)) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| var tempArchive = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".zip"); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| Log.Info($"Downloading archive from '{archivePath}' to '{tempArchive}'"); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| var ok = await DownloadFileAsync(archivePath, tempArchive, maxRetries: 3, timeout: 60, throwOnError: true); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (!ok) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| throw new InvalidOperationException($"Could not download archive from {archivePath}"); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| ZipFile.ExtractToDirectory(tempArchive, targetDir); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| try { File.Delete(tempArchive); } catch { } | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| try { File.Delete(tempArchive); } catch { } | |
| try | |
| { | |
| File.Delete(tempArchive); | |
| } | |
| catch (IOException ex) | |
| { | |
| Log.Warning(ex, $"Failed to delete temporary archive file '{tempArchive}' due to IO error."); | |
| } | |
| catch (UnauthorizedAccessException ex) | |
| { | |
| Log.Warning(ex, $"Failed to delete temporary archive file '{tempArchive}' due to insufficient permissions."); | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ public class Source | |
| public string Repository { get; set; } | ||
| public bool InitSubmodules { get; set; } | ||
| public string LocalFolder { get; set; } | ||
| public string Archive { get; set; } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: spacing |
||
|
|
||
| /// <summary> | ||
| /// When set, will specify where the source data will be copied to on the agent. | ||
|
|
@@ -65,7 +66,8 @@ public SourceKeyData GetSourceKeyData() | |
| BranchOrCommit = BranchOrCommit, | ||
| Repository = Repository, | ||
| InitSubmodules = InitSubmodules, | ||
| LocalFolder = LocalFolder | ||
| LocalFolder = LocalFolder, | ||
| Archive = Archive | ||
| }; | ||
| } | ||
| } | ||
|
|
@@ -79,5 +81,6 @@ public class SourceKeyData | |
| public string Repository { get; set; } | ||
| public bool InitSubmodules { get; set; } | ||
| public string LocalFolder { get; set; } | ||
| public string Archive { get; set; } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -81,6 +81,52 @@ public async Task BenchmarkHello() | |||||||||||||||||||
| Assert.Contains("ASP.NET Core Version", result.StandardOutput); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| [Fact] | ||||||||||||||||||||
| public async Task BenchmarkHelloArchive() | ||||||||||||||||||||
| { | ||||||||||||||||||||
| _output.WriteLine($"[TEST] Starting controller (archive)"); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Create a zip next to the hello folder called hello.zip and use the permanent config | ||||||||||||||||||||
| var assetsDir = Path.Combine(_crankTestsDirectory, "assets"); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // The original config references ../hello relative to the assets file | ||||||||||||||||||||
| var helloFolder = Path.GetFullPath(Path.Combine(assetsDir, "..", "hello")); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Assert.True(Directory.Exists(helloFolder), $"Expected hello folder at {helloFolder}"); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| var helloZip = Path.GetFullPath(Path.Combine(assetsDir, "..", "hello.zip")); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (File.Exists(helloZip)) File.Delete(helloZip); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| System.IO.Compression.ZipFile.CreateFromDirectory(helloFolder, helloZip, System.IO.Compression.CompressionLevel.Fastest, includeBaseDirectory: false); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| var configPath = Path.Combine(_crankTestsDirectory, "assets", "hello-archive.benchmarks.yml"); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| try | ||||||||||||||||||||
| { | ||||||||||||||||||||
| var result = await ProcessUtil.RunAsync( | ||||||||||||||||||||
| "dotnet", | ||||||||||||||||||||
| $"exec {Path.Combine(_crankDirectory, "crank.dll")} --config {configPath} --scenario hello --profile local", | ||||||||||||||||||||
| workingDirectory: _crankTestsDirectory, | ||||||||||||||||||||
| captureOutput: true, | ||||||||||||||||||||
| timeout: DefaultTimeOut, | ||||||||||||||||||||
| throwOnError: false, | ||||||||||||||||||||
| outputDataReceived: t => { _output.WriteLine($"[CTL] {t}"); } | ||||||||||||||||||||
| ); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Assert.Equal(0, result.ExitCode); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Assert.Contains("Requests/sec", result.StandardOutput); | ||||||||||||||||||||
| Assert.Contains(".NET Core SDK Version", result.StandardOutput); | ||||||||||||||||||||
| Assert.Contains(".NET Runtime Version", result.StandardOutput); | ||||||||||||||||||||
| Assert.Contains("ASP.NET Core Version", result.StandardOutput); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| finally | ||||||||||||||||||||
| { | ||||||||||||||||||||
| try { File.Delete(helloZip); } catch { } | ||||||||||||||||||||
|
||||||||||||||||||||
| try { File.Delete(helloZip); } catch { } | |
| try | |
| { | |
| File.Delete(helloZip); | |
| } | |
| catch (Exception ex) | |
| { | |
| _output.WriteLine($"[CLEANUP] Failed to delete {helloZip}: {ex.GetType().Name}: {ex.Message}"); | |
| } |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be an extra or unsaved file. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| jobs: | ||
| server: | ||
| sources: | ||
| hello: | ||
| archive: '../hello.zip' | ||
| project: hello/hello.csproj | ||
| readyStateText: Application started. | ||
| bombardier: | ||
| sources: | ||
| local: | ||
| # uploading the whole source folder since it requires other libraries | ||
| localFolder: '../src' | ||
| destinationFolder: '' | ||
| project: Microsoft.Crank.Jobs.Bombardier/Microsoft.Crank.Jobs.Bombardier.csproj | ||
| readyStateText: Bombardier Client | ||
| waitForExit: true | ||
| variables: | ||
| connections: 256 | ||
| warmup: 3 | ||
| duration: 3 | ||
| requests: 0 | ||
| rate: 0 | ||
| transport: fasthttp # | http1 | http2 | ||
| serverScheme: http | ||
| serverAddress: localhost | ||
| serverPort: 5000 | ||
| customHeaders: [ ] # list of headers with the format: '<name1>: <value1>', e.g. [ 'content-type: application/json' ] | ||
| arguments: "-c {{connections}} -w {{warmup}} -d {{duration}} -n {{requests}} --insecure -l {% if rate != 0 %} --rate {{ rate }} {% endif %} {% if transport %} --{{ transport}} {% endif %} {{headers[presetHeaders]}} {% for h in customHeaders %}{% assign s = h | split : ':' %}--header \"{{ s[0] }}: {{ s[1] | strip }}\" {% endfor %} {{serverScheme}}://{{serverAddress}}:{{serverPort}}{{path}}" | ||
|
|
||
| scenarios: | ||
| hello: | ||
| application: | ||
| job: server | ||
| load: | ||
| job: bombardier | ||
| variables: | ||
| path: / | ||
|
|
||
| profiles: | ||
| local: | ||
| variables: | ||
| serverPort: 5000 | ||
| serverAddress: localhost | ||
| jobs: | ||
| application: | ||
| endpoints: | ||
| - http://localhost:5010 | ||
| load: | ||
| endpoints: | ||
| - http://localhost:5010 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Path.GetRandomFileName() for temporary files can create predictable filenames. Consider using Path.GetTempFileName() which creates a unique temporary file with proper permissions, or use a cryptographically secure random generator for the filename.