Skip to content

Commit faca5b2

Browse files
committed
add a --setup flag to sample ingest
1 parent 4a363f5 commit faca5b2

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Linq;
2+
using System.Threading.Tasks;
3+
using Seq.Api;
4+
using SeqCli.EndToEnd.Support;
5+
using Serilog;
6+
using Xunit;
7+
8+
namespace SeqCli.EndToEnd.Sample;
9+
10+
public class SampleIngestTestCase : ICliTestCase
11+
{
12+
public async Task ExecuteAsync(SeqConnection connection, ILogger logger, CliCommandRunner runner)
13+
{
14+
runner.Exec("sample ingest", "--setup --confirm", timeout: TimeSpan.FromSeconds(3));
15+
16+
var sampleWorkspace = (await connection.Workspaces.ListAsync(shared: true))
17+
.SingleOrDefault(w => w.Title == "Sample");
18+
19+
Assert.NotNull(sampleWorkspace);
20+
}
21+
}

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)