Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/SeqCli/Cli/Commands/Sample/IngestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class IngestCommand : Command
readonly BatchSizeFeature _batchSize;

bool _quiet;
bool _setup;
int _simulations = 1;

public IngestCommand(SeqConnectionFactory connectionFactory)
Expand All @@ -41,6 +42,7 @@ public IngestCommand(SeqConnectionFactory connectionFactory)
_connection = Enable<ConnectionFeature>();

Options.Add("quiet", "Don't echo ingested events to `STDOUT`", _ => _quiet = true);
Options.Add("setup", "Configure sample dashboards, signals, users, and so on before starting ingestion", _ => _setup = true);
Options.Add("simulations=", "Number of concurrent simulations to run; the default runs a single simulation",
v => _simulations = int.Parse(v));

Expand All @@ -51,14 +53,27 @@ protected override async Task<int> Run()
{
var (url, apiKey) = _connectionFactory.GetConnectionDetails(_connection);
var batchSize = _batchSize.Value;

if (!_confirm.TryConfirm($"This will send sample events to the Seq server at {url}."))
{

if (!_confirm.TryConfirm(_setup
? $"This will apply sample configuration and send sample events to the Seq server at {url}."
: $"This will send sample events to the Seq server at {url}."
)) {
await Console.Error.WriteLineAsync("Canceled by user.");
return 1;
}

var connection = _connectionFactory.Connect(_connection);

if (_setup)
{
var setupResult = await SetupCommand.ImportTemplates(connection);

if (setupResult != 0)
{
return setupResult;
}
}

var simulations = Enumerable.Range(0, _simulations)
.Select(_ => Simulation.RunAsync(connection, apiKey, batchSize, echoToStdout: !_quiet))
.ToList();
Expand Down
6 changes: 6 additions & 0 deletions src/SeqCli/Cli/Commands/Sample/SetupCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using SeqCli.Templates.Ast;
using SeqCli.Templates.Import;
using SeqCli.Util;
using Seq.Api;

// ReSharper disable once UnusedType.Global

Expand Down Expand Up @@ -58,6 +59,11 @@ protected override async Task<int> Run()
return 1;
}

return await ImportTemplates(connection);
}

internal static async Task<int> ImportTemplates(SeqConnection connection)
{
var templateArgs = new Dictionary<string, JsonTemplate>();
templateArgs["ownerId"] = new JsonTemplateNull();

Expand Down
32 changes: 32 additions & 0 deletions test/SeqCli.EndToEnd/Sample/SampleIngestTestCase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Seq.Api;
using SeqCli.EndToEnd.Support;
using Serilog;
using Xunit;

namespace SeqCli.EndToEnd.Sample;

public class SampleIngestTestCase : ICliTestCase
{
public async Task ExecuteAsync(SeqConnection connection, ILogger logger, CliCommandRunner runner)
{
try
{
runner.Exec("sample ingest", "--setup --confirm", timeout: TimeSpan.FromSeconds(3));
}
catch
{
// Ignored
}

var events = await connection.Events.ListAsync();
Assert.NotEmpty(events);

var sampleWorkspace = (await connection.Workspaces.ListAsync(shared: true))
.SingleOrDefault(w => w.Title == "Sample");

Assert.NotNull(sampleWorkspace);
}
}
4 changes: 2 additions & 2 deletions test/SeqCli.EndToEnd/Support/CliCommandRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public class CliCommandRunner(TestConfiguration configuration)

public ITestProcess? LastRunProcess { get; private set; }

public int Exec(string command, string? args = null, bool disconnected = false)
public int Exec(string command, string? args = null, bool disconnected = false, TimeSpan? timeout = null)
{
using var process = configuration.SpawnCliProcess(command, args, skipServerArg: disconnected);
LastRunProcess = process;
return process.WaitForExit(DefaultExecTimeout);
return process.WaitForExit(timeout ?? DefaultExecTimeout);
}
}