-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
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 was deleted.
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, | ||
Check warning on line 50 in src/AssociationRegistry.Acm.Api/Infrastructure/Metrics/ProjectionStateListener.cs GitHub Actions / Build ACM Api / build-image
Check warning on line 50 in src/AssociationRegistry.Acm.Api/Infrastructure/Metrics/ProjectionStateListener.cs GitHub Actions / Build ACM Api / build-image
|
||
"UpdateProjectionProgress" => opperation.GetType().GetProperty("Range").GetValue(opperation) as EventRange, | ||
Check warning on line 51 in src/AssociationRegistry.Acm.Api/Infrastructure/Metrics/ProjectionStateListener.cs GitHub Actions / Build ACM Api / build-image
|
||
_ => 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; | ||
} | ||
} |
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(); | ||
} | ||
} |
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) | ||
Check warning on line 55 in src/AssociationRegistry.Admin.ProjectionHost/Infrastructure/Metrics/ProjectionStateListener.cs GitHub Actions / Build Admin Projections / build-image
Check warning on line 55 in src/AssociationRegistry.Admin.ProjectionHost/Infrastructure/Metrics/ProjectionStateListener.cs GitHub Actions / Build Admin Projections / build-image
|
||
.GetValue(opperation) as EventRange, | ||
"UpdateProjectionProgress" => opperation.GetType().GetProperty("Range").GetValue(opperation) as EventRange, | ||
Check warning on line 57 in src/AssociationRegistry.Admin.ProjectionHost/Infrastructure/Metrics/ProjectionStateListener.cs GitHub Actions / Build Admin Projections / build-image
Check warning on line 57 in src/AssociationRegistry.Admin.ProjectionHost/Infrastructure/Metrics/ProjectionStateListener.cs GitHub Actions / Build Admin Projections / build-image
|
||
_ => 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; | ||
} | ||
} |