Skip to content

Commit

Permalink
splunk for isl
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Wright authored and Lee Wright committed Jul 4, 2024
1 parent b71679c commit 62c96ad
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 12 deletions.
24 changes: 16 additions & 8 deletions backend/ISLInterfaces/Features/CaseAccess/CaseAccessService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public class CaseAccessService(DiamReadOnlyContext context, ILogger<CaseAccessSe
private readonly Counter<long> caseSearchCount = instrumentation.CaseSearchCount;
private readonly Counter<long> caseActiveUsersCount = instrumentation.CaseActiveUsersCount;


/// <summary>
/// Get users that are currently active on a case
/// </summary>
/// <param name="rccNumber"></param>
/// <returns></returns>
public async Task<List<string>> GetCaseAccessUsersAsync(string rccNumber)
{
this.logger.LogInformation($"Getting users on case {rccNumber}");
Expand All @@ -28,14 +34,16 @@ public async Task<List<string>> GetCaseAccessUsersAsync(string rccNumber)
logger.LogError("Unable to connect to database - check connection info");
}

var result = await this.context.SubmittingAgencyRequests
.Where(access => access.RCCNumber == rccNumber && (access.RequestStatus == AgencyRequestStatus.Complete || access.RequestStatus == AgencyRequestStatus.Pending))
.Include(party => party.Party)
.OrderBy(access => access.RequestedOn)
.Select(access => access.Party.Jpdid)
.ToListAsync();
this.caseActiveUsersCount.Add(result.Count);
return result;
List<string?> results = [];

results = await this.context.SubmittingAgencyRequests
.Where(access => access.RCCNumber == rccNumber && (access.RequestStatus == AgencyRequestStatus.Complete || access.RequestStatus == AgencyRequestStatus.Pending || access.RequestStatus == AgencyRequestStatus.Submitted))
.Include(party => party.Party)
.OrderBy(access => access.RequestedOn)
.Select(access => access.Party.Jpdid)
.ToListAsync();
this.caseActiveUsersCount.Add(results.Count);
return results;

}
}
9 changes: 8 additions & 1 deletion backend/ISLInterfaces/ISLInterfacesConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ public class ISLInterfacesConfiguration
public KeycloakConfiguration Keycloak { get; set; } = new();
public const string KeycloakConfig = "Keycloak";
public const string DatabaseConnectionInfoConfig = "DatabaseConnectionInfo";

public SplunkConfiguration SplunkConfig { get; set; } = new();
public ConnectionStringConfiguration DatabaseConnectionInfo { get; set; } = new();
}

public class SplunkConfiguration
{
public string Host { get; set; } = string.Empty;
public string CollectorToken { get; set; } = string.Empty;
}


public class ConnectionStringConfiguration
{
public string CaseManagementDataStore { get; set; } = string.Empty;
Expand Down
24 changes: 24 additions & 0 deletions backend/ISLInterfaces/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace ISLInterfaces;
using OpenTelemetry.Resources;
using Prometheus;
using Serilog;
using Serilog.Events;

public class Program
{
Expand Down Expand Up @@ -70,6 +71,29 @@ public static void Main(string[] args)
app.UseSwagger();
app.UseSwaggerUI();
}
var loggerConfig = new LoggerConfiguration();



var splunkHost = Environment.GetEnvironmentVariable("SplunkConfig__Host");
splunkHost ??= builder.Configuration.GetValue<string>("SplunkConfig:Host");
var splunkToken = Environment.GetEnvironmentVariable("SplunkConfig__CollectorToken");
splunkToken ??= builder.Configuration.GetValue<string>("SplunkConfig:CollectorToken");

if (string.IsNullOrEmpty(splunkHost) || string.IsNullOrEmpty(splunkToken))
{
Console.WriteLine("Splunk Host or Token is not configured - check Splunk environment");
Environment.Exit(-1);
}
else
{
Log.Information($"Logging to splunk host {splunkHost}");
}


loggerConfig
.MinimumLevel.Verbose()
.WriteTo.EventCollector(splunkHost, splunkToken, restrictedToMinimumLevel: LogEventLevel.Debug);


Action<ResourceBuilder> configureResource = r => r.AddService(
Expand Down
6 changes: 5 additions & 1 deletion backend/ISLInterfaces/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@
"Schema": "diam",
"EfHistorySchema": "public"
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"SplunkConfig": {
"Host": "localhost",
"CollectorToken": "<redacted>"
}
}
4 changes: 2 additions & 2 deletions backend/common/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@
<PackageReference Include="NodaTime" Version="3.1.11" />
<PackageReference Include="NodaTime.Serialization.SystemTextJson" Version="1.2.0" />
<PackageReference Include="Polly" Version="8.4.0" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.3.0" />
<PackageReference Include="Serilog.Expressions" Version="4.0.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Serilog.Sinks.Splunk" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.Splunk" Version="5.0.0" />

<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.Seq" Version="7.0.1" />
Expand Down

0 comments on commit 62c96ad

Please sign in to comment.