Skip to content

Commit 714e727

Browse files
committed
feat(fennec): add mongodb timestamp index
NETANOL-232
1 parent d4aa73a commit 714e727

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

Packrat/Fennec/Fennec.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.12" />
3333
<PackageReference Include="MongoDB.Bson" Version="2.22.0" />
3434
<PackageReference Include="MongoDB.Driver" Version="2.22.0" />
35-
<PackageReference Include="QuickGraph" Version="3.6.61119.7" />
3635
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
3736
<PackageReference Include="Serilog" Version="3.0.1" />
3837
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />

Packrat/Fennec/Services/DnsResolverService.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ public DnsResolverService(ILogger log, IOptions<DnsCacheOptions> options)
7373
catch (Exception e)
7474
{
7575
// Prevent the console from being too cluttered with DNS resolution errors
76-
if (e is SocketException { Message: "No such host is known." })
76+
if (e is SocketException)
77+
{
78+
_log.Verbose(e, "Failed to resolve IP address {IpAddress} | {ExceptionName}: {ExceptionMessage}", ipAddress,
79+
e.GetType(), e.Message);
7780
return null;
81+
}
7882

7983
_log.Error(e, "Unexpected exception while DNS resolving {IpAddress} | {ExceptionName}: {ExceptionMessage}", ipAddress,
8084
e.GetType(),

Packrat/Fennec/Startup.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Microsoft.EntityFrameworkCore;
1515
using Microsoft.Extensions.Options;
1616
using Microsoft.IdentityModel.Tokens;
17+
using MongoDB.Bson;
1718
using MongoDB.Bson.Serialization;
1819
using MongoDB.Driver;
1920
using Newtonsoft.Json;
@@ -291,6 +292,24 @@ public async Task Configure(WebApplication app, IWebHostEnvironment env)
291292
}
292293
}
293294

295+
var database = app.Services.GetRequiredService<IMongoDatabase>();
296+
try
297+
{
298+
Log.Information("Attempting to connect to the MongoDB");
299+
await database.RunCommandAsync((Command<BsonDocument>) "{ping:1}");
300+
Log.Information("Successfully connected to the MongoDB database");
301+
}
302+
catch (Exception e)
303+
{
304+
Log.Fatal(e, "Failed to connect to the MongoDB database | {ExceptionName}: {ExceptionMessage}",
305+
e.GetType(),
306+
e.Message);
307+
}
308+
// TODO: use an injected collection
309+
var collection = database.GetCollection<SingleTrace>("singleTraces");
310+
var model = Builders<SingleTrace>.IndexKeys.Descending(s => s.Timestamp);
311+
await collection.Indexes.CreateOneAsync(new CreateIndexModel<SingleTrace>(model));
312+
294313
app.UsePathBase("/api");
295314
app.UseSerilogRequestLogging();
296315

0 commit comments

Comments
 (0)