l.s.f.f.FeatureController : class documentation

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
def __init__(self, scope_check_callback, rule_source=None):
Construct a new view of the features for a set of scopes.
Parametersscope_check_callbackGiven a scope name, says whether it's active or not.
rule_sourceInstance of StormFeatureRuleSource or similar.
def getFlag(self, flag):
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.
def _checkFlag(self, flag):
Undocumented
def _currentValueAndScope(self, flag):
Undocumented
def _debugMessage(self, message):
Undocumented
def currentScope(self, flag):
The name of the scope of the matching rule with the highest priority.
def _findCurrentScope(self, flag):
Lookup method for self._current_scopes. See also currentScope().
def isInScope(self, scope):
Undocumented
def __getitem__(self, flag_name):
FeatureController can be indexed.

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.

def getAllFlags(self):
Return a dict of all active flags.

This may be expensive because of evaluating many scopes, so it shouldn't normally be used by code that only wants to know about one or a few flags.

def _needRules(self):
Undocumented
def usedFlags(self):
Return dict of flags used in this controller so far.
def usedScopes(self):
Return {scope: active} for scopes that have been used so far.
def defaultFlagValue(self, flag):
Return the flag's value in the default scope.
API Documentation for Launchpad, generated by pydoctor at 2020-06-07 00:00:04.