-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01f2115
commit 93d8513
Showing
7 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...xtensions.Configuration.AzureAppConfiguration/FeatureManagement/FeatureFilterTelemetry.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
// | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Microsoft.Extensions.Configuration.AzureAppConfiguration.FeatureManagement | ||
{ | ||
/// <summary> | ||
/// Telemetry for tracking built-in feature filter usage. | ||
/// </summary> | ||
internal class FeatureFilterTelemetry | ||
{ | ||
private const string CustomFilter = "CSTM"; | ||
private const string PercentageFilter = "PRCNT"; | ||
private const string TimeWindowFilter = "TIME"; | ||
private const string TargetingFilter = "TRGT"; | ||
private const string FilterTypeDelimiter = "+"; | ||
|
||
// 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" }; | ||
private readonly List<string> TargetingFilterNames = new List<string> { "Targeting", "Microsoft.Targeting", "TargetingFilter", "Microsoft.TargetingFilter" }; | ||
|
||
public bool UsesCustomFilter { get; set; } = false; | ||
public bool UsesPercentageFilter { get; set; } = false; | ||
public bool UsesTimeWindowFilter { get; set; } = false; | ||
public bool UsesTargetingFilter { get; set; } = false; | ||
|
||
public bool UsesAnyFeatureFilter() | ||
{ | ||
return UsesCustomFilter || UsesPercentageFilter || UsesTimeWindowFilter || UsesTargetingFilter; | ||
} | ||
|
||
public void ResetFeatureFilterTelemetry() | ||
{ | ||
UsesCustomFilter = false; | ||
UsesPercentageFilter = false; | ||
UsesTimeWindowFilter = false; | ||
UsesTargetingFilter = false; | ||
} | ||
|
||
public void UpdateFeatureFilterTelemetry(string filterName) | ||
{ | ||
if (PercentageFilterNames.Any(name => string.Equals(name, filterName, StringComparison.OrdinalIgnoreCase))) | ||
{ | ||
UsesPercentageFilter = true; | ||
} | ||
else if (TimeWindowFilterNames.Any(name => string.Equals(name, filterName, StringComparison.OrdinalIgnoreCase))) | ||
{ | ||
UsesTimeWindowFilter = true; | ||
} | ||
else if (TargetingFilterNames.Any(name => string.Equals(name, filterName, StringComparison.OrdinalIgnoreCase))) | ||
{ | ||
UsesTargetingFilter = true; | ||
} | ||
else | ||
{ | ||
UsesCustomFilter = true; | ||
} | ||
} | ||
|
||
/// <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 override string ToString() | ||
{ | ||
if (!UsesAnyFeatureFilter()) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
var sb = new StringBuilder(); | ||
|
||
if (UsesCustomFilter) | ||
{ | ||
sb.Append(CustomFilter); | ||
} | ||
|
||
if (UsesPercentageFilter) | ||
{ | ||
if (sb.Length > 0) | ||
{ | ||
sb.Append(FilterTypeDelimiter); | ||
} | ||
|
||
sb.Append(PercentageFilter); | ||
} | ||
|
||
if (UsesTimeWindowFilter) | ||
{ | ||
if (sb.Length > 0) | ||
{ | ||
sb.Append(FilterTypeDelimiter); | ||
} | ||
|
||
sb.Append(TimeWindowFilter); | ||
} | ||
|
||
if (UsesTargetingFilter) | ||
{ | ||
if (sb.Length > 0) | ||
{ | ||
sb.Append(FilterTypeDelimiter); | ||
} | ||
|
||
sb.Append(TargetingFilter); | ||
} | ||
|
||
return sb.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters