Skip to content

Only check feature flags for changes when their refresh interval has elapsed - #771

Open
Rafe Kemmis (kemmis) wants to merge 1 commit into
Azure:previewfrom
kemmis:kemmis/feature-flag-refresh-interval
Open

Rafe Kemmis (kemmis) wants to merge 1 commit into
Azure:previewfrom
kemmis:kemmis/feature-flag-refresh-interval

Conversation

@kemmis

Copy link
Copy Markdown

Fixes #770.

Problem

RefreshAsync checks every feature flag selector for changes, for both feature flags (HEAD /kv?key=.appconfig.featureflag/*) and enhanced feature flags (GET /ff), on every refresh pass. refreshableFfWatchers is only used to decide whether to skip the pass entirely. So any watcher with a shorter interval, such as a sentinel registered via ConfigureRefresh, causes feature flags to be checked at that interval, and FeatureFlagOptions.SetRefreshInterval is effectively ignored.

This regressed in #738. In 8.6.1 the feature flag change check only covered refreshableFfWatchers.

Change

Build the feature flag selectors to check from refreshableFfWatchers (each UseFeatureFlags selector registers a watcher with the same name, label, and tag filters), and pass them to HaveFeatureFlagsChanged and HaveEnhancedFeatureFlagsChanged instead of _options.FeatureFlagSelectors. FeatureFlagSelector equality is value-based, so the watched-page lookups still match.

When a change is detected, all feature flags are still reloaded, as before.

Testing

  • New unit test FeatureFlagsAreNotCheckedForChangesUntilTheirRefreshIntervalElapses: an individually watched key-value (refreshAll: true, 1s interval) is due while feature flags (1 day interval) are not. It verifies the key-value is checked but neither CheckConfigurationSettingsAsync nor a second GetFeatureFlagsAsync is called. It fails without the fix and passes with it.
  • Unit tests (FullyQualifiedName!~Integration):
    • net9.0: 204/205 pass. The one failure, KeyVaultReferenceTests.ServerRequestIsMadeWhenDefaultCredentialIsSet, fails identically without this change on a machine without managed identity (IMDS unreachable).
    • net8.0: Feature management, refresh, AFD, and failover tests pass (98/98).
  • The repro from 8.7.0-preview: feature flag refresh interval is ignored; feature flags are checked on every refresh pass #770 (sentinel 1s, feature flags 10s, 30s run) against this branch: 2 feature flag checks instead of 29, matching 8.6.1.

…elapsed

RefreshAsync checked every feature flag selector (feature flags and enhanced
feature flags) on every refresh pass, so any watcher with a shorter refresh
interval, such as a sentinel key, caused feature flags to be checked at that
interval and FeatureFlagOptions.SetRefreshInterval was effectively ignored.

Limit the feature flag change check to selectors whose watcher's refresh
interval has elapsed, matching the behavior in 8.6.1.

Fixes Azure#770

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@kemmis

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant