klio.metrics.base

Base classes from which a metrics consumer (i.e. ffwd, logger, etc.) will need to implement.

New consumers are required to implement the AbstractRelayClient, and three metrics objects based off of BaseMetric: a counter, a gauge, and a timer.

klio.metrics.base.abstract_attr(obj=None)

Set an attribute or a property as abstract.

Supports class-level attributes as well as methods defined as a @property.

Usage:

class Foo(object):
    my_foo_attribute = abstract_attr()

    @property
    @abstract_attr
    def my_foo_property(self):
        pass
Parameters

obj (callable) – Python object to “decorate”, i.e. a class method. If none is provided, a dummy object is created in order to attach the __isabstractattr__ attribute (similar to __isabstractmethod__ from abc.abstractmethod).

Returns object with __isabstractattr__ attribute set to True.

class klio.metrics.base.AbstractRelayClient(klio_config)

Abstract base class for all metric consumer relay clients.

Each new consumer (i.e. ffwd, logging-based metrics) will need to implement this relay class.

RELAY_CLIENT_NAME

must match the key in klio-job.yaml under job_config.metrics.

Type

str

abstract unmarshal(metric)

Returns a dictionary-representation of the metric object

abstract emit(metric)

Emit the given metric object to the particular consumer.

emit will be run in a threadpool separate from the transform, and any errors raised from the method will be logged then ignored.

abstract counter(name, value=0, transform=None, **kwargs)

Return a newly instantiated counter-type metric specific for the particular consumer.

Callers to the counter method will store new counter objects returned in memory for simple caching.

abstract gauge(name, value=0, transform=None, **kwargs)

Return a newly instantiated gauge-type metric specific for the particular consumer.

Callers to the gauge method will store new gauge objects returned in memory for simple caching.

abstract timer(name, transform=None, **kwargs)

Return a newly instantiated timer-type metric specific for the particular consumer.

Callers to the timer method will store new timer objects returned in memory for simple caching.

class klio.metrics.base.BaseMetric(name, value=0, transform=None, **kwargs)

Base class for all metric types.

A consumer must implement a counter metric, a gauge metric, and a timer metric.