canonical / hotsos

Software analysis toolkit. Define checks in high-level language and leverage library to perform analysis of common Cloud applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add property aliasing to Python properties

xmkg opened this issue · comments

Currently, property names are long because they must be the full import path to the property, e.g.:

@hotsos.core.plugins.kernel.memory.MemInfo.mem_avail_to_mem_total_percentage

The given example property is implemented in the MemInfo class as follows:

hotsos/core/plugins/kernel/memory/MemInfo.py:

class MemInfo(_BaseProcKeyValue):
    # /* .... */
    @property
    def mem_avail_to_mem_total_percentage(self):
        return round((self.MemAvailable * 100) / self.MemTotal)

We could allow aliasing such properties to a shorter, more comprehensible name with a decorator, e.g.:

hotsos/core/plugins/kernel/memory/MemInfo.py:

class MemInfo(_BaseProcKeyValue):
    # /* .... */
    @property
    @alias('kernel.mem.avail_to_total_pct')
    def mem_avail_to_mem_total_percentage(self):
        return round((self.MemAvailable * 100) / self.MemTotal)

... so we can refer to it in YAML files like:

@kernel.mem.avail_to_total_pct