Skip to content

Commit 2c34e3a

Browse files
committed
Updating for allowing RequiredMinimumPollIntervalInSeconds property to be supplied at the time of setup
Signed-off-by: Ash.Wani <[email protected]>
1 parent 12f6863 commit 2c34e3a

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

src/OpenFeature.Contrib.Providers.AwsAppConfig/AppConfigProvider.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,24 @@ public class AppConfigProvider : FeatureProvider
1919
private readonly string _applicationName;
2020

2121
// The environment (e.g., prod, dev, staging) in AWS AppConfig
22-
private readonly string _environmentName;
22+
private readonly string _environmentName;
23+
24+
private readonly int _minimumPollIntervalInSeconds;
2325

2426
/// <summary>
2527
/// Returns metadata about the provider
2628
/// </summary>
2729
/// <returns>Metadata object containing provider information</returns>
2830
public override Metadata GetMetadata() => new Metadata("AWS AppConfig Provider");
29-
31+
3032
/// <summary>
3133
/// Constructor for AwsAppConfigProvider
3234
/// </summary>
3335
/// <param name="retrievalApi">The AWS AppConfig retrieval API</param>
3436
/// <param name="applicationName">The name of the application in AWS AppConfig</param>
35-
/// <param name="environmentName">The environment (e.g., prod, dev, staging) in AWS AppConfig</param>
36-
public AppConfigProvider(IRetrievalApi retrievalApi, string applicationName, string environmentName)
37+
/// <param name="environmentName">The environment (e.g., prod, dev, staging) in AWS AppConfig</param>
38+
/// <param name="minimumPollIntervalInSeconds">Client cannot call GetLatest more frequently than every specified seconds. Range 15-86400.</param>
39+
public AppConfigProvider(IRetrievalApi retrievalApi, string applicationName, string environmentName, int minimumPollIntervalInSeconds = 15)
3740
{
3841
// Application name, environment name and configuration profile ID is needed for connecting to AWS Appconfig.
3942
// If any of these are missing, an exception will be thrown.
@@ -46,7 +49,8 @@ public AppConfigProvider(IRetrievalApi retrievalApi, string applicationName, str
4649

4750
_appConfigRetrievalApi = retrievalApi;
4851
_applicationName = applicationName;
49-
_environmentName = environmentName;
52+
_environmentName = environmentName;
53+
_minimumPollIntervalInSeconds = minimumPollIntervalInSeconds;
5054
}
5155

5256
/// <summary>
@@ -175,7 +179,7 @@ private async Task<Value> ResolveFeatureFlagValue(string flagKey, Value defaultV
175179
/// and returns it in its raw string format. The returned string is expected to be
176180
/// in JSON format that can be parsed into feature flag configurations.
177181
/// </remarks>
178-
/// <exception cref="AmazonAppConfigException">Thrown when there is an error retrieving the configuration from AWS AppConfig.</exception>
182+
/// <exception cref="AmazonAppConfigDataException">Thrown when there is an error retrieving the configuration from AWS AppConfig.</exception>
179183
private async Task<string> GetFeatureFlagsResponseJson(string configurationProfileId, EvaluationContext context = null)
180184
{
181185
var response = await GetFeatureFlagsStreamAsync(configurationProfileId, context);
@@ -198,6 +202,7 @@ private async Task<GetLatestConfigurationResponse> GetFeatureFlagsStreamAsync(st
198202
{
199203
ApplicationIdentifier = _applicationName,
200204
EnvironmentIdentifier = _environmentName,
205+
RequiredMinimumPollIntervalInSeconds = _minimumPollIntervalInSeconds,
201206
ConfigurationProfileIdentifier = configurationProfileId
202207
};
203208

src/OpenFeature.Contrib.Providers.AwsAppConfig/AppConfigRetrievalApi.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ private async Task<string> GetSessionToken(FeatureFlagProfile profile)
178178
{
179179
ApplicationIdentifier = profile.ApplicationIdentifier,
180180
EnvironmentIdentifier = profile.EnvironmentIdentifier,
181-
ConfigurationProfileIdentifier = profile.ConfigurationProfileIdentifier
181+
ConfigurationProfileIdentifier = profile.ConfigurationProfileIdentifier,
182+
RequiredMinimumPollIntervalInSeconds = profile.RequiredMinimumPollIntervalInSeconds
182183
};
183184

184185
var sessionResponse = await _appConfigDataClient.StartConfigurationSessionAsync(request);

src/OpenFeature.Contrib.Providers.AwsAppConfig/FeatureFlagProfile.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ public class FeatureFlagProfile
1919
/// </summary>
2020
public string EnvironmentIdentifier { get; set; }
2121

22+
/// <summary>
23+
/// Gets or sets the minimum polling interval in seconds for AWS AppConfig.
24+
/// This value determines the minimum time that must elapse between configuration refresh attempts.
25+
/// The default value set here is 15 seconds, which aligns with AWS AppConfig's minimum supported interval.
26+
/// Range 15 to 86400 seconds.
27+
/// </summary>
28+
/// <remarks>
29+
/// AWS AppConfig enforces a minimum interval of 15 seconds between configuration refresh attempts.
30+
/// Setting a value lower than 15 seconds may result in throttling by the service.
31+
/// </remarks>
32+
public int RequiredMinimumPollIntervalInSeconds {get; set;} = 15;
33+
2234
/// <summary>
2335
/// Gets or sets the AWS AppConfig configuration profile identifier.
2436
/// This identifies the specific configuration profile containing the feature flags.

src/OpenFeature.Contrib.Providers.AwsAppConfig/README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,16 @@ This package maintains the aforementioned structure by supplying values in two d
4747

4848
**Stage 1: Setup**
4949

50-
During this stage, the Application and Environment are provided at the initiation of the project. It is expected that these two values remain constant throughout the application's lifetime. If a change is necessary, a restart of the application will be required.
50+
During this stage, the Application and Environment are provided at the initiation of the project. It is expected that these two values remain static during the application's lifetime. If a change is necessary, a restart of the application will be required.
51+
52+
Additionally, at this point Required Minimum Polling Interval in seconds can also be configured by supplying integer value of seconds you would like to set. Default is 15 seconds and maximum allowed by AWS id 86400 seconds.
5153

5254
**Stage 2: Fetching Value**
5355

5456
In this stage, to retrieve the AWS AppConfig feature flag, the key should be supplied in the format `configurationProfileId:flagKey[:attributeKey]`. If the AttributeKey is not included, all attributes will be returned as a structured object.
5557

58+
## Important information about the implementation
59+
As per AWS AppConfig documentation, the recommended way to access AWS AppConfig is by using
5660

5761
## Usage
5862

@@ -89,11 +93,12 @@ namespace OpenFeatureTestApp
8993

9094
// Replace these values with your AWS AppConfig settings
9195
const string application = "YourApplication";
92-
const string environment = "YourEnvironment";
96+
const string environment = "YourEnvironment";
97+
const int pollingIntervalSeconds = 60; // default is 15
9398
9499
await Api.Instance.SetProviderAsync(
95-
new AppConfigProvider(appConfigRetrievalApi, application, environment)
96-
);
100+
new AppConfigProvider(appConfigRetrievalApi, application, environment, pollingIntervalSeconds)
101+
);
97102
}
98103
}
99104
}

test/OpenFeature.Contrib.Providers.AwsAppConfig.Test/AppCOnfigRetrievalApiTests.cs renamed to test/OpenFeature.Contrib.Providers.AwsAppConfig.Test/AppConfigRetrievalApiTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
using Xunit;
22
using Moq;
33
using System;
4-
using OpenFeature.Model;
54
using Amazon.AppConfigData;
65
using Amazon.AppConfigData.Model;
76
using System.Text;
87
using OpenFeature.Contrib.Providers.AwsAppConfig;
98
using System.Threading;
109
using System.Threading.Tasks;
11-
using System.Collections.Generic;
1210
using System.IO;
1311
using Microsoft.Extensions.Caching.Memory;
1412
public class AppConfigRetrievalApiTests

0 commit comments

Comments
 (0)