mozilla

Config API

Helpers to handle HekaClient configuration details.

heka.config._convert(value)[source]

Converts a config value. Numeric integer strings are converted to integer values. ‘True-ish’ string values are converted to boolean True, ‘False-ish’ to boolean False. Any alphanumeric (plus underscore) value enclosed within ${dollar_sign_curly_braces} is assumed to represent an environment variable, and will be converted to the corresponding value provided by os.environ.

heka.config.client_from_dict_config(config, client=None)[source]

Configure a heka client, fully configured w/ stream and plugins.

Parameters:
  • config – Configuration dictionary.
  • client – HekaClient instance to configure. If None, one will be created.

The configuration dict supports the following values:

logger
Heka client default logger value.
severity
Heka client default severity value.
disabled_timers
Sequence of string tokens identifying timers that are to be deactivated.
filters
Sequence of 2-tuples (filter_provider, config). Each filter_provider is a dotted name referring to a function which, when called and passed the associated config dict as kwargs, will return a usable HekaClient filter function.
plugins
Nested dictionary containing plugin configuration. Keys are the plugin names (i.e. the name the method will be given when attached to the client). Values are 2-tuples (plugin_provider, config). Each plugin_provider is a dotted name referring to a function which, when called and passed the associated config, will return the usable plugin method.
stream
Nested dictionary containing stream configuration.

All of the configuration values are optional, but failure to include a stream may result in a non-functional Heka client. Any unrecognized keys will be ignored.

Note that any top level config values starting with stream_ will be added to the stream config dictionary, overwriting any values that may already be set.

The stream configuration supports the following values:

class (required)
Dotted name identifying the stream class to instantiate.
args
Sequence of non-keyword args to pass to stream constructor.
<kwargs>
All remaining key-value pairs in the stream config dict will be passed as keyword arguments to the stream constructor.
heka.config.client_from_stream_config(stream, section, client=None)[source]

Extract configuration data in INI format from a stream object (e.g. a file object) and use it to generate a Heka client. Config values will be sent through the _convert function for possible type conversion.

Parameters:
  • stream – Stream object containing config information.
  • section – INI file section containing the configuration we care about.
  • client – HekaClient instance to configure. If None, one will be created.

Note that all stream config options should be prefaced by “stream_”, e.g. “stream_class” should specify the dotted name of the stream class to use. Similarly all extension method settings should be prefaced by “extensions_”.

heka.config.client_from_text_config(text, section, client=None)[source]

Extract configuration data in INI format from provided text and use it to configure a Heka client. Text is converted to a stream and passed on to client_from_stream_config.

Parameters:
  • text – INI text containing config information.
  • section – INI file section containing the configuration we care about.
  • client – HekaClient instance to configure. If None, one will be created.
heka.config.dict_from_stream_config(stream, section)[source]

Parses configuration from a stream and converts it to a dictionary suitable for passing to client_from_dict_config.

Parameters:
  • stream – Stream object containing config information.
  • section – INI file section containing the configuration we care about.
heka.config.nest_prefixes(config_dict, prefixes=None, separator='_')[source]

Iterates through the config_dict keys, looking for any starting w/ one of a specific set of prefixes, moving those into a single nested dictionary keyed by the prefix value.

Parameters:
  • config_dict – Dictionary to mutate. Will also be returned.
  • prefixes – Sequence of prefixes to look for in config_dict keys.
  • separator – String which separates prefix values from the rest of the key.