Part of lp.services.features.flags View In Hierarchy
Known subclasses: lp.services.features.flags.NullFeatureController
A FeatureController tells application code what features are active. It does this by meshing together two sources of data: - feature flags, typically set by an administrator into the database - feature scopes, which would typically be looked up based on attributes of the current web request, or the user for whom a job is being run, or something similar. FeatureController presents a high level interface for application code to query flag values, without it needing to know that they are stored in the database. At this level flag names and scope names are presented as strings for easier use in Python code, though the values remain unicode. They should always be ascii like Python identifiers. One instance of FeatureController should be constructed for the lifetime of code that has consistent configuration values. For instance there will be one per web app request. Intended performance: when this object is first asked about a flag, it will read the whole feature flag table from the database. It is expected to be reasonably small. The scopes may be expensive to compute (eg checking team membership) so they are checked at most once when they are first needed. The controller is then supposed to be held in a thread-local and reused for the duration of the request. @see: U{https://dev.launchpad.net/LEP/FeatureFlags}
Method | __init__ | Construct a new view of the features for a set of scopes. |
Method | getFlag | Get the value of a specific flag. |
Method | currentScope | The name of the scope of the matching rule with the highest |
Method | isInScope | Undocumented |
Method | __getitem__ | FeatureController can be indexed. |
Method | getAllFlags | Return a dict of all active flags. |
Method | usedFlags | Return dict of flags used in this controller so far. |
Method | usedScopes | Return {scope: active} for scopes that have been used so far. |
Method | defaultFlagValue | Return the flag's value in the default scope. |
Method | _checkFlag | Undocumented |
Method | _currentValueAndScope | Undocumented |
Method | _debugMessage | Undocumented |
Method | _findCurrentScope | Lookup method for self._current_scopes. See also currentScope() . |
Method | _needRules | Undocumented |
Parameters | scope_check_callback | Given a scope name, says whether it's active or not. |
rule_source | Instance of StormFeatureRuleSource or similar. |
Get the value of a specific flag. :param flag: A name to lookup. e.g. 'recipes.enabled' :return: The value of the flag determined by the highest priority rule that matched.
This is to support easy zope traversal through eg "request/features/a.b.c". We don't support other collection protocols.
Note that calling this the first time for any key may cause arbitrarily large amounts of work to be done to determine if the controller is in any scopes relevant to this flag.