Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Log fusion cache in memory entry #1527

Merged
merged 11 commits into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
using Altinn.Authorization.ABAC.Xacml.JsonProfile;
Expand All @@ -23,7 +24,6 @@ internal sealed class AltinnAuthorizationClient : IAltinnAuthorization
private readonly IFusionCache _partiesCache;
private readonly IUser _user;
private readonly ILogger _logger;
private readonly IMemoryCache _inMemoryCache;

private static readonly JsonSerializerOptions SerializerOptions = new()
{
Expand All @@ -35,15 +35,13 @@ public AltinnAuthorizationClient(
HttpClient client,
IFusionCacheProvider cacheProvider,
IUser user,
ILogger<AltinnAuthorizationClient> logger,
IMemoryCache inMemoryCache)
ILogger<AltinnAuthorizationClient> logger)
{
_httpClient = client ?? throw new ArgumentNullException(nameof(client));
_pdpCache = cacheProvider.GetCache(nameof(Authorization)) ?? throw new ArgumentNullException(nameof(cacheProvider));
_partiesCache = cacheProvider.GetCache(nameof(AuthorizedPartiesResult)) ?? throw new ArgumentNullException(nameof(cacheProvider));
_user = user ?? throw new ArgumentNullException(nameof(user));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_inMemoryCache = inMemoryCache;
}

public async Task<DialogDetailsAuthorizationResult> GetDialogDetailsAuthorization(
Expand Down Expand Up @@ -90,9 +88,17 @@ public async Task<AuthorizedPartiesResult> GetAuthorizedParties(IPartyIdentifier
var authorizedParties = await _partiesCache.GetOrSetAsync(cacheKey, async token
=> await PerformAuthorizedPartiesRequest(authorizedPartiesRequest, token), token: cancellationToken);

var inMemoryCacheValue = _inMemoryCache.TryGetValue<AuthorizedPartiesResult>(cacheKey, out var inMemoryCacheEntry);
_logger.LogInformation("In memory cache value for {CacheKey}, success: {InMemoryCacheValue} value: {@InMemoryCacheEntry}",
cacheKey, inMemoryCacheValue, inMemoryCacheEntry);
var mcaField = typeof(FusionCache).GetField("_mca", BindingFlags.NonPublic | BindingFlags.Instance);
var mcaValue = mcaField?.GetValue(_partiesCache);
var mcField = mcaValue!.GetType().GetField("_cache", BindingFlags.NonPublic | BindingFlags.Instance);
var mcValue = mcField?.GetValue(mcaValue) as IMemoryCache;

var inMemoryCacheValue = mcValue!.TryGetValue(cacheKey, out var inMemoryCacheEntry);
var inMemoryCacheEntryValue = inMemoryCacheEntry?.GetType().GetProperty("Value")?.GetValue(inMemoryCacheEntry);

_logger.LogInformation("In memory cache value for {CacheKey}, success: {InMemoryCacheValue} value: {@inMemoryCacheEntryValue}",
cacheKey, inMemoryCacheValue, inMemoryCacheEntryValue);


// Temporary logging to debug missing authorized sub parties
_logger.LogInformation("Authorized parties for {Party}: {@AuthorizedParties}", authenticatedParty, authorizedParties);
Expand Down
Loading