Skip to content

Empty appsettings.json FeatureManagement section returns internal GetFeatureNamesAsync #144

Closed

Description

Not sure if the title reflects the issue correctly, but I have a dotnet app that uses Microsoft.FeatureManagement 2.3.0.

It has this configured in its appsettings.json:

  "FeatureManagement": {
    "MyFeature": false
  },

And then I thought it would be helpful to have a logger that logs all enabled or disabled features upon startup:

    public class FeatureLogger : IFeatureLogger
    {
        private readonly IFeatureManager _featureManager;
        private readonly ILogger _logger;

        public FeatureLogger(IFeatureManager featureManager, ILogger logger)
        {
            _featureManager = featureManager;
            _logger = logger.ForContext<FeatureLogger>();
        }

        public async Task LogFeatureStatus()
        {
            var features = _featureManager.GetFeatureNamesAsync();
            await foreach (var feature in features)
            {
                var isEnabled = await _featureManager.IsEnabledAsync(feature);
                _logger.Information("Feature {Feature} is {Status}", feature, isEnabled ? "enabled" : "disabled");
            }
        }
    }

It works as expected as long as I have something in the FeatureManagement section in appsettings.json:

[10:41:32 INF] Feature MyFeature is disabled

But if I decide to remove this MyFeature prop from FeatureManagement in appsettings.json:

  "FeatureManagement": {
  },

then the following is logged:

[10:42:57 INF] Feature applicationName is disabled
[10:42:57 INF] Feature ASPNETCORE_ENVIRONMENT is disabled
[10:42:57 INF] Feature ASPNETCORE_URLS is disabled
[10:42:57 INF] Feature BAMF_DESKTOP_FILE_HINT is disabled
[10:42:57 INF] Feature contentRoot is disabled
[10:42:57 INF] Feature DBUS_SESSION_BUS_ADDRESS is disabled
[10:42:57 INF] Feature DESKTOP_SESSION is disabled
[10:42:57 INF] Feature DISPLAY is disabled
[10:42:57 INF] Feature DOTNET_ROOT is disabled
[10:42:57 INF] Feature ENVIRONMENT is disabled
[10:42:57 INF] Feature GDMSESSION is disabled
[10:42:57 INF] Feature GIO_LAUNCHED_DESKTOP_FILE is disabled
[10:42:57 INF] Feature GIO_LAUNCHED_DESKTOP_FILE_PID is disabled
[10:42:57 INF] Feature GJS_DEBUG_OUTPUT is disabled
[10:42:57 INF] Feature GJS_DEBUG_TOPICS is disabled
[10:42:57 INF] Feature GNOME_DESKTOP_SESSION_ID is disabled
[10:42:57 INF] Feature GNOME_SHELL_SESSION_MODE is disabled
[10:42:57 INF] Feature GPG_AGENT_INFO is disabled
[10:42:57 INF] Feature GTK_MODULES is disabled
[10:42:57 INF] Feature HOME is disabled
[10:42:57 INF] Feature IM_CONFIG_PHASE is disabled
[10:42:57 INF] Feature INVOCATION_ID is disabled
[10:42:57 INF] Feature JOURNAL_STREAM is disabled
[10:42:57 INF] Feature LANG is disabled
[10:42:57 INF] Feature LANGUAGE is disabled
[10:42:57 INF] Feature LC_ADDRESS is disabled
[10:42:57 INF] Feature LC_IDENTIFICATION is disabled
[10:42:57 INF] Feature LC_MEASUREMENT is disabled
[10:42:57 INF] Feature LC_MONETARY is disabled
[10:42:57 INF] Feature LC_NAME is disabled
[10:42:57 INF] Feature LC_NUMERIC is disabled
[10:42:57 INF] Feature LC_PAPER is disabled
[10:42:57 INF] Feature LC_TELEPHONE is disabled
[10:42:57 INF] Feature LC_TIME is disabled
[10:42:57 INF] Feature Logging is disabled
[10:42:57 INF] Feature LOGNAME is disabled
[10:42:57 INF] Feature MANAGERPID is disabled
[10:42:57 INF] Feature PAPERSIZE is disabled
[10:42:57 INF] Feature PATH is disabled
[10:42:57 INF] Feature PWD is disabled
[10:42:57 INF] Feature QT_ACCESSIBILITY is disabled
[10:42:57 INF] Feature QT_IM_MODULE is disabled
[10:42:57 INF] Feature ROOT is disabled
[10:42:57 INF] Feature Serilog is disabled
[10:42:57 INF] Feature SESSION_MANAGER is disabled
[10:42:57 INF] Feature SHELL is disabled
[10:42:57 INF] Feature SHLVL is disabled
[10:42:57 INF] Feature SNAP is disabled
[10:42:57 INF] Feature SNAP_ARCH is disabled
[10:42:57 INF] Feature SNAP_COMMON is disabled
[10:42:57 INF] Feature SNAP_CONTEXT is disabled
[10:42:57 INF] Feature SNAP_COOKIE is disabled
[10:42:57 INF] Feature SNAP_DATA is disabled
[10:42:57 INF] Feature SNAP_INSTANCE_KEY is disabled
[10:42:57 INF] Feature SNAP_INSTANCE_NAME is disabled
[10:42:57 INF] Feature SNAP_LIBRARY_PATH is disabled
[10:42:57 INF] Feature SNAP_NAME is disabled
[10:42:57 INF] Feature SNAP_REAL_HOME is disabled
[10:42:57 INF] Feature SNAP_REEXEC is disabled
[10:42:57 INF] Feature SNAP_REVISION is disabled
[10:42:57 INF] Feature SNAP_USER_COMMON is disabled
[10:42:57 INF] Feature SNAP_USER_DATA is disabled
[10:42:57 INF] Feature SNAP_VERSION is disabled
[10:42:57 INF] Feature SSH_AGENT_PID is disabled
[10:42:57 INF] Feature SSH_AUTH_SOCK is disabled
[10:42:57 INF] Feature TERM is disabled
[10:42:57 INF] Feature URLS is disabled
[10:42:57 INF] Feature USER is disabled
[10:42:57 INF] Feature USERNAME is disabled
[10:42:57 INF] Feature WINDOWPATH is disabled
[10:42:57 INF] Feature XAUTHORITY is disabled
[10:42:57 INF] Feature XDG_CONFIG_DIRS is disabled
[10:42:57 INF] Feature XDG_CURRENT_DESKTOP is disabled
[10:42:57 INF] Feature XDG_DATA_DIRS is disabled
[10:42:57 INF] Feature XDG_MENU_PREFIX is disabled
[10:42:57 INF] Feature XDG_RUNTIME_DIR is disabled
[10:42:57 INF] Feature XDG_SESSION_CLASS is disabled
[10:42:57 INF] Feature XDG_SESSION_DESKTOP is disabled
[10:42:57 INF] Feature XDG_SESSION_TYPE is disabled
[10:42:57 INF] Feature XMODIFIERS is disabled
[10:42:57 INF] Feature _ is disabled
[10:42:57 INF] Feature _NO_DEBUG_HEAP is disabled

I would expect that when the FeatureManagement section is empty in appsettings.json, then no features are returned from GetFeatureNamesAsync.

Or am I missing someting in the configuration?

Activity

  1. uwh-ronb commented on Jan 25, 2022

    @uwh-ronb

    I am seeing the same thing.

  2. jgn-epp commented on Jan 25, 2022

    @jgn-epp

    This seems to be by design
    #55 (comment)

  3. jimmyca15 commented on Jan 25, 2022

    @jimmyca15
    Member

    @devops-lucina Jeppe (@jgn-epp) Simon Auner (@simonauner)

    While this was by design for a certain use case, it seems to be doing more harm than good. We can't turn this off with a 2.x release because it's a breaking change, but we can consider removing this fallback behavior in 3.x.

    Meanwhile, would a flag on FeatureManagementOptions to disable this fallback behavior help?

  4. uwh-ronb commented on Jan 27, 2022

    @uwh-ronb

    I was using that to debug why the feature flags were not working. I was confirming seeing that same behavior.

    My bigger issue is around how it seems to be functioning, or not. If I setup FeatureManagement in appsettings.json and control it there, everything works as expected for that file.

    However, it is never overwritten by what is in the App Configuration Service FM section. If I take the section out of appsettings.json, I only get back the list above, and the feature never toggles on or off.

  5. zhiyuanliang-ms commented on Sep 14, 2023

    @zhiyuanliang-ms
    Member

    @devops-lucina Feature management is built on IConfiguration. You can add multiple sources for the IConfigurationBuilder.
    You've mentioned that

    However, it is never overwritten by what is in the App Configuration Service FM section.
    I am not very sure what you mean. If you call AddAzureAppConfiguration() after calling AddJsonFile(), the section iwith same name in the IConfiguration will be overwritten.

    IConfigurationBuilder builder = new ConfigurationBuilder();
    builder.AddJsonFile("appsettings.json");
    builder.AddAzureAppConfiguration(options =>
    {
        options.Connect(ConnectionString)
               .UseFeatureFlags(featureFlagOptions =>
               {
                   featureFlagOptions.Label = null;
               });
    });
    

    After the IConfigurationBuilder is built and we get a IConfiguration which will registered to the feature manager. Only if the IConfiguration has no FeatureManagement section, the ConfigurationFeatureDefinitionProvider will pull the whole IConfiguration.

    We will discard this bad design in the next release. A PR(#261) is progress to solve this.
    A standalone PR to solve this in release 2.x has also been created, which will provide an additional flag in FeatureManagementOption to change the FeatureDefinitionProvider when there is no FeatureManagement section in the configuration.

  6. jimmyca15 commented on Oct 30, 2023

    @jimmyca15
    Member

    Fixed in 3.0

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

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions