Skip to content

Commit

Permalink
FFM-11022 Log Flags/Groups payload (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
erdirowlands committed Mar 29, 2024
1 parent e5db133 commit 3db3ae4
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 17 deletions.
32 changes: 22 additions & 10 deletions Connected Services/HarnessOpenAPIService/HarnessOpenAPIS.cs
Expand Up @@ -4,6 +4,8 @@
// </auto-generated>
//----------------------

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?'
Expand Down Expand Up @@ -63,9 +65,9 @@ public string BaseUrl
/// <param name="cluster">Unique identifier for the cluster for the account</param>
/// <returns>OK</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public virtual System.Threading.Tasks.Task<System.Collections.Generic.ICollection<FeatureConfig>> ClientEnvFeatureConfigsGetAsync(string environmentUUID, string cluster)
public virtual System.Threading.Tasks.Task<System.Collections.Generic.ICollection<FeatureConfig>> ClientEnvFeatureConfigsGetAsync(string environmentUUID, string cluster, ILogger logger)
{
return ClientEnvFeatureConfigsGetAsync(environmentUUID, cluster, System.Threading.CancellationToken.None);
return ClientEnvFeatureConfigsGetAsync(environmentUUID, cluster, System.Threading.CancellationToken.None, logger);
}

/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
Expand All @@ -79,7 +81,7 @@ public virtual System.Threading.Tasks.Task<System.Collections.Generic.ICollectio
/// <param name="cluster">Unique identifier for the cluster for the account</param>
/// <returns>OK</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public virtual async System.Threading.Tasks.Task<System.Collections.Generic.ICollection<FeatureConfig>> ClientEnvFeatureConfigsGetAsync(string environmentUUID, string cluster, System.Threading.CancellationToken cancellationToken)
public virtual async System.Threading.Tasks.Task<System.Collections.Generic.ICollection<FeatureConfig>> ClientEnvFeatureConfigsGetAsync(string environmentUUID, string cluster, System.Threading.CancellationToken cancellationToken, ILogger logger)
{
if (environmentUUID == null)
throw new System.ArgumentNullException("environmentUUID");
Expand Down Expand Up @@ -125,13 +127,18 @@ public virtual async System.Threading.Tasks.Task<System.Collections.Generic.ICol
var status_ = (int)response_.StatusCode;
if (status_ == 200)
{
var rawResponseData = await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
// Log the raw JSON response data
logger.LogInformation("Raw FlagJSON response data: {RawResponseData}", rawResponseData);

var objectResponse_ = await ReadObjectResponseAsync<System.Collections.Generic.ICollection<FeatureConfig>>(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}

else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
Expand Down Expand Up @@ -160,7 +167,7 @@ public virtual async System.Threading.Tasks.Task<System.Collections.Generic.ICol
/// <param name="cluster">Unique identifier for the cluster for the account</param>
/// <returns>OK</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public virtual System.Threading.Tasks.Task<FeatureConfig> ClientEnvFeatureConfigsGetAsync(string identifier, string environmentUUID, string cluster)
public virtual System.Threading.Tasks.Task<FeatureConfig> ClientEnvFeatureConfigsGetAsync(string identifier, string environmentUUID, string cluster, ILogger logger)
{
return ClientEnvFeatureConfigsGetAsync(identifier, environmentUUID, cluster, System.Threading.CancellationToken.None);
}
Expand Down Expand Up @@ -261,9 +268,9 @@ public virtual async System.Threading.Tasks.Task<FeatureConfig> ClientEnvFeature
/// <param name="cluster">Unique identifier for the cluster for the account</param>
/// <returns>OK</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public virtual System.Threading.Tasks.Task<System.Collections.Generic.ICollection<Segment>> ClientEnvTargetSegmentsGetAsync(string environmentUUID, string cluster)
public virtual System.Threading.Tasks.Task<System.Collections.Generic.ICollection<Segment>> ClientEnvTargetSegmentsGetAsync(string environmentUUID, string cluster, ILogger logger)
{
return ClientEnvTargetSegmentsGetAsync(environmentUUID, cluster, System.Threading.CancellationToken.None);
return ClientEnvTargetSegmentsGetAsync(environmentUUID, cluster, System.Threading.CancellationToken.None, logger);
}

/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
Expand All @@ -277,7 +284,7 @@ public virtual System.Threading.Tasks.Task<System.Collections.Generic.ICollectio
/// <param name="cluster">Unique identifier for the cluster for the account</param>
/// <returns>OK</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public virtual async System.Threading.Tasks.Task<System.Collections.Generic.ICollection<Segment>> ClientEnvTargetSegmentsGetAsync(string environmentUUID, string cluster, System.Threading.CancellationToken cancellationToken)
public virtual async System.Threading.Tasks.Task<System.Collections.Generic.ICollection<Segment>> ClientEnvTargetSegmentsGetAsync(string environmentUUID, string cluster, System.Threading.CancellationToken cancellationToken, ILogger logger)
{
if (environmentUUID == null)
throw new System.ArgumentNullException("environmentUUID");
Expand Down Expand Up @@ -323,6 +330,11 @@ public virtual async System.Threading.Tasks.Task<System.Collections.Generic.ICol
var status_ = (int)response_.StatusCode;
if (status_ == 200)
{
var rawResponseData = await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
// Log the raw JSON response data
logger.LogInformation("Raw GroupSON response data: {RawResponseData}", rawResponseData);


var objectResponse_ = await ReadObjectResponseAsync<System.Collections.Generic.ICollection<Segment>>(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
Expand Down Expand Up @@ -401,9 +413,9 @@ public virtual async System.Threading.Tasks.Task<System.Collections.Generic.ICol
/// <param name="cluster">Unique identifier for the cluster for the account</param>
/// <returns>OK</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public virtual System.Threading.Tasks.Task<Segment> ClientEnvTargetSegmentsGetAsync(string identifier, string environmentUUID, string cluster)
public virtual System.Threading.Tasks.Task<Segment> 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);
}

/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
Expand All @@ -418,7 +430,7 @@ public virtual System.Threading.Tasks.Task<Segment> ClientEnvTargetSegmentsGetAs
/// <param name="cluster">Unique identifier for the cluster for the account</param>
/// <returns>OK</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public virtual async System.Threading.Tasks.Task<Segment> ClientEnvTargetSegmentsGetAsync(string identifier, string environmentUUID, string cluster, System.Threading.CancellationToken cancellationToken)
public virtual async System.Threading.Tasks.Task<Segment> ClientEnvTargetSegmentsGetAsync(string identifier, string environmentUUID, string cluster, System.Threading.CancellationToken cancellationToken, ILogger logger)
{
if (identifier == null)
throw new System.ArgumentNullException("identifier");
Expand Down
6 changes: 5 additions & 1 deletion client/api/PollingProcessor.cs
Expand Up @@ -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)
{
Expand All @@ -131,10 +134,11 @@ private async Task ProcessSegments()
{
logger.LogDebug("Fetching segments started");
IEnumerable<Segment> 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)
{
Expand Down
13 changes: 13 additions & 0 deletions client/api/Repository.cs
Expand Up @@ -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<FeatureConfig> flags);
void SetSegments(IEnumerable<Segment> segments);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -117,6 +129,7 @@ public void DeleteFlag(string identifier)

this.callback?.OnFlagDeleted(identifier);
}


public void DeleteSegment(string identifier)
{
Expand Down
29 changes: 26 additions & 3 deletions client/connector/HarnessConnector.cs
Expand Up @@ -241,20 +241,43 @@ private async Task<T> ReauthenticateIfNeeded<T>(Func<Task<T>> task)
}
public async Task<IEnumerable<FeatureConfig>> 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<IEnumerable<Segment>> 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<FeatureConfig> GetFlag(string identifier)
{
return ReauthenticateIfNeeded(() => harnessClient.ClientEnvFeatureConfigsGetAsync(identifier, _environment, cluster, cancelToken.Token));
}
public Task<Segment> 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)
{
Expand Down
6 changes: 3 additions & 3 deletions ff-netF48-server-sdk.csproj
Expand Up @@ -8,10 +8,10 @@
<PackageId>ff-dotnet-server-sdk</PackageId>
<RootNamespace>io.harness.cfsdk</RootNamespace>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Version>1.6.6</Version>
<Version>1.6.7</Version>
<PackOnBuild>true</PackOnBuild>
<PackageVersion>1.6.6</PackageVersion>
<AssemblyVersion>1.6.6</AssemblyVersion>
<PackageVersion>1.6.7</PackageVersion>
<AssemblyVersion>1.6.7</AssemblyVersion>
<Authors>support@harness.io</Authors>
<Copyright>Copyright © 2024</Copyright>
<PackageIconUrl>https://harness.io/icon-ff.svg</PackageIconUrl>
Expand Down

0 comments on commit 3db3ae4

Please sign in to comment.