Skip to content

Commit

Permalink
Merge pull request #1097 from ITfoxtec/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
Revsgaard authored Jan 15, 2025
2 parents 94542fa + b7ed714 commit 3d226ec
Show file tree
Hide file tree
Showing 21 changed files with 140 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/FoxIDs.Control/FoxIDs.Control.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Version>1.14.9</Version>
<Version>1.14.10</Version>
<RootNamespace>FoxIDs</RootNamespace>
<Authors>Anders Revsgaard</Authors>
<Company>ITfoxtec</Company>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ private void AddAddTraceMessage(LogsTableRow row, InternalLogItem item)
item.Details = new List<Api.LogItemDetail>();

var logTraceMessage = message.ToObject<List<LogTraceMessageItem>>();
logTraceMessage.Reverse();
foreach (var messageItem in logTraceMessage)
{
var logItemDetail = new Api.LogItemDetail
Expand Down
1 change: 1 addition & 0 deletions src/FoxIDs.Control/Logic/Logs/LogOpenSearchLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ private void AddValue(Dictionary<string, string> values, string key, string valu
if (!item.Message.IsNullOrWhiteSpace())
{
var logTraceMessageItems = item.Message.ToObject<List<LogTraceMessageItem>>();
logTraceMessageItems.Reverse();
foreach (var logTraceMessageItem in logTraceMessageItems)
{
var logItemDetail = new Api.LogItemDetail
Expand Down
2 changes: 1 addition & 1 deletion src/FoxIDs.ControlClient/FoxIDs.ControlClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Version>1.14.9</Version>
<Version>1.14.10</Version>
<RootNamespace>FoxIDs.Client</RootNamespace>
<Authors>Anders Revsgaard</Authors>
<Company>ITfoxtec</Company>
Expand Down
4 changes: 2 additions & 2 deletions src/FoxIDs.ControlClient/Pages/Logging/LogSettings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
{
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link" href="@logUsageHref">Usages</a>
<a class="nav-link" href="@logsHref">Logs</a>
</li>
<li class="nav-item">
<a class="nav-link" href="@logsHref">Logs</a>
<a class="nav-link" href="@logUsageHref">Usages</a>
</li>
<li class="nav-item">
<a class="nav-link active">Settings</a>
Expand Down
4 changes: 2 additions & 2 deletions src/FoxIDs.ControlClient/Pages/Logging/LogUsage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active">Usage</a>
<a class="nav-link" href="@logsHref">Logs</a>
</li>
<li class="nav-item">
<a class="nav-link" href="@logsHref">Logs</a>
<a class="nav-link active">Usages</a>
</li>
<li class="nav-item">
<a class="nav-link" href="@logSettingsHref">Settings</a>
Expand Down
4 changes: 2 additions & 2 deletions src/FoxIDs.ControlClient/Pages/Logging/Logs.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link" href="@logUsageHref">Usages</a>
<a class="nav-link active">Logs</a>
</li>
<li class="nav-item">
<a class="nav-link active">Logs</a>
<a class="nav-link" href="@logUsageHref">Usages</a>
</li>
<li class="nav-item">
<a class="nav-link" href="@logSettingsHref">Settings</a>
Expand Down
2 changes: 1 addition & 1 deletion src/FoxIDs.ControlClient/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
}
@if (ClientSettings.LogOption != LogOptions.Stdout)
{
<TenantLiNavLink Href="logusage" SubPages="logs,logsettings">
<TenantLiNavLink Href="logs" SubPages="logusage,logsettings">
Logs
</TenantLiNavLink>
}
Expand Down
2 changes: 1 addition & 1 deletion src/FoxIDs.ControlShared/FoxIDs.ControlShared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Version>1.14.9</Version>
<Version>1.14.10</Version>
<RootNamespace>FoxIDs</RootNamespace>
<Authors>Anders Revsgaard</Authors>
<Company>ITfoxtec</Company>
Expand Down
2 changes: 1 addition & 1 deletion src/FoxIDs.Shared/FoxIDs.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Version>1.14.9</Version>
<Version>1.14.10</Version>
<RootNamespace>FoxIDs</RootNamespace>
<Authors>Anders Revsgaard</Authors>
<Company>ITfoxtec</Company>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,25 @@ private void AddMapping()
index_patterns = new[] { $"{settings.OpenSearch.LogName}*" },
template = new
{
settings = new
{
index = new
{
refresh_interval = "5s"
}
},
mappings = new
{
properties = new
properties = new
{
tenantName = new { type = "keyword" },
trackName = new { type = "keyword" }
tenantName = new { type = "keyword" },
trackName = new { type = "keyword" }
}
}
}
},
priority = "1"
}));
}

}

private void CreateIndexPolicy(LogLifetimeOptions logLifetime)
Expand Down Expand Up @@ -199,7 +206,7 @@ public void Metric(string metricName, double value, IDictionary<string, string>
Index(GetMetricTelemetryLogString(metricName, value, properties), Constants.Logs.IndexName.Metrics);
}

private void Index(OpenSearchLogItem logItem, string indexName)
private void Index<T>(T logItem, string indexName) where T : OpenSearchLogItemBase
{
try
{
Expand Down Expand Up @@ -229,9 +236,9 @@ private string GetIndexName(DateTimeOffset utcNow, string logIndexName)
return $"{settings.OpenSearch.LogName}-{lifetime}d-{logIndexName}-{utcNow.Year}.{utcNow.Month}.{utcNow.Day}";
}

private OpenSearchLogItem GetExceptionTelemetryLogString(LogTypes logType, Exception exception, string message, IDictionary<string, string> properties)
private OpenSearchErrorLogItem GetExceptionTelemetryLogString(LogTypes logType, Exception exception, string message, IDictionary<string, string> properties)
{
var logItem = CreateLogItem(logType, properties);
var logItem = CreateLogItem<OpenSearchErrorLogItem>(logType, properties);
var messageItems = new List<ErrorMessageItem>();
if (!message.IsNullOrWhiteSpace())
{
Expand Down Expand Up @@ -260,46 +267,46 @@ private IEnumerable<ErrorMessageItem> GetErrorMessageItems(Exception exception)
}
}

private OpenSearchLogItem GetEventTelemetryLogString(string eventName, IDictionary<string, string> properties)
private OpenSearchEventLogItem GetEventTelemetryLogString(string eventName, IDictionary<string, string> properties)
{
var logItem = CreateLogItem(LogTypes.Event, properties);
var logItem = CreateLogItem<OpenSearchEventLogItem>(LogTypes.Event, properties);
logItem.Message = eventName;
return logItem;
}

private OpenSearchLogItem GetTraceTelemetryLogString(string message, IDictionary<string, string> properties)
private OpenSearchTraceLogItem GetTraceTelemetryLogString(string message, IDictionary<string, string> properties)
{
var logItem = CreateLogItem(LogTypes.Trace, properties);
var logItem = CreateLogItem<OpenSearchTraceLogItem>(LogTypes.Trace, properties);
logItem.Message = message;
return logItem;
}

private OpenSearchLogItem GetMetricTelemetryLogString(string metricName, double value, IDictionary<string, string> properties)
private OpenSearchMetricLogItem GetMetricTelemetryLogString(string metricName, double value, IDictionary<string, string> properties)
{
var logItem = CreateLogItem(LogTypes.Metric, properties);
var logItem = CreateLogItem<OpenSearchMetricLogItem>(LogTypes.Metric, properties);
logItem.Message = metricName;
logItem.Value = value;
return logItem;
}

private OpenSearchLogItem CreateLogItem(LogTypes logType, IDictionary<string, string> properties)
private T CreateLogItem<T>(LogTypes logType, IDictionary<string, string> properties) where T : OpenSearchLogItemBase
{
var logItem = CreateLogItem(properties);
var logItem = CreateLogItem<T>(properties);
logItem.LogType = logType.ToString();
logItem.Timestamp = DateTimeOffset.UtcNow;
return logItem;
}

private OpenSearchLogItem CreateLogItem(IDictionary<string, string> properties)
private T CreateLogItem<T>(IDictionary<string, string> properties) where T : OpenSearchLogItemBase
{
if(properties != null && properties.Count > 0)
{
var json = JsonConvert.SerializeObject(properties);
return json.ToObject<OpenSearchLogItem>();
return json.ToObject<T>();
}
else
{
return new OpenSearchLogItem();
return default;
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/FoxIDs.Shared/Logic/PlanUsageLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ private double GetLogAddRating(UsageLogTokenTypes? tokenType = null)
{
if (scopedLogger.LogInfoTrace)
{
rating += 0.1;
rating += 0.4;
}
if (scopedLogger.LogClaimTrace)
{
rating += 0.4;
rating += 0.8;
}
if (scopedLogger.LogMessageTrace)
{
rating += 0.5;
rating += 1.0;
}
if (scopedLogger.LogMetric)
{
rating += 0.01;
rating += 0.2;
}
}

Expand All @@ -79,19 +79,19 @@ private double GetLogAddRating(UsageLogTokenTypes? tokenType = null)

if (scopedStreamLogger.LogInfoTrace)
{
rating += 0.005;
rating += 0.02;
}
if (scopedStreamLogger.LogClaimTrace)
{
rating += 0.02;
rating += 0.06;
}
if (scopedStreamLogger.LogMessageTrace)
{
rating += 0.02;
rating += 0.08;
}
if (scopedStreamLogger.LogMetric)
{
rating += 0.001;
rating += 0.01;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace FoxIDs.Models
{
public class OpenSearchErrorLogItem : OpenSearchLogItemBase
{
public string Message { get; set; }
public string Domain { get; set; }
public string RequestPath { get; set; }
public string GrantType { get; set; }
public string UpPartyClientId { get; set; }
public string UpPartyStatus { get; set; }
public string DownPartyClientId { get; set; }
public string AccountAction { get; set; }
public string SequenceCulture { get; set; }
public string Issuer { get; set; }
public string Status { get; set; }
public string SessionId { get; set; }
public string ExternalSessionId { get; set; }
public string UserId { get; set; }
public string Email { get; set; }
public int FailingLoginCount { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace FoxIDs.Models
{
public class OpenSearchEventLogItem : OpenSearchLogItemBase
{
public string Message { get; set; }
public string UserId { get; set; }
public string Email { get; set; }
public string UsageType { get; set; }
public string UsageLoginType { get; set; }
public string UsageTokenType { get; set; }
public double UsageAddRating { get; set; }
}
}
19 changes: 2 additions & 17 deletions src/FoxIDs.Shared/Models/Tracks/Logs/Logging/OpenSearchLogItem.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
using System;

namespace FoxIDs.Models
namespace FoxIDs.Models
{
public class OpenSearchLogItem
public class OpenSearchLogItem : OpenSearchLogItemBase
{
public DateTimeOffset Timestamp { get; set; }
public string LogType { get; set; }
public string Message { get; set; }
public double Value { get; set; }
public string MachineName { get; set; }
public string ClientIP { get; set; }
public string Domain { get; set; }
public string UserAgent { get; set; }
public string OperationId { get; set; }
public string RequestId { get; set; }
public string RequestPath { get; set; }
public string TenantName { get; set; }
public string TrackName { get; set; }
public string GrantType { get; set; }
public string UpPartyId { get; set; }
public string UpPartyClientId { get; set; }
public string UpPartyStatus { get; set; }
public string DownPartyId { get; set; }
public string DownPartyClientId { get; set; }
public string SequenceId { get; set; }
public string ExternalSequenceId { get; set; }
public string AccountAction { get; set; }
public string SequenceCulture { get; set; }
public string Issuer { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

namespace FoxIDs.Models
{
public class OpenSearchLogItemBase
{
public DateTimeOffset Timestamp { get; set; }
public string LogType { get; set; }
public string TenantName { get; set; }
public string TrackName { get; set; }
public string OperationId { get; set; }
public string RequestId { get; set; }
public string SequenceId { get; set; }
public string ExternalSequenceId { get; set; }

public string MachineName { get; set; }
public string ClientIP { get; set; }
public string UserAgent { get; set; }
public string UpPartyId { get; set; }
public string DownPartyId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace FoxIDs.Models
{
public class OpenSearchMetricLogItem : OpenSearchLogItemBase
{
public string Message { get; set; }
public double Value { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace FoxIDs.Models
{
public class OpenSearchTraceLogItem : OpenSearchLogItemBase
{
public string Message { get; set; }
public string Domain { get; set; }
public string RequestPath { get; set; }
public string GrantType { get; set; }
public string UpPartyClientId { get; set; }
public string UpPartyStatus { get; set; }
public string DownPartyClientId { get; set; }
public string AccountAction { get; set; }
public string SequenceCulture { get; set; }
public string Issuer { get; set; }
public string Status { get; set; }
public string SessionId { get; set; }
public string ExternalSessionId { get; set; }
public string UserId { get; set; }
public string Email { get; set; }
public int FailingLoginCount { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/FoxIDs.SharedBase/FoxIDs.SharedBase.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Version>1.14.9</Version>
<Version>1.14.10</Version>
<RootNamespace>FoxIDs</RootNamespace>
<Authors>Anders Revsgaard</Authors>
<Company>ITfoxtec</Company>
Expand Down
Loading

0 comments on commit 3d226ec

Please sign in to comment.