Skip to content

Commit

Permalink
Merge pull request #294 from datalust/dev
Browse files Browse the repository at this point in the history
2023.4 Release
  • Loading branch information
nblumhardt authored Aug 31, 2023
2 parents cb6edc6 + a3c487c commit 629f673
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 29 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ $token = (

See `CONTRIBUTING.md`.

## Permissions

When connecting with an API key the allowed operations are determined by the [permissions assigned to that API key](https://docs.datalust.co/docs/api-keys#api-keys-and-permissions).

To determine the permission required for a command check the 'Permission demand' column of the [equivalent server API operation](https://docs.datalust.co/docs/server-http-api). For example, the command `apikey create` uses the [`POST api/apikeys` endpoint](https://docs.datalust.co/docs/server-http-api#apiapikeys), which requires the `Write` permission.

## Commands

Usage:
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 2023.3.{build}
version: 2023.4.{build}
skip_tags: true
image:
- Visual Studio 2022
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "7.0.305"
"version": "7.0.400"
}
}
7 changes: 2 additions & 5 deletions src/SeqCli/Cli/Commands/IngestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using SeqCli.Ingestion;
using SeqCli.Levels;
using SeqCli.PlainText;
using SeqCli.Syntax;
using Serilog;
using Serilog.Core;
using Serilog.Events;
Expand Down Expand Up @@ -92,11 +93,7 @@ protected override async Task<int> Run()
Func<LogEvent, bool>? filter = null;
if (_filter != null)
{
// Support non-Serilog level names (`@l` can't be overridden by the name resolver). At a later date,
// we hope to be able to use the Serilog.Expressions AST to do this reliably (at the moment, all occurrences
// of @l, whether referring to the property or not, will be replaced).
var expr = _filter.Replace("@l", "@Level").Replace("@Level", $"coalesce(@p['{SurrogateLevelProperty.PropertyName}'],@l)");
var eval = SerilogExpression.Compile(expr, nameResolver: new SeqBuiltInNameResolver());
var eval = SeqSyntax.CompileExpression(_filter);
filter = evt => ExpressionResult.IsTrue(eval(evt));
}

Expand Down
6 changes: 3 additions & 3 deletions src/SeqCli/SeqCli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
<PackageReference Include="Serilog.Formatting.Compact.Reader" Version="2.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Autofac" Version="7.0.1" />
<PackageReference Include="Autofac" Version="7.1.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="5.2.2" />
<PackageReference Include="Superpower" Version="3.0.0" />
<PackageReference Include="System.Reactive" Version="6.0.0" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="7.0.1" />
<PackageReference Include="Seq.Api" Version="2023.3.0" />
<PackageReference Include="Seq.Apps" Version="2021.4.0" />
<PackageReference Include="Seq.Api" Version="2023.4.0" />
<PackageReference Include="Seq.Apps" Version="2023.4.0" />
<PackageReference Include="Tavis.UriTemplates" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
using System.Diagnostics.CodeAnalysis;
using Serilog.Expressions;

#nullable enable

namespace SeqCli.Ingestion;
namespace SeqCli.Syntax;

/// <summary>
/// Extends Serilog.Expressions with support for commonly-used Seq property names.
Expand All @@ -30,26 +28,26 @@ public override bool TryResolveBuiltInPropertyName(string alias, [NotNullWhen(tr
{
switch (alias)
{
case "@Properties":
target = "@p";
case "Properties":
target = "p";
return true;
case "@Timestamp":
target = "@t";
case "Timestamp":
target = "t";
return true;
case "@Level":
target = "@l";
case "Level":
target = "l";
return true;
case "@Message":
target = "@m";
case "Message":
target = "m";
return true;
case "@MessageTemplate":
target = "@mt";
case "MessageTemplate":
target = "mt";
return true;
case "@EventType":
target = "@i";
case "EventType":
target = "i";
return true;
case "@Exception":
target = "@x";
case "Exception":
target = "x";
return true;
default:
target = null;
Expand Down
16 changes: 16 additions & 0 deletions src/SeqCli/Syntax/SeqSyntax.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using SeqCli.Levels;
using Serilog.Expressions;

namespace SeqCli.Syntax;

static class SeqSyntax
{
public static CompiledExpression CompileExpression(string expression)
{
// Support non-Serilog level names (`@l` can't be overridden by the name resolver). At a later date,
// we'll use the Seq.Syntax package to do this reliably (at the moment, all occurrences
// of @l, whether referring to the property or not, will be replaced).
var expr = expression.Replace("@l", "@Level").Replace("@Level", $"coalesce(@p['{SurrogateLevelProperty.PropertyName}'],@l)");
return SerilogExpression.Compile(expr, nameResolver: new SeqBuiltInNameResolver());
}
}
2 changes: 1 addition & 1 deletion test/SeqCli.EndToEnd/SeqCli.EndToEnd.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFrameworks>net7.0;net7.0-windows</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="7.0.1" />
<PackageReference Include="Autofac" Version="7.1.0" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="5.2.2" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/SeqCli.Tests/SeqCli.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFrameworks>net7.0;net7.0-windows</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
38 changes: 38 additions & 0 deletions test/SeqCli.Tests/Syntax/SeqSyntaxTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Linq;
using SeqCli.Levels;
using SeqCli.Syntax;
using Serilog.Events;
using Serilog.Parsing;
using Xunit;

namespace SeqCli.Tests.Syntax;

public class SeqSyntaxTests
{
[Fact]
public void MessageIsExposed()
{
var evt = new LogEvent(DateTimeOffset.Now, LogEventLevel.Information, null,
new MessageTemplateParser().Parse("Hello"), ArraySegment<LogEventProperty>.Empty);

var expr = SeqSyntax.CompileExpression("@Message");
var result = expr(evt);
var scalar = Assert.IsType<ScalarValue>(result);
Assert.Equal("Hello", scalar.Value);
}

[Fact]
public void SurrogateLevelIsExposed()
{
var evt = new LogEvent(DateTimeOffset.Now, LogEventLevel.Information, null, new MessageTemplate(Enumerable.Empty<MessageTemplateToken>()), new[]
{
new LogEventProperty(SurrogateLevelProperty.PropertyName, new ScalarValue("Warning"))
});

var expr = SeqSyntax.CompileExpression("@Level");
var result = expr(evt);
var scalar = Assert.IsType<ScalarValue>(result);
Assert.Equal("Warning", scalar.Value);
}
}

0 comments on commit 629f673

Please sign in to comment.