-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f30c322
commit f764df8
Showing
20 changed files
with
467 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,6 @@ wwwroot/ | |
otel-collector-config.yaml | ||
src/*/Internal | ||
|
||
otel-collector-config.yaml | ||
|
||
.vs/ | ||
.vscode/ | ||
.fake/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
src/AssociationRegistry.Acm.Api/Infrastructure/Metrics/HighWatermarkListener.cs
This file was deleted.
Oops, something went wrong.
76 changes: 76 additions & 0 deletions
76
src/AssociationRegistry.Acm.Api/Infrastructure/Metrics/ProjectionStateListener.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
namespace AssociationRegistry.Acm.Api.Infrastructure.Metrics; | ||
|
||
using Marten; | ||
using Marten.Events.Daemon; | ||
using Marten.Internal.Operations; | ||
using Marten.Services; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using Newtonsoft.Json.Serialization; | ||
using Projections; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
public class ProjectionStateListener : DocumentSessionListenerBase | ||
{ | ||
private readonly AcmInstrumentation _acmInstrumentation; | ||
|
||
public ProjectionStateListener(AcmInstrumentation acmInstrumentation) | ||
{ | ||
_acmInstrumentation = acmInstrumentation; | ||
} | ||
|
||
public override Task AfterCommitAsync(IDocumentSession session, IChangeSet commit, CancellationToken token) | ||
{ | ||
if (commit is not IUnitOfWork uow) return Task.CompletedTask; | ||
var operations = uow.OperationsFor<Marten.Events.IEvent>(); | ||
|
||
foreach (var operation in operations) | ||
{ | ||
var range = GetEventRange(operation); | ||
|
||
if (range is null) continue; | ||
|
||
if (range.ShardName.ProjectionName == | ||
typeof(VerenigingenPerInszProjection).FullName) | ||
_acmInstrumentation.VerenigingPerInszEventValue =range.SequenceCeiling; | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
private static EventRange? GetEventRange(IStorageOperation opperation) | ||
{ | ||
return opperation.GetType().Name switch | ||
{ | ||
"InsertProjectionProgress" => opperation.GetType().GetField("_progress", BindingFlags.NonPublic|BindingFlags.Instance).GetValue(opperation) as EventRange, | ||
"UpdateProjectionProgress" => opperation.GetType().GetProperty("Range").GetValue(opperation) as EventRange, | ||
_ => null | ||
}; | ||
} | ||
} | ||
|
||
public class AllFieldsContractResolver : DefaultContractResolver | ||
{ | ||
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) | ||
{ | ||
var props = type | ||
.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) | ||
.Select(p => base.CreateProperty(p, memberSerialization)) | ||
.Union(type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) | ||
.Select(f => base.CreateProperty(f, memberSerialization))) | ||
.ToList(); | ||
|
||
props.ForEach(p => | ||
{ | ||
p.Writable = true; | ||
p.Readable = true; | ||
}); | ||
|
||
return props; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/AssociationRegistry.Admin.ProjectionHost/Infrastructure/Metrics/AdminInstrumentation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
namespace AssociationRegistry.Admin.ProjectionHost.Infrastructure.Metrics; | ||
|
||
using AssociationRegistry.OpenTelemetry; | ||
using System; | ||
using System.Diagnostics; | ||
using System.Diagnostics.Metrics; | ||
|
||
/// <summary> | ||
/// It is recommended to use a custom type to hold references for | ||
/// ActivitySource and Instruments. This avoids possible type collisions | ||
/// with other components in the DI container. | ||
/// </summary> | ||
public class AdminInstrumentation : IInstrumentation, IDisposable | ||
{ | ||
public string ActivitySourceName => "AssociationRegistry"; | ||
public string MeterName => "AdminProjections"; | ||
private readonly Meter meter; | ||
|
||
public AdminInstrumentation() | ||
{ | ||
var version = typeof(AdminInstrumentation).Assembly.GetName().Version?.ToString(); | ||
ActivitySource = new ActivitySource(ActivitySourceName, version); | ||
meter = new Meter(MeterName, version); | ||
|
||
_verenigingZoeken = meter.CreateObservableGauge(name: "ar.beheer.p.zoeken.g", unit: "events", description: "Beheer zoeken projection", observeValue:() => VerenigingZoekenEventValue); | ||
_verenigingDetail = meter.CreateObservableGauge(name: "ar.beheer.p.detail.g", unit: "events", description: "Beheer detail projection", observeValue:() => VerenigingDetailEventValue); | ||
_historiek = meter.CreateObservableGauge(name: "ar.beheer.p.historiek.g", unit: "events", description: "Beheer detail projection", observeValue:() => VerenigingHistoriekEventValue); | ||
} | ||
public ActivitySource ActivitySource { get; } | ||
|
||
private ObservableGauge<long> _verenigingZoeken; | ||
public long VerenigingZoekenEventValue { get; set; } | ||
private ObservableGauge<long> _verenigingDetail; | ||
public long VerenigingDetailEventValue { get; set; } | ||
|
||
private ObservableGauge<long> _historiek; | ||
public long VerenigingHistoriekEventValue { get; set; } | ||
|
||
|
||
public void Dispose() | ||
{ | ||
ActivitySource.Dispose(); | ||
meter.Dispose(); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
...ssociationRegistry.Admin.ProjectionHost/Infrastructure/Metrics/ProjectionStateListener.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
namespace AssociationRegistry.Admin.ProjectionHost.Infrastructure.Metrics; | ||
|
||
using Marten; | ||
using Marten.Events.Daemon; | ||
using Marten.Internal.Operations; | ||
using Marten.Services; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Serialization; | ||
using Projections.Detail; | ||
using Projections.Historiek; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
public class ProjectionStateListener : DocumentSessionListenerBase | ||
{ | ||
private readonly AdminInstrumentation _adminInstrumentation; | ||
|
||
public ProjectionStateListener(AdminInstrumentation adminInstrumentation) | ||
{ | ||
_adminInstrumentation = adminInstrumentation; | ||
} | ||
|
||
public override Task AfterCommitAsync(IDocumentSession session, IChangeSet commit, CancellationToken token) | ||
{ | ||
if (commit is not IUnitOfWork uow) return Task.CompletedTask; | ||
var operations = uow.OperationsFor<Marten.Events.IEvent>(); | ||
|
||
foreach (var operation in operations) | ||
{ | ||
var range = GetEventRange(operation); | ||
|
||
if (range is null) continue; | ||
|
||
if (range.ShardName.ProjectionName == "BeheerVerenigingZoekenDocument") | ||
_adminInstrumentation.VerenigingZoekenEventValue = range.SequenceCeiling; | ||
|
||
if (range.ShardName.ProjectionName == typeof(BeheerVerenigingDetailProjection).FullName) | ||
_adminInstrumentation.VerenigingDetailEventValue = range.SequenceCeiling; | ||
|
||
if (range.ShardName.ProjectionName == typeof(BeheerVerenigingHistoriekProjection).FullName) | ||
_adminInstrumentation.VerenigingHistoriekEventValue = range.SequenceCeiling; | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
private static EventRange? GetEventRange(IStorageOperation opperation) | ||
{ | ||
return opperation.GetType().Name switch | ||
{ | ||
"InsertProjectionProgress" => opperation.GetType().GetField("_progress", BindingFlags.NonPublic | BindingFlags.Instance) | ||
.GetValue(opperation) as EventRange, | ||
"UpdateProjectionProgress" => opperation.GetType().GetProperty("Range").GetValue(opperation) as EventRange, | ||
_ => null | ||
}; | ||
} | ||
} | ||
|
||
public class AllFieldsContractResolver : DefaultContractResolver | ||
{ | ||
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) | ||
{ | ||
var props = type | ||
.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) | ||
.Select(p => base.CreateProperty(p, memberSerialization)) | ||
.Union(type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) | ||
.Select(f => base.CreateProperty(f, memberSerialization))) | ||
.ToList(); | ||
|
||
props.ForEach(p => | ||
{ | ||
p.Writable = true; | ||
p.Readable = true; | ||
}); | ||
|
||
return props; | ||
} | ||
} |
Oops, something went wrong.