From 3db3ae4be8557a554cf594ad63ec7539fdd3f56a Mon Sep 17 00:00:00 2001 From: Erdi Rowlands Date: Fri, 29 Mar 2024 18:38:30 +0000 Subject: [PATCH] FFM-11022 Log Flags/Groups payload (#113) --- .../HarnessOpenAPIService/HarnessOpenAPIS.cs | 32 +++++++++++++------ client/api/PollingProcessor.cs | 6 +++- client/api/Repository.cs | 13 ++++++++ client/connector/HarnessConnector.cs | 29 +++++++++++++++-- ff-netF48-server-sdk.csproj | 6 ++-- 5 files changed, 69 insertions(+), 17 deletions(-) diff --git a/Connected Services/HarnessOpenAPIService/HarnessOpenAPIS.cs b/Connected Services/HarnessOpenAPIService/HarnessOpenAPIS.cs index 4f15aab..a6d5f7e 100644 --- a/Connected Services/HarnessOpenAPIService/HarnessOpenAPIS.cs +++ b/Connected Services/HarnessOpenAPIService/HarnessOpenAPIS.cs @@ -4,6 +4,8 @@ // //---------------------- +using Microsoft.Extensions.Logging; + #pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." #pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." #pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' @@ -63,9 +65,9 @@ public string BaseUrl /// Unique identifier for the cluster for the account /// OK /// A server side error occurred. - public virtual System.Threading.Tasks.Task> ClientEnvFeatureConfigsGetAsync(string environmentUUID, string cluster) + public virtual System.Threading.Tasks.Task> ClientEnvFeatureConfigsGetAsync(string environmentUUID, string cluster, ILogger logger) { - return ClientEnvFeatureConfigsGetAsync(environmentUUID, cluster, System.Threading.CancellationToken.None); + return ClientEnvFeatureConfigsGetAsync(environmentUUID, cluster, System.Threading.CancellationToken.None, logger); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. @@ -79,7 +81,7 @@ public virtual System.Threading.Tasks.TaskUnique identifier for the cluster for the account /// OK /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> ClientEnvFeatureConfigsGetAsync(string environmentUUID, string cluster, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task> ClientEnvFeatureConfigsGetAsync(string environmentUUID, string cluster, System.Threading.CancellationToken cancellationToken, ILogger logger) { if (environmentUUID == null) throw new System.ArgumentNullException("environmentUUID"); @@ -125,6 +127,10 @@ public virtual async System.Threading.Tasks.Task>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { @@ -132,6 +138,7 @@ public virtual async System.Threading.Tasks.TaskUnique identifier for the cluster for the account /// OK /// A server side error occurred. - public virtual System.Threading.Tasks.Task ClientEnvFeatureConfigsGetAsync(string identifier, string environmentUUID, string cluster) + public virtual System.Threading.Tasks.Task ClientEnvFeatureConfigsGetAsync(string identifier, string environmentUUID, string cluster, ILogger logger) { return ClientEnvFeatureConfigsGetAsync(identifier, environmentUUID, cluster, System.Threading.CancellationToken.None); } @@ -261,9 +268,9 @@ public virtual async System.Threading.Tasks.Task ClientEnvFeature /// Unique identifier for the cluster for the account /// OK /// A server side error occurred. - public virtual System.Threading.Tasks.Task> ClientEnvTargetSegmentsGetAsync(string environmentUUID, string cluster) + public virtual System.Threading.Tasks.Task> ClientEnvTargetSegmentsGetAsync(string environmentUUID, string cluster, ILogger logger) { - return ClientEnvTargetSegmentsGetAsync(environmentUUID, cluster, System.Threading.CancellationToken.None); + return ClientEnvTargetSegmentsGetAsync(environmentUUID, cluster, System.Threading.CancellationToken.None, logger); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. @@ -277,7 +284,7 @@ public virtual System.Threading.Tasks.TaskUnique identifier for the cluster for the account /// OK /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> ClientEnvTargetSegmentsGetAsync(string environmentUUID, string cluster, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task> ClientEnvTargetSegmentsGetAsync(string environmentUUID, string cluster, System.Threading.CancellationToken cancellationToken, ILogger logger) { if (environmentUUID == null) throw new System.ArgumentNullException("environmentUUID"); @@ -323,6 +330,11 @@ public virtual async System.Threading.Tasks.Task>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { @@ -401,9 +413,9 @@ public virtual async System.Threading.Tasks.TaskUnique identifier for the cluster for the account /// OK /// A server side error occurred. - public virtual System.Threading.Tasks.Task ClientEnvTargetSegmentsGetAsync(string identifier, string environmentUUID, string cluster) + public virtual System.Threading.Tasks.Task ClientEnvTargetSegmentsGetAsync(string identifier, string environmentUUID, string cluster, ILogger logger) { - return ClientEnvTargetSegmentsGetAsync(identifier, environmentUUID, cluster, System.Threading.CancellationToken.None); + return ClientEnvTargetSegmentsGetAsync(identifier, environmentUUID, cluster, System.Threading.CancellationToken.None, logger); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. @@ -418,7 +430,7 @@ public virtual System.Threading.Tasks.Task ClientEnvTargetSegmentsGetAs /// Unique identifier for the cluster for the account /// OK /// A server side error occurred. - public virtual async System.Threading.Tasks.Task ClientEnvTargetSegmentsGetAsync(string identifier, string environmentUUID, string cluster, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task ClientEnvTargetSegmentsGetAsync(string identifier, string environmentUUID, string cluster, System.Threading.CancellationToken cancellationToken, ILogger logger) { if (identifier == null) throw new System.ArgumentNullException("identifier"); diff --git a/client/api/PollingProcessor.cs b/client/api/PollingProcessor.cs index e5734cd..1b22f53 100644 --- a/client/api/PollingProcessor.cs +++ b/client/api/PollingProcessor.cs @@ -118,6 +118,9 @@ private async Task ProcessFlags() logger.LogDebug("Fetching flags finished"); repository.SetFlags(flags); + + logger.LogInformation("Flag cache loaded {GetFlagsCount} flags", repository.GetFlagsCount()); + } catch (Exception ex) { @@ -131,10 +134,11 @@ private async Task ProcessSegments() { logger.LogDebug("Fetching segments started"); IEnumerable segments = await connector.GetSegments(); + logger.LogInformation("Count of segments {}", segments.Count()); logger.LogDebug("Fetching segments finished"); repository.SetSegments(segments); - logger.LogDebug("Loaded {SegmentRuleCount}", segments.Count()); + logger.LogInformation("Group cache loaded {SegmentRuleCount} groups", repository.GetSegmentsCount()); } catch (Exception ex) { diff --git a/client/api/Repository.cs b/client/api/Repository.cs index 9673a57..2e1d974 100644 --- a/client/api/Repository.cs +++ b/client/api/Repository.cs @@ -22,6 +22,8 @@ internal interface IRepository { void SetFlag(string identifier, FeatureConfig featureConfig); void SetSegment(string identifier, Segment segment); + int GetFlagsCount(); + int GetSegmentsCount(); void SetFlags(IEnumerable flags); void SetSegments(IEnumerable segments); @@ -54,6 +56,16 @@ public StorageRepository(ICache cache, IStore store, IRepositoryCallback callbac private string FlagKey(string identifier) { return "flags_" + identifier; } private string SegmentKey(string identifier) { return "segments_" + identifier; } + + public int GetFlagsCount() + { + return cache.Keys().Count(key => key.StartsWith("flags_")); + } + + public int GetSegmentsCount() + { + return cache.Keys().Count(key => key.StartsWith("segments_")); + } public FeatureConfig GetFlag(string identifier) { @@ -117,6 +129,7 @@ public void DeleteFlag(string identifier) this.callback?.OnFlagDeleted(identifier); } + public void DeleteSegment(string identifier) { diff --git a/client/connector/HarnessConnector.cs b/client/connector/HarnessConnector.cs index e15295c..4130fe4 100644 --- a/client/connector/HarnessConnector.cs +++ b/client/connector/HarnessConnector.cs @@ -241,20 +241,43 @@ private async Task ReauthenticateIfNeeded(Func> task) } public async Task> GetFlags() { - return await ReauthenticateIfNeeded(() => harnessClient.ClientEnvFeatureConfigsGetAsync(_environment, cluster, cancelToken.Token)); + var flags = await ReauthenticateIfNeeded(() => harnessClient.ClientEnvFeatureConfigsGetAsync(_environment, cluster, cancelToken.Token, logger)); + + if (flags != null) + { + logger.LogInformation("Fetched {Count} feature flags from the server", flags.Count); + } + else + { + logger.LogInformation("No feature flags were fetched from the server"); + } + + return flags; } public async Task> GetSegments() { - return await ReauthenticateIfNeeded(() => harnessClient.ClientEnvTargetSegmentsGetAsync(_environment, cluster, cancelToken.Token)); + var segments = await ReauthenticateIfNeeded(() => harnessClient.ClientEnvTargetSegmentsGetAsync(_environment, cluster, cancelToken.Token, logger)); + + if (segments != null) + { + logger.LogInformation("Fetched {Count} segments from the server", segments.Count); + } + else + { + logger.LogInformation("No segments were fetched from the server"); + } + + return segments; } + public Task GetFlag(string identifier) { return ReauthenticateIfNeeded(() => harnessClient.ClientEnvFeatureConfigsGetAsync(identifier, _environment, cluster, cancelToken.Token)); } public Task GetSegment(string identifier) { - return ReauthenticateIfNeeded(() => harnessClient.ClientEnvTargetSegmentsGetAsync(identifier, _environment, cluster, cancelToken.Token)); + return ReauthenticateIfNeeded(() => harnessClient.ClientEnvTargetSegmentsGetAsync(identifier, _environment, cluster, cancelToken.Token, logger)); } public IService Stream(IUpdateCallback updater) { diff --git a/ff-netF48-server-sdk.csproj b/ff-netF48-server-sdk.csproj index e1698b6..8027f76 100644 --- a/ff-netF48-server-sdk.csproj +++ b/ff-netF48-server-sdk.csproj @@ -8,10 +8,10 @@ ff-dotnet-server-sdk io.harness.cfsdk false - 1.6.6 + 1.6.7 true - 1.6.6 - 1.6.6 + 1.6.7 + 1.6.7 support@harness.io Copyright © 2024 https://harness.io/icon-ff.svg