canonical / hotsos

Software analysis toolkit. Define checks in high-level language and leverage library to perform analysis of common Cloud applications.
Apache License 2.0
30 stars 37 forks source link

Add property aliasing to Python properties #912

Open mustafakemalgilor opened 1 week ago

mustafakemalgilor commented 1 week ago

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