Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyuanliang-ms committed Aug 15, 2024
1 parent 7a5fcfa commit d730fd6
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ namespace Microsoft.Extensions.Configuration.AzureAppConfiguration.FeatureManage
/// </summary>
internal class FeatureFlagTracing
{
private const string CustomFilter = "CSTM";
private const string PercentageFilter = "PRCNT";
private const string TimeWindowFilter = "TIME";
private const string TargetingFilter = "TRGT";

// Built-in Feature Filter Names
private readonly List<string> PercentageFilterNames = new List<string> { "Percentage", "Microsoft.Percentage", "PercentageFilter", "Microsoft.PercentageFilter" };
private readonly List<string> TimeWindowFilterNames = new List<string> { "TimeWindow", "Microsoft.TimeWindow", "TimeWindowFilter", "Microsoft.TimeWindowFilter" };
Expand Down Expand Up @@ -82,5 +77,87 @@ public void NotifyMaxVariants(int currentFlagTotalVariants)
MaxVariants = currentFlagTotalVariants;
}
}

/// <summary>
/// Returns a formatted string containing code names, indicating which feature filters are used by the application.
/// </summary>
/// <returns>Formatted string like: "CSTM+PRCNT+TIME+TRGT", "PRCNT+TRGT", etc. If no filters are used, empty string will be returned.</returns>
public string CreateFiltersString()
{
var sb = new StringBuilder();

if (UsesCustomFilter)
{
sb.Append(RequestTracingConstants.CustomFilter);
}

if (UsesPercentageFilter)
{
if (sb.Length > 0)
{
sb.Append(RequestTracingConstants.Delimiter);
}

sb.Append(RequestTracingConstants.PercentageFilter);
}

if (UsesTimeWindowFilter)
{
if (sb.Length > 0)
{
sb.Append(RequestTracingConstants.Delimiter);
}

sb.Append(RequestTracingConstants.TimeWindowFilter);
}

if (UsesTargetingFilter)
{
if (sb.Length > 0)
{
sb.Append(RequestTracingConstants.Delimiter);
}

sb.Append(RequestTracingConstants.TargetingFilter);
}

return sb.ToString();
}

/// <summary>
/// Returns a formatted string containing code names, indicating which tracing features are used by feature flags.
/// </summary>
/// <returns>Formatted string like: "Seed+ConfigRef+Telemnetry". If no tracing features are used, empty string will be returned.</returns>
public string CreateFeaturesString()
{
var sb = new StringBuilder();

if (UsesSeed)
{
sb.Append(RequestTracingConstants.FeatureFlagUsesSeedTag);
}

if (UsesVariantConfigurationReference)
{
if (sb.Length > 0)
{
sb.Append(RequestTracingConstants.Delimiter);
}

sb.Append(RequestTracingConstants.FeatureFlagUsesVariantConfigurationReferenceTag);
}

if (UsesTelemetry)
{
if (sb.Length > 0)
{
sb.Append(RequestTracingConstants.Delimiter);
}

sb.Append(RequestTracingConstants.FeatureFlagUsesTelemetryTag);
}

return sb.ToString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,31 @@ public bool UsesAnyTracingFeature()
{
return IsLoadBalancingEnabled || IsSignalRUsed;
}

/// <summary>
/// Returns a formatted string containing code names, indicating which tracing features are used by the application.
/// </summary>
/// <returns>Formatted string like: "LB+SignalR". If no tracing features are used, empty string will be returned.</returns>
public string CreateFeaturesString()
{
var sb = new StringBuilder();

if (IsLoadBalancingEnabled)
{
sb.Append(RequestTracingConstants.LoadBalancingEnabledTag);
}

if (IsSignalRUsed)
{
if (sb.Length > 0)
{
sb.Append(RequestTracingConstants.Delimiter);
}

sb.Append(RequestTracingConstants.SignalRUsedTag);
}

return sb.ToString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private static string CreateCorrelationContextHeader(RequestType requestType, Re

if (requestTracingOptions.FeatureFlagTracing.UsesAnyFeatureFilter())
{
correlationContextKeyValues.Add(new KeyValuePair<string, string>(RequestTracingConstants.FeatureFlagFilterTypeKey, CreateFiltersString(requestTracingOptions.FeatureFlagTracing)));
correlationContextKeyValues.Add(new KeyValuePair<string, string>(RequestTracingConstants.FeatureFlagFilterTypeKey, requestTracingOptions.FeatureFlagTracing.CreateFiltersString()));
}

if (requestTracingOptions.FeatureFlagTracing.MaxVariants > 0)
Expand All @@ -169,7 +169,7 @@ private static string CreateCorrelationContextHeader(RequestType requestType, Re

if (requestTracingOptions.FeatureFlagTracing.UsesAnyTracingFeature())
{
correlationContextKeyValues.Add(new KeyValuePair<string, string>(RequestTracingConstants.FeatureFlagFeaturesKey, CreateFeatureFlagFeaturesString(requestTracingOptions.FeatureFlagTracing)));
correlationContextKeyValues.Add(new KeyValuePair<string, string>(RequestTracingConstants.FeatureFlagFeaturesKey, requestTracingOptions.FeatureFlagTracing.CreateFeaturesString()));
}

if (requestTracingOptions.FeatureManagementVersion != null)
Expand All @@ -184,7 +184,7 @@ private static string CreateCorrelationContextHeader(RequestType requestType, Re

if (requestTracingOptions.UsesAnyTracingFeature())
{
correlationContextKeyValues.Add(new KeyValuePair<string, string>(RequestTracingConstants.FeaturesKey, CreateFeaturesString(requestTracingOptions)));
correlationContextKeyValues.Add(new KeyValuePair<string, string>(RequestTracingConstants.FeaturesKey, requestTracingOptions.CreateFeaturesString()));
}

if (requestTracingOptions.IsKeyVaultConfigured)
Expand Down Expand Up @@ -226,113 +226,5 @@ private static string CreateCorrelationContextHeader(RequestType requestType, Re

return sb.ToString();
}

/// <summary>
/// Returns a formatted string containing code names, indicating which tracing features are used by the application.
/// </summary>
/// <returns>Formatted string like: "LB+SignalR". If no tracing features are used, empty string will be returned.</returns>
private static string CreateFeaturesString(RequestTracingOptions requestTracingOptions)
{
var sb = new StringBuilder();

if (requestTracingOptions.IsLoadBalancingEnabled)
{
sb.Append(RequestTracingConstants.LoadBalancingEnabledTag);
}

if (requestTracingOptions.IsSignalRUsed)
{
if (sb.Length > 0)
{
sb.Append(RequestTracingConstants.Delimiter);
}

sb.Append(RequestTracingConstants.SignalRUsedTag);
}

return sb.ToString();
}

/// <summary>
/// Returns a formatted string containing code names, indicating which tracing features are used by feature flags.
/// </summary>
/// <returns>Formatted string like: "Seed+ConfigRef+Telemnetry". If no tracing features are used, empty string will be returned.</returns>
private static string CreateFeatureFlagFeaturesString(FeatureFlagTracing featureFlagTracing)
{
var sb = new StringBuilder();

if (featureFlagTracing.UsesSeed)
{
sb.Append(RequestTracingConstants.FeatureFlagUsesSeedTag);
}

if (featureFlagTracing.UsesVariantConfigurationReference)
{
if (sb.Length > 0)
{
sb.Append(RequestTracingConstants.Delimiter);
}

sb.Append(RequestTracingConstants.FeatureFlagUsesVariantConfigurationReferenceTag);
}

if (featureFlagTracing.UsesTelemetry)
{
if (sb.Length > 0)
{
sb.Append(RequestTracingConstants.Delimiter);
}

sb.Append(RequestTracingConstants.FeatureFlagUsesTelemetryTag);
}

return sb.ToString();
}

/// <summary>
/// Returns a formatted string containing code names, indicating which feature filters are used by the application.
/// </summary>
/// <returns>Formatted string like: "CSTM+PRCNT+TIME+TRGT". If no filters are used, empty string will be returned.</returns>
private static string CreateFiltersString(FeatureFlagTracing featureFlagTracing)
{
var sb = new StringBuilder();

if (featureFlagTracing.UsesCustomFilter)
{
sb.Append(RequestTracingConstants.CustomFilter);
}

if (featureFlagTracing.UsesPercentageFilter)
{
if (sb.Length > 0)
{
sb.Append(RequestTracingConstants.Delimiter);
}

sb.Append(RequestTracingConstants.PercentageFilter);
}

if (featureFlagTracing.UsesTimeWindowFilter)
{
if (sb.Length > 0)
{
sb.Append(RequestTracingConstants.Delimiter);
}

sb.Append(RequestTracingConstants.TimeWindowFilter);
}

if (featureFlagTracing.UsesTargetingFilter)
{
if (sb.Length > 0)
{
sb.Append(RequestTracingConstants.Delimiter);
}

sb.Append(RequestTracingConstants.TargetingFilter);
}

return sb.ToString();
}
}
}

0 comments on commit d730fd6

Please sign in to comment.