feat: Add RustFS artifact object store and migration tool
- Implemented RustFsArtifactObjectStore for managing artifacts in RustFS. - Added unit tests for RustFsArtifactObjectStore functionality. - Created a RustFS migrator tool to transfer objects from S3 to RustFS. - Introduced policy preview and report models for API integration. - Added fixtures and tests for policy preview and report functionality. - Included necessary metadata and scripts for cache_pkg package.
This commit is contained in:
		@@ -1,4 +1,6 @@
 | 
			
		||||
using System.Globalization;
 | 
			
		||||
using StellaOps.Bench.ScannerAnalyzers.Baseline;
 | 
			
		||||
using StellaOps.Bench.ScannerAnalyzers.Reporting;
 | 
			
		||||
using StellaOps.Bench.ScannerAnalyzers.Scenarios;
 | 
			
		||||
 | 
			
		||||
namespace StellaOps.Bench.ScannerAnalyzers;
 | 
			
		||||
@@ -15,8 +17,13 @@ internal static class Program
 | 
			
		||||
            var iterations = options.Iterations ?? config.Iterations ?? 5;
 | 
			
		||||
            var thresholdMs = options.ThresholdMs ?? config.ThresholdMs ?? 5000;
 | 
			
		||||
            var repoRoot = ResolveRepoRoot(options.RepoRoot, options.ConfigPath);
 | 
			
		||||
            var regressionLimit = options.RegressionLimit ?? 1.2d;
 | 
			
		||||
            var capturedAt = (options.CapturedAtUtc ?? DateTimeOffset.UtcNow).ToUniversalTime();
 | 
			
		||||
 | 
			
		||||
            var baseline = await LoadBaselineDictionaryAsync(options.BaselinePath, CancellationToken.None).ConfigureAwait(false);
 | 
			
		||||
 | 
			
		||||
            var results = new List<ScenarioResult>();
 | 
			
		||||
            var reports = new List<BenchmarkScenarioReport>();
 | 
			
		||||
            var failures = new List<string>();
 | 
			
		||||
 | 
			
		||||
            foreach (var scenario in config.Scenarios)
 | 
			
		||||
@@ -28,26 +35,54 @@ internal static class Program
 | 
			
		||||
                var stats = ScenarioStatistics.FromDurations(execution.Durations);
 | 
			
		||||
                var scenarioThreshold = scenario.ThresholdMs ?? thresholdMs;
 | 
			
		||||
 | 
			
		||||
                results.Add(new ScenarioResult(
 | 
			
		||||
                var result = new ScenarioResult(
 | 
			
		||||
                    scenario.Id!,
 | 
			
		||||
                    scenario.Label ?? scenario.Id!,
 | 
			
		||||
                    execution.SampleCount,
 | 
			
		||||
                    stats.MeanMs,
 | 
			
		||||
                    stats.P95Ms,
 | 
			
		||||
                    stats.MaxMs,
 | 
			
		||||
                    iterations));
 | 
			
		||||
                    iterations,
 | 
			
		||||
                    scenarioThreshold);
 | 
			
		||||
 | 
			
		||||
                results.Add(result);
 | 
			
		||||
 | 
			
		||||
                if (stats.MaxMs > scenarioThreshold)
 | 
			
		||||
                {
 | 
			
		||||
                    failures.Add($"{scenario.Id} exceeded threshold: {stats.MaxMs:F2} ms > {scenarioThreshold:F2} ms");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                baseline.TryGetValue(result.Id, out var baselineEntry);
 | 
			
		||||
                var report = new BenchmarkScenarioReport(result, baselineEntry, regressionLimit);
 | 
			
		||||
                if (report.BuildRegressionFailureMessage() is { } regressionFailure)
 | 
			
		||||
                {
 | 
			
		||||
                    failures.Add(regressionFailure);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                reports.Add(report);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            TablePrinter.Print(results);
 | 
			
		||||
 | 
			
		||||
            if (!string.IsNullOrWhiteSpace(options.OutPath))
 | 
			
		||||
            if (!string.IsNullOrWhiteSpace(options.CsvOutPath))
 | 
			
		||||
            {
 | 
			
		||||
                CsvWriter.Write(options.OutPath!, results);
 | 
			
		||||
                CsvWriter.Write(options.CsvOutPath!, results);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!string.IsNullOrWhiteSpace(options.JsonOutPath))
 | 
			
		||||
            {
 | 
			
		||||
                var metadata = new BenchmarkJsonMetadata(
 | 
			
		||||
                    "1.0",
 | 
			
		||||
                    capturedAt,
 | 
			
		||||
                    options.Commit,
 | 
			
		||||
                    options.Environment);
 | 
			
		||||
 | 
			
		||||
                await BenchmarkJsonWriter.WriteAsync(options.JsonOutPath!, metadata, reports, CancellationToken.None).ConfigureAwait(false);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!string.IsNullOrWhiteSpace(options.PrometheusOutPath))
 | 
			
		||||
            {
 | 
			
		||||
                PrometheusWriter.Write(options.PrometheusOutPath!, reports);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (failures.Count > 0)
 | 
			
		||||
@@ -71,6 +106,22 @@ internal static class Program
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static async Task<IReadOnlyDictionary<string, BaselineEntry>> LoadBaselineDictionaryAsync(string? baselinePath, CancellationToken cancellationToken)
 | 
			
		||||
    {
 | 
			
		||||
        if (string.IsNullOrWhiteSpace(baselinePath))
 | 
			
		||||
        {
 | 
			
		||||
            return new Dictionary<string, BaselineEntry>(StringComparer.OrdinalIgnoreCase);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var resolved = Path.GetFullPath(baselinePath);
 | 
			
		||||
        if (!File.Exists(resolved))
 | 
			
		||||
        {
 | 
			
		||||
            return new Dictionary<string, BaselineEntry>(StringComparer.OrdinalIgnoreCase);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return await BaselineLoader.LoadAsync(resolved, cancellationToken).ConfigureAwait(false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static string ResolveRepoRoot(string? overridePath, string configPath)
 | 
			
		||||
    {
 | 
			
		||||
        if (!string.IsNullOrWhiteSpace(overridePath))
 | 
			
		||||
@@ -108,15 +159,34 @@ internal static class Program
 | 
			
		||||
        return combined;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private sealed record ProgramOptions(string ConfigPath, int? Iterations, double? ThresholdMs, string? OutPath, string? RepoRoot)
 | 
			
		||||
    private sealed record ProgramOptions(
 | 
			
		||||
        string ConfigPath,
 | 
			
		||||
        int? Iterations,
 | 
			
		||||
        double? ThresholdMs,
 | 
			
		||||
        string? CsvOutPath,
 | 
			
		||||
        string? JsonOutPath,
 | 
			
		||||
        string? PrometheusOutPath,
 | 
			
		||||
        string? RepoRoot,
 | 
			
		||||
        string? BaselinePath,
 | 
			
		||||
        DateTimeOffset? CapturedAtUtc,
 | 
			
		||||
        string? Commit,
 | 
			
		||||
        string? Environment,
 | 
			
		||||
        double? RegressionLimit)
 | 
			
		||||
    {
 | 
			
		||||
        public static ProgramOptions Parse(string[] args)
 | 
			
		||||
        {
 | 
			
		||||
            var configPath = DefaultConfigPath();
 | 
			
		||||
            var baselinePath = DefaultBaselinePath();
 | 
			
		||||
            int? iterations = null;
 | 
			
		||||
            double? thresholdMs = null;
 | 
			
		||||
            string? outPath = null;
 | 
			
		||||
            string? csvOut = null;
 | 
			
		||||
            string? jsonOut = null;
 | 
			
		||||
            string? promOut = null;
 | 
			
		||||
            string? repoRoot = null;
 | 
			
		||||
            DateTimeOffset? capturedAt = null;
 | 
			
		||||
            string? commit = null;
 | 
			
		||||
            string? environment = null;
 | 
			
		||||
            double? regressionLimit = null;
 | 
			
		||||
 | 
			
		||||
            for (var index = 0; index < args.Length; index++)
 | 
			
		||||
            {
 | 
			
		||||
@@ -136,20 +206,50 @@ internal static class Program
 | 
			
		||||
                        thresholdMs = double.Parse(args[++index], CultureInfo.InvariantCulture);
 | 
			
		||||
                        break;
 | 
			
		||||
                    case "--out":
 | 
			
		||||
                    case "--csv":
 | 
			
		||||
                        EnsureNext(args, index);
 | 
			
		||||
                        outPath = args[++index];
 | 
			
		||||
                        csvOut = args[++index];
 | 
			
		||||
                        break;
 | 
			
		||||
                    case "--json":
 | 
			
		||||
                        EnsureNext(args, index);
 | 
			
		||||
                        jsonOut = args[++index];
 | 
			
		||||
                        break;
 | 
			
		||||
                    case "--prom":
 | 
			
		||||
                    case "--prometheus":
 | 
			
		||||
                        EnsureNext(args, index);
 | 
			
		||||
                        promOut = args[++index];
 | 
			
		||||
                        break;
 | 
			
		||||
                    case "--baseline":
 | 
			
		||||
                        EnsureNext(args, index);
 | 
			
		||||
                        baselinePath = args[++index];
 | 
			
		||||
                        break;
 | 
			
		||||
                    case "--repo-root":
 | 
			
		||||
                    case "--samples":
 | 
			
		||||
                        EnsureNext(args, index);
 | 
			
		||||
                        repoRoot = args[++index];
 | 
			
		||||
                        break;
 | 
			
		||||
                    case "--captured-at":
 | 
			
		||||
                        EnsureNext(args, index);
 | 
			
		||||
                        capturedAt = DateTimeOffset.Parse(args[++index], CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
 | 
			
		||||
                        break;
 | 
			
		||||
                    case "--commit":
 | 
			
		||||
                        EnsureNext(args, index);
 | 
			
		||||
                        commit = args[++index];
 | 
			
		||||
                        break;
 | 
			
		||||
                    case "--environment":
 | 
			
		||||
                        EnsureNext(args, index);
 | 
			
		||||
                        environment = args[++index];
 | 
			
		||||
                        break;
 | 
			
		||||
                    case "--regression-limit":
 | 
			
		||||
                        EnsureNext(args, index);
 | 
			
		||||
                        regressionLimit = double.Parse(args[++index], CultureInfo.InvariantCulture);
 | 
			
		||||
                        break;
 | 
			
		||||
                    default:
 | 
			
		||||
                        throw new ArgumentException($"Unknown argument: {current}", nameof(args));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return new ProgramOptions(configPath, iterations, thresholdMs, outPath, repoRoot);
 | 
			
		||||
            return new ProgramOptions(configPath, iterations, thresholdMs, csvOut, jsonOut, promOut, repoRoot, baselinePath, capturedAt, commit, environment, regressionLimit);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static string DefaultConfigPath()
 | 
			
		||||
@@ -160,6 +260,15 @@ internal static class Program
 | 
			
		||||
            return Path.Combine(configDirectory, "config.json");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static string? DefaultBaselinePath()
 | 
			
		||||
        {
 | 
			
		||||
            var binaryDir = AppContext.BaseDirectory;
 | 
			
		||||
            var projectRoot = Path.GetFullPath(Path.Combine(binaryDir, "..", "..", ".."));
 | 
			
		||||
            var benchRoot = Path.GetFullPath(Path.Combine(projectRoot, ".."));
 | 
			
		||||
            var baselinePath = Path.Combine(benchRoot, "baseline.csv");
 | 
			
		||||
            return File.Exists(baselinePath) ? baselinePath : baselinePath;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static void EnsureNext(string[] args, int index)
 | 
			
		||||
        {
 | 
			
		||||
            if (index + 1 >= args.Length)
 | 
			
		||||
@@ -169,15 +278,6 @@ internal static class Program
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private sealed record ScenarioResult(
 | 
			
		||||
        string Id,
 | 
			
		||||
        string Label,
 | 
			
		||||
        int SampleCount,
 | 
			
		||||
        double MeanMs,
 | 
			
		||||
        double P95Ms,
 | 
			
		||||
        double MaxMs,
 | 
			
		||||
        int Iterations);
 | 
			
		||||
 | 
			
		||||
    private sealed record ScenarioStatistics(double MeanMs, double P95Ms, double MaxMs)
 | 
			
		||||
    {
 | 
			
		||||
        public static ScenarioStatistics FromDurations(IReadOnlyList<double> durations)
 | 
			
		||||
@@ -232,25 +332,16 @@ internal static class Program
 | 
			
		||||
            Console.WriteLine("---------------------------- | ----- | --------- | --------- | ----------");
 | 
			
		||||
            foreach (var row in results)
 | 
			
		||||
            {
 | 
			
		||||
                Console.WriteLine(FormatRow(row));
 | 
			
		||||
                Console.WriteLine(string.Join(" | ", new[]
 | 
			
		||||
                {
 | 
			
		||||
                    row.IdColumn,
 | 
			
		||||
                    row.SampleCountColumn,
 | 
			
		||||
                    row.MeanColumn,
 | 
			
		||||
                    row.P95Column,
 | 
			
		||||
                    row.MaxColumn
 | 
			
		||||
                }));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static string FormatRow(ScenarioResult row)
 | 
			
		||||
        {
 | 
			
		||||
            var idColumn = row.Id.Length <= 28
 | 
			
		||||
                ? row.Id.PadRight(28)
 | 
			
		||||
                : row.Id[..28];
 | 
			
		||||
 | 
			
		||||
            return string.Join(" | ", new[]
 | 
			
		||||
            {
 | 
			
		||||
                idColumn,
 | 
			
		||||
                row.SampleCount.ToString(CultureInfo.InvariantCulture).PadLeft(5),
 | 
			
		||||
                row.MeanMs.ToString("F2", CultureInfo.InvariantCulture).PadLeft(9),
 | 
			
		||||
                row.P95Ms.ToString("F2", CultureInfo.InvariantCulture).PadLeft(9),
 | 
			
		||||
                row.MaxMs.ToString("F2", CultureInfo.InvariantCulture).PadLeft(10),
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static class CsvWriter
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user