Skip to content

Commit

Permalink
Merge pull request #312 from datalust/dev
Browse files Browse the repository at this point in the history
2024.1 Release
  • Loading branch information
nblumhardt authored Jan 29, 2024
2 parents 629f673 + c47f7c5 commit 11a4a0f
Show file tree
Hide file tree
Showing 85 changed files with 1,197 additions and 496 deletions.
7 changes: 5 additions & 2 deletions Build.Docker.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ $IsCIBuild = $null -ne $env:APPVEYOR_BUILD_NUMBER
$IsPublishedBuild = ($env:APPVEYOR_REPO_BRANCH -eq "main" -or $env:APPVEYOR_REPO_BRANCH -eq "dev") -and $null -eq $env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH

$version = Get-SemVer(@{ $true = $env:APPVEYOR_BUILD_VERSION; $false = "99.99.99" }[$env:APPVEYOR_BUILD_VERSION -ne $NULL])
$framework = "net7.0"
$framework = "net8.0"
$image = "datalust/seqcli"
$archs = @(
@{ rid = "x64"; platform = "linux/amd64" },
@{ rid = "arm64"; platform = "linux/arm64/v8" }
)

$endToEndVersion = "preview"

function Execute-Tests
{
& dotnet test ./test/SeqCli.Tests/SeqCli.Tests.csproj -c Release -f $framework /p:Configuration=Release /p:VersionPrefix=$version
if ($LASTEXITCODE -ne 0) { exit 1 }

cd ./test/SeqCli.EndToEnd/
docker pull datalust/seq:latest
docker pull "datalust/seq:$endToEndVersion"
docker tag "datalust/seq:$endToEndVersion" datalust/seq:latest
& dotnet run -f $framework -- --docker-server
if ($LASTEXITCODE -ne 0)
{
Expand Down
5 changes: 3 additions & 2 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Push-Location $PSScriptRoot
$ErrorActionPreference = 'Stop'

$version = Get-SemVer(@{ $true = $env:APPVEYOR_BUILD_VERSION; $false = "99.99.99" }[$env:APPVEYOR_BUILD_VERSION -ne $NULL])
$framework = 'net7.0'
$framework = 'net8.0'
$windowsTfmSuffix = '-windows'

function Clean-Output
Expand Down Expand Up @@ -86,7 +86,8 @@ Clean-Output
Create-ArtifactDir
Restore-Packages
Publish-Archives($version)
Publish-DotNetTool($version)
# Temporarily disabled while SerilogTracing is in pre-release
# Publish-DotNetTool($version)
Execute-Tests($version)
Publish-Docs($version)

Expand Down
212 changes: 174 additions & 38 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 2023.4.{build}
version: 2024.1.{build}
skip_tags: true
image:
- Visual Studio 2022
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/seqcli/linux-arm64.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN apt-get update \
zlib1g \
&& rm -rf /var/lib/apt/lists/*

COPY src/SeqCli/bin/Release/net7.0/linux-arm64/publish /bin/seqcli
COPY src/SeqCli/bin/Release/net8.0/linux-arm64/publish /bin/seqcli

ENTRYPOINT ["/bin/seqcli/seqcli"]

Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/seqcli/linux-x64.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN apt-get update \
zlib1g \
&& rm -rf /var/lib/apt/lists/*

COPY src/SeqCli/bin/Release/net7.0/linux-x64/publish /bin/seqcli
COPY src/SeqCli/bin/Release/net8.0/linux-x64/publish /bin/seqcli

ENTRYPOINT ["/bin/seqcli/seqcli"]

Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "7.0.400"
"version": "8.0.101"
}
}
}
19 changes: 14 additions & 5 deletions src/Roastery/Data/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
using System.Threading.Tasks;
using Roastery.Util;
using Serilog;
using Serilog.Events;
using SerilogTracing;
using SerilogTracing.Instrumentation;

namespace Roastery.Data;

Expand Down Expand Up @@ -134,17 +137,23 @@ static string AsSqlLiteral(object? o)

async Task LogExecAsync(string sql, int rowCount)
{
using var activity = _logger.StartActivity("Execution of {Sql}", sql);

if (Distribution.OnceIn(200))
{
throw new OperationCanceledException(
var exception = new OperationCanceledException(
"A deadlock was detected and the transaction chosen as the deadlock victim.");
}

var sw = Stopwatch.StartNew();
activity.Complete(LogEventLevel.Error, exception);

throw exception;
}


var delay = 10 + (int)(Distribution.Uniform() * Math.Pow(rowCount, 1.6));
await Task.Delay(delay);
_logger.Debug("Execution of {Sql} affected {RowCount} rows in {Elapsed:0.000} ms",
sql, rowCount, sw.Elapsed.TotalMilliseconds);

activity.AddProperty("RowCount", rowCount);
}

static T Clone<T>(T value) where T: IIdentifiable, new()
Expand Down
8 changes: 4 additions & 4 deletions src/Roastery/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static async Task Main(ILogger logger, CancellationToken cancellationToke

var database = new Database(webApplicationLogger, "roastery");
DatabaseMigrator.Populate(database);

var client = new HttpClient(
"https://roastery.datalust.co",
new NetworkLatencyMiddleware(
Expand All @@ -35,13 +35,13 @@ public static async Task Main(ILogger logger, CancellationToken cancellationToke
}, webApplicationLogger))))));

var agents = new List<Agent>();

for (var i = 0; i < 100; ++i)
agents.Add(new Customer(client, Person.Generate(), (int)Distribution.Uniform(60000, 180000)));

for (var i = 0; i < 3; ++i)
agents.Add(new WarehouseStaff(client));

var batchApplicationLogger = logger.ForContext("Application", "Roastery Batch Processing");
agents.Add(new CatalogBatch(client, batchApplicationLogger));
agents.Add(new ArchivingBatch(client, batchApplicationLogger));
Expand Down
7 changes: 4 additions & 3 deletions src/Roastery/Roastery.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="3.0.1" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="SerilogTracing" Version="1.0.0-dev-00088" />
</ItemGroup>

</Project>
21 changes: 12 additions & 9 deletions src/Roastery/Web/RequestLoggingMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System.Diagnostics;
using System.Net;
using System.Threading.Tasks;
using Serilog;
using Serilog.Context;
using Serilog.Events;
using SerilogTracing;
using SerilogTracing.Instrumentation;

namespace Roastery.Web;

Expand All @@ -22,15 +23,16 @@ public RequestLoggingMiddleware(ILogger logger, HttpServer next)
public override async Task<HttpResponse> InvokeAsync(HttpRequest request)
{
using var _ = LogContext.PushProperty("RequestId", request.RequestId);

var sw = Stopwatch.StartNew();

using var activity = _logger.StartActivity("HTTP {RequestMethod} {RequestPath}", request.Method, request.Path);

try
{
var response = await _next.InvokeAsync(request);
LogCompletion(null, request, sw, response.StatusCode);
LogCompletion(activity, null, response.StatusCode);
return response;
}
catch (Exception ex1) when (LogCompletion(ex1, request, sw, HttpStatusCode.InternalServerError))
catch (Exception ex1) when (LogCompletion(activity, ex1, HttpStatusCode.InternalServerError))
{
// We never hit this, because the exception filter always returns false.
throw;
Expand All @@ -41,12 +43,13 @@ public override async Task<HttpResponse> InvokeAsync(HttpRequest request)
}
}

bool LogCompletion(Exception? exception, HttpRequest request, Stopwatch sw, HttpStatusCode statusCode)
bool LogCompletion(LoggerActivity activity, Exception? exception, HttpStatusCode statusCode)
{
var level = (int)statusCode >= 500 ? LogEventLevel.Error : LogEventLevel.Information;
_logger.Write(level, exception,
"HTTP {RequestMethod} {RequestPath} responded {StatusCode} in {Elapsed:0.000} ms",
request.Method, request.Path, (int)statusCode, sw.Elapsed.TotalMilliseconds);

activity.AddProperty("StatusCode", (int)statusCode);
activity.Complete(level, exception);

return false;
}
}
2 changes: 0 additions & 2 deletions src/SeqCli/Apps/Definitions/AppDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable

using System.Collections.Generic;
using Newtonsoft.Json;

Expand Down
2 changes: 0 additions & 2 deletions src/SeqCli/Apps/Definitions/AppMetadataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
using System.Reflection;
using Seq.Apps;

#nullable enable

namespace SeqCli.Apps.Definitions;

static class AppMetadataReader
Expand Down
2 changes: 0 additions & 2 deletions src/SeqCli/Apps/Definitions/AppSettingDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

using Newtonsoft.Json;

#nullable enable

namespace SeqCli.Apps.Definitions;

// ReSharper disable all
Expand Down
2 changes: 0 additions & 2 deletions src/SeqCli/Cli/CommandLineHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
using Serilog.Core;
using Serilog.Events;

#nullable enable

namespace SeqCli.Cli;

class CommandLineHost
Expand Down
2 changes: 0 additions & 2 deletions src/SeqCli/Cli/Commands/App/InstallCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
using SeqCli.Util;
using Serilog;

#nullable enable

namespace SeqCli.Cli.Commands.App;

[Command("app", "install", "Install an app package",
Expand Down
2 changes: 0 additions & 2 deletions src/SeqCli/Cli/Commands/App/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
using SeqCli.Util;
using Serilog;

#nullable enable

namespace SeqCli.Cli.Commands.App;

[Command("app", "update", "Update an installed app package",
Expand Down
22 changes: 19 additions & 3 deletions src/SeqCli/Cli/Commands/AppInstance/CreateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using SeqCli.Cli.Features;
using SeqCli.Config;
using SeqCli.Connection;
using SeqCli.Signals;
using SeqCli.Util;
using Serilog;

Expand All @@ -20,9 +21,10 @@ class CreateCommand : Command
readonly ConnectionFeature _connection;
readonly OutputFormatFeature _output;

string? _title, _appId;
string? _title, _appId, _streamIncomingEventsSignal;
readonly Dictionary<string, string> _settings = new();
readonly List<string> _overridable = new();
bool _streamIncomingEvents;

public CreateCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config)
{
Expand All @@ -48,12 +50,24 @@ public CreateCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config
_settings.Add(name, valueText ?? "");
});

Options.Add(
"stream:",
"Stream incoming events to this app instance as they're ingested; optionally accepts a signal expression limiting which events should be streamed",
s =>
{
_streamIncomingEvents = true;
if (!string.IsNullOrEmpty(s))
{
_streamIncomingEventsSignal = s;
}
}
);

Options.Add(
"overridable=",
"Specify setting names that may be overridden by users when invoking the app",
s => _overridable.Add(s));

// The command doesn't yet implement "Stream incoming events".

_connection = Enable<ConnectionFeature>();
_output = Enable(new OutputFormatFeature(config.Output));
Expand All @@ -77,6 +91,8 @@ bool ValidateSettingName(string settingName)
}

instance.Title = _title;
instance.AcceptStreamedEvents = _streamIncomingEvents;
instance.StreamedSignalExpression = !string.IsNullOrWhiteSpace(_streamIncomingEventsSignal) ? SignalExpressionParser.ParseExpression(_streamIncomingEventsSignal) : null;

foreach (var setting in _settings)
{
Expand Down
3 changes: 1 addition & 2 deletions src/SeqCli/Cli/Commands/Bench/BenchCasesCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System.Collections.Generic;

namespace SeqCli.Cli.Commands.Bench;
Expand All @@ -23,5 +22,5 @@ namespace SeqCli.Cli.Commands.Bench;
class BenchCasesCollection
{
// ReSharper disable once CollectionNeverUpdated.Global
public IList<BenchCase> Cases { get; } = new List<BenchCase>();
public IList<QueryBenchCase> Cases { get; } = new List<QueryBenchCase>();
}
Loading

0 comments on commit 11a4a0f

Please sign in to comment.