Skip to content

Commit 05e32d9

Browse files
committed
Changes:
- Introduced records for requests and responses - Added missing cancellation tokens - Fixed some namespaces - Added LogExtractor tests - Version bump to 2.1.0
1 parent 6b6678d commit 05e32d9

File tree

60 files changed

+442
-237
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+442
-237
lines changed

src/Benchmarks/Benchmarks.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net5.0</TargetFramework>
6+
<EnableNETAnalyzers>false</EnableNETAnalyzers>
7+
<EnforceCodeStyleInBuild>false</EnforceCodeStyleInBuild>
8+
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
69
</PropertyGroup>
710

811
<ItemGroup>

src/Benchmarks/KuduApiAdapter/KuduApiAdapterOld.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ namespace Benchmarks.KuduApiAdapter
1313
{
1414
public class KuduApiAdapterOld
1515
{
16-
private static Func<JsonSerializerOptions> GetJsonSerializerOptions = delegate ()
17-
{
18-
return new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
19-
};
16+
private static readonly Lazy<JsonSerializerOptions> GetJsonSerializerOptions =
17+
new Lazy<JsonSerializerOptions> (() => new JsonSerializerOptions
18+
{
19+
PropertyNameCaseInsensitive = true
20+
});
2021

2122
private const string InitStringValue = "init";
2223
private const string Docker = "docker";
@@ -43,11 +44,11 @@ public KuduApiAdapterOld(HttpClient client, ILogger logger)
4344

4445
response.EnsureSuccessStatusCode();
4546

46-
using var stream = await response.Content.ReadAsStreamAsync();
47+
using var stream = await response.Content.ReadAsStreamAsync(cancellation);
4748

4849
var logs = await JsonSerializer.DeserializeAsync<KuduLog[]>(
4950
stream,
50-
GetJsonSerializerOptions(),
51+
GetJsonSerializerOptions.Value,
5152
cancellation);
5253

5354
var values = logs.Where(

src/Benchmarks/Program.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
using BenchmarkDotNet.Running;
2-
using Benchmarks.WebHookReporter;
3-
using System.Threading.Tasks;
42

53
namespace Benchmarks
64
{
75
internal class Program
86
{
9-
private static void Main(string[] args)
7+
private static void Main()
108
{
119
BenchmarkRunner.Run<KuduApiAdapter.KuduApiAdapterBenchmarks>();
1210
}

src/Benchmarks/WebHookReporter/WebHookReporterBenchmarks.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using Microsoft.Extensions.Options;
55
using Microsoft.IO;
66
using Rooster.Mediator.Commands.ExtractDockerRunParams;
7-
using Rooster.Mediator.Commands.ProcessLogEntry;
7+
using Rooster.Mediator.Commands.ShouldProcessDockerLog;
88
using Rooster.QoS.Resilency;
99
using Rooster.Slack.Reporting;
1010
using System;
@@ -20,15 +20,15 @@ namespace Benchmarks.WebHookReporter
2020
[MemoryDiagnoser, ThreadingDiagnoser, NativeMemoryProfiler]
2121
public class WebHookReporterBenchmarks
2222
{
23-
private const string message = "New container deployment.";
23+
private const string Message = "New container deployment.";
2424
private const string DateTitle = "Date";
2525
private const string ContainerNameTitle = "Container name";
2626
private const string PortsTitle = "Ports";
2727
private const string ImageTitle = "Image";
2828
private const string MarkdownInOption = "text";
2929
private const string ColorValue = "warning";
3030

31-
private static ShouldProcessDockerLogRequest request = new ShouldProcessDockerLogRequest
31+
private static readonly ShouldProcessDockerLogRequest Request = new ShouldProcessDockerLogRequest
3232
{
3333
ExportedLogEntry = new ExtractDockerRunParamsResponse
3434
{
@@ -45,7 +45,7 @@ public class WebHookReporterBenchmarks
4545

4646
private static readonly RecyclableMemoryStreamManager _manager = new RecyclableMemoryStreamManager();
4747

48-
private CancellationTokenSource _source = new CancellationTokenSource();
48+
private readonly CancellationTokenSource _source = new CancellationTokenSource();
4949
private WebHookReporterOld _reporterOld;
5050
private Rooster.Slack.Reporting.WebHookReporter _reporter;
5151
private object _payloadOld;
@@ -54,8 +54,10 @@ public class WebHookReporterBenchmarks
5454
[GlobalSetup]
5555
public void Setup()
5656
{
57-
var client = new HttpClient();
58-
client.BaseAddress = new Uri("https://hooks.slack.com");
57+
var client = new HttpClient
58+
{
59+
BaseAddress = new Uri("https://hooks.slack.com")
60+
};
5961

6062
_reporterOld = new WebHookReporterOld(
6163
new WebHookReporterOptionsMonitor(),
@@ -69,12 +71,12 @@ public void Setup()
6971
new RetryProvider(new RetryProviderOptionsMonitor(), NullLogger<RetryProvider>.Instance),
7072
NullLogger<Rooster.Slack.Reporting.WebHookReporter>.Instance);
7173

72-
var fields = new object[4]
74+
var attachmentFields = new object[4]
7375
{
74-
new { title = DateTitle, value = $"`{request.ExportedLogEntry.EventDate}`" },
75-
new { title = ContainerNameTitle, value = $"`{request.ExportedLogEntry.ContainerName}`"},
76-
new { title = PortsTitle, value = $"`{request.ExportedLogEntry.InboundPort}` : `{request.ExportedLogEntry.OutboundPort}`"},
77-
new { title = ImageTitle, value = $"`{request.ExportedLogEntry.ImageName}`: `{request.ExportedLogEntry.ImageTag}`" }
76+
new { title = DateTitle, value = $"`{Request.ExportedLogEntry.EventDate}`" },
77+
new { title = ContainerNameTitle, value = $"`{Request.ExportedLogEntry.ContainerName}`"},
78+
new { title = PortsTitle, value = $"`{Request.ExportedLogEntry.InboundPort}` : `{Request.ExportedLogEntry.OutboundPort}`"},
79+
new { title = ImageTitle, value = $"`{Request.ExportedLogEntry.ImageName}`: `{Request.ExportedLogEntry.ImageTag}`" }
7880
};
7981

8082
var content =
@@ -86,9 +88,9 @@ public void Setup()
8688
{
8789
mrkdwn_in = new object[1] { MarkdownInOption },
8890
color = ColorValue,
89-
pretext = $"*Service:* {request.ExportedLogEntry.ServiceName}",
90-
text = $"_{message}_",
91-
fields = fields
91+
pretext = $"*Service:* {Request.ExportedLogEntry.ServiceName}",
92+
text = $"_{Message}_",
93+
fields = attachmentFields
9294
},
9395
}
9496
};

src/Benchmarks/WebHookReporter/WebHookReporterOld.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public async Task Send<T>(T payload, CancellationToken cancellation)
5757
{
5858
var serializedContent = JsonSerializer.Serialize(payload);
5959

60-
await
60+
_ = await
6161
_retryProvider.RetryOn<HttpRequestException, HttpResponseMessage>(
6262
CheckError,
6363
TransientHttpStatusCodePredicate,

src/Benchmarks/WritingJson/WritingJsonBenchmarks.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
using BenchmarkDotNet.Attributes;
22
using Microsoft.IO;
33
using Rooster.Mediator.Commands.ExtractDockerRunParams;
4-
using Rooster.Mediator.Commands.ProcessLogEntry;
4+
using Rooster.Mediator.Commands.ShouldProcessDockerLog;
55
using System;
66
using System.Text.Json;
77

88
namespace Benchmarks.WritingJson
99
{
1010
[MemoryDiagnoser, ThreadingDiagnoser]
11-
public class WritingJsonBenchmarks
11+
public static class WritingJsonBenchmarks
1212
{
13-
private const string message = "New container deployment.";
13+
private const string Message = "New container deployment.";
1414
private const string DateTitle = "Date";
1515
private const string ContainerNameTitle = "Container name";
1616
private const string PortsTitle = "Ports";
1717
private const string ImageTitle = "Image";
1818
private const string MarkdownInOption = "text";
1919
private const string ColorValue = "warning";
2020

21-
private static ShouldProcessDockerLogRequest request = new ShouldProcessDockerLogRequest
21+
private static readonly ShouldProcessDockerLogRequest Request = new ShouldProcessDockerLogRequest
2222
{
2323
ExportedLogEntry = new ExtractDockerRunParamsResponse
2424
{
@@ -34,14 +34,14 @@ public class WritingJsonBenchmarks
3434
};
3535

3636
[Benchmark]
37-
public string Execute()
37+
public static string Execute()
3838
{
39-
var fields = new object[4]
39+
var attachmentFields = new object[4]
4040
{
41-
new { title = DateTitle, value = $"`{request.ExportedLogEntry.EventDate}`" },
42-
new { title = ContainerNameTitle, value = $"`{request.ExportedLogEntry.ContainerName}`"},
43-
new { title = PortsTitle, value = $"`{request.ExportedLogEntry.InboundPort}` : `{request.ExportedLogEntry.OutboundPort}`"},
44-
new { title = ImageTitle, value = $"`{request.ExportedLogEntry.ImageName}`: `{request.ExportedLogEntry.ImageTag}`" }
41+
new { title = DateTitle, value = $"`{Request.ExportedLogEntry.EventDate}`" },
42+
new { title = ContainerNameTitle, value = $"`{Request.ExportedLogEntry.ContainerName}`"},
43+
new { title = PortsTitle, value = $"`{Request.ExportedLogEntry.InboundPort}` : `{Request.ExportedLogEntry.OutboundPort}`"},
44+
new { title = ImageTitle, value = $"`{Request.ExportedLogEntry.ImageName}`: `{Request.ExportedLogEntry.ImageTag}`" }
4545
};
4646

4747
var content =
@@ -53,9 +53,9 @@ public string Execute()
5353
{
5454
mrkdwn_in = new object[1] { MarkdownInOption },
5555
color = ColorValue,
56-
pretext = $"*Service:* {request.ExportedLogEntry.ServiceName}",
57-
text = $"_{message}_",
58-
fields = fields
56+
pretext = $"*Service:* {Request.ExportedLogEntry.ServiceName}",
57+
text = $"_{Message}_",
58+
fields = attachmentFields
5959
},
6060
}
6161
};
@@ -81,12 +81,12 @@ public string Execute()
8181
private static readonly JsonEncodedText imageTitleValue = JsonEncodedText.Encode(ImageTitle);
8282

8383
[Benchmark]
84-
public Memory<byte> Execute3()
84+
public static Memory<byte> Execute3()
8585
{
8686
using var stream = _manager.GetStream();
8787
using var writer = new Utf8JsonWriter(stream, new JsonWriterOptions { SkipValidation = true });
8888

89-
WriteJson(writer, request);
89+
WriteJson(writer, Request);
9090

9191
return stream.ToArray();
9292
}
@@ -103,7 +103,7 @@ private static void WriteJson(Utf8JsonWriter writer, ShouldProcessDockerLogReque
103103

104104
writer.WriteString(colorKey, colorValue);
105105
writer.WriteString(pretextKey, $"*Service:* {request.ExportedLogEntry.ServiceName}");
106-
writer.WriteString(textKey, $"_{message}_");
106+
writer.WriteString(textKey, $"_{Message}_");
107107

108108
writer.WriteStartArray(fieldsKey); // start fields
109109

src/Rooster.App/Program.cs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,4 @@
11
using Rooster.DependencyInjection;
2-
using System;
32
using System.Threading;
4-
using System.Threading.Tasks;
53

6-
namespace Rooster.App
7-
{
8-
internal class Program
9-
{
10-
private static readonly Func<CancellationToken> BuildCancellationToken = delegate ()
11-
{
12-
CancellationTokenSource source = new CancellationTokenSource();
13-
14-
return source.Token;
15-
};
16-
17-
public static async Task Main(string[] args)
18-
{
19-
await Runner.Run(BuildCancellationToken());
20-
}
21-
}
22-
}
4+
await Runner.Run(new CancellationTokenSource().Token);

src/Rooster.App/Rooster.App.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net5.0</TargetFramework>
6+
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
67
</PropertyGroup>
78

89
<ItemGroup>

src/Rooster.App/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.9
1+
2.1.0

src/Rooster.AppInsights/Commands/HealthCheck/AppInsightsHealthCheckRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Rooster.AppInsights.Commands.HealthCheck
44
{
5-
public class AppInsightsHealthCheckRequest : HealthCheckRequest
5+
public sealed record AppInsightsHealthCheckRequest : HealthCheckRequest
66
{
77
}
88
}

0 commit comments

Comments
 (0)