From 5efc62379203102e34f6e55ac939193b144db30e Mon Sep 17 00:00:00 2001 From: Mikhail Movchan <15570482+ruhex@users.noreply.github.com> Date: Thu, 11 Jun 2026 22:21:56 +0300 Subject: [PATCH] feat: improve logging and streamline peer creation/update logic - Add detailed logging for `CreatePeer` and `UpdatePeer` operations to track input and processed data. - Simplify `SetSubscriptions`, `SetCustomPrefixes`, and `SetCustomAsns` calls by removing conditional checks. --- BGPLite.Api/ManagementApi.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/BGPLite.Api/ManagementApi.cs b/BGPLite.Api/ManagementApi.cs index 26b7b17..e131d61 100644 --- a/BGPLite.Api/ManagementApi.cs +++ b/BGPLite.Api/ManagementApi.cs @@ -289,6 +289,11 @@ public sealed class ManagementApi : IHostedService, IDisposable var asnLists = data.AsnLists ?? []; var customPrefixes = new List<(string Prefix, byte Length)>(); + _logger.LogInformation("CreatePeer raw body: {Body}", body); + _logger.LogInformation("CreatePeer deserialized: AsnLists={Lists}, CustomPrefixes={Prefixes}, CustomAsns={Asns}", + string.Join(",", asnLists), string.Join(",", data.CustomPrefixes ?? []), + string.Join(",", data.CustomAsns ?? [])); + if (data.CustomPrefixes is not null) { foreach (var cidr in data.CustomPrefixes) @@ -303,12 +308,9 @@ public sealed class ManagementApi : IHostedService, IDisposable } var id = _store.CreatePeer(data.Ip, data.Asn, data.Description); - if (asnLists.Count > 0) - _store.SetSubscriptions(id, asnLists); - if (customPrefixes.Count > 0) - _store.SetCustomPrefixes(id, customPrefixes); - if (data.CustomAsns is { Count: > 0 }) - _store.SetCustomAsns(id, data.CustomAsns); + _store.SetSubscriptions(id, asnLists); + _store.SetCustomPrefixes(id, customPrefixes); + _store.SetCustomAsns(id, data.CustomAsns ?? []); var peer = _store.GetDbPeerById(id); @@ -380,6 +382,8 @@ public sealed class ManagementApi : IHostedService, IDisposable _store.SetSubscriptions(peerId, data.Lists); var customPrefixes = data.CustomPrefixes ?? []; + _logger.LogInformation("UpdatePeer {Id}: CustomPrefixes={Count}, CustomAsns={AsnCount}, raw={Raw}", + peerId, customPrefixes.Count, (data.CustomAsns ?? []).Count, body); var parsed = new List<(string, byte)>(); foreach (var cidr in customPrefixes) {