Skip to content

Commit 16a906f

Browse files
authored
Merge pull request #388 from KodrAus/feat/sample-ingest-setup
Add a --setup flag to sample ingest
2 parents 4a363f5 + 2c981a6 commit 16a906f

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
lines changed

src/SeqCli/Cli/Commands/Sample/IngestCommand.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class IngestCommand : Command
3232
readonly BatchSizeFeature _batchSize;
3333

3434
bool _quiet;
35+
bool _setup;
3536
int _simulations = 1;
3637

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

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

@@ -51,14 +53,27 @@ protected override async Task<int> Run()
5153
{
5254
var (url, apiKey) = _connectionFactory.GetConnectionDetails(_connection);
5355
var batchSize = _batchSize.Value;
54-
55-
if (!_confirm.TryConfirm($"This will send sample events to the Seq server at {url}."))
56-
{
56+
57+
if (!_confirm.TryConfirm(_setup
58+
? $"This will apply sample configuration and send sample events to the Seq server at {url}."
59+
: $"This will send sample events to the Seq server at {url}."
60+
)) {
5761
await Console.Error.WriteLineAsync("Canceled by user.");
5862
return 1;
5963
}
6064

6165
var connection = _connectionFactory.Connect(_connection);
66+
67+
if (_setup)
68+
{
69+
var setupResult = await SetupCommand.ImportTemplates(connection);
70+
71+
if (setupResult != 0)
72+
{
73+
return setupResult;
74+
}
75+
}
76+
6277
var simulations = Enumerable.Range(0, _simulations)
6378
.Select(_ => Simulation.RunAsync(connection, apiKey, batchSize, echoToStdout: !_quiet))
6479
.ToList();

src/SeqCli/Cli/Commands/Sample/SetupCommand.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using SeqCli.Templates.Ast;
2323
using SeqCli.Templates.Import;
2424
using SeqCli.Util;
25+
using Seq.Api;
2526

2627
// ReSharper disable once UnusedType.Global
2728

@@ -58,6 +59,11 @@ protected override async Task<int> Run()
5859
return 1;
5960
}
6061

62+
return await ImportTemplates(connection);
63+
}
64+
65+
internal static async Task<int> ImportTemplates(SeqConnection connection)
66+
{
6167
var templateArgs = new Dictionary<string, JsonTemplate>();
6268
templateArgs["ownerId"] = new JsonTemplateNull();
6369

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
using Seq.Api;
5+
using SeqCli.EndToEnd.Support;
6+
using Serilog;
7+
using Xunit;
8+
9+
namespace SeqCli.EndToEnd.Sample;
10+
11+
public class SampleIngestTestCase : ICliTestCase
12+
{
13+
public async Task ExecuteAsync(SeqConnection connection, ILogger logger, CliCommandRunner runner)
14+
{
15+
try
16+
{
17+
runner.Exec("sample ingest", "--setup --confirm", timeout: TimeSpan.FromSeconds(3));
18+
}
19+
catch
20+
{
21+
// Ignored
22+
}
23+
24+
var events = await connection.Events.ListAsync();
25+
Assert.NotEmpty(events);
26+
27+
var sampleWorkspace = (await connection.Workspaces.ListAsync(shared: true))
28+
.SingleOrDefault(w => w.Title == "Sample");
29+
30+
Assert.NotNull(sampleWorkspace);
31+
}
32+
}

test/SeqCli.EndToEnd/Support/CliCommandRunner.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ public class CliCommandRunner(TestConfiguration configuration)
1010

1111
public ITestProcess? LastRunProcess { get; private set; }
1212

13-
public int Exec(string command, string? args = null, bool disconnected = false)
13+
public int Exec(string command, string? args = null, bool disconnected = false, TimeSpan? timeout = null)
1414
{
1515
using var process = configuration.SpawnCliProcess(command, args, skipServerArg: disconnected);
1616
LastRunProcess = process;
17-
return process.WaitForExit(DefaultExecTimeout);
17+
return process.WaitForExit(timeout ?? DefaultExecTimeout);
1818
}
1919
}

0 commit comments

Comments
 (0)