weaveworks / grafanalib

Python library for building Grafana dashboards
Apache License 2.0
1.86k stars 309 forks source link

Support for tenant, fields, and shouldComputeMulti Fields in OpenTSDBTarget #672

Open guanyuding opened 1 month ago

guanyuding commented 1 month ago

What you expected to happen?

The library should be able to support tenant, fields, and shouldComputeMulti parameters.

What happened?

I have made some local modifications to the code to better handle multi-value metrics and support different tenants. The changes include:

tenant: Added a tenant attribute to the OpenTSDBTarget class to support multi-tenancy. This allows specifying different tenants for various metrics.

shouldComputeMulti: Introduced a shouldComputeMulti attribute to indicate whether multi-computation should be performed based on the metrics.

fields: Added a fields attribute to manage multiple fields dynamically within the OpenTSDBTarget class.

class OpenTSDBTarget(object):
    ...
    tenant = attr.ib(default="default")
    shouldComputeMulti = attr.ib(default=False, validator=instance_of(bool))
    fields = attr.ib(default=attr.Factory(list))
    def to_json_data(self):
        return {
            'tenant':self.tenant,
            'shouldComputeMulti':self.shouldComputeMulti,
            'fields':self.fields,
        }

Do you plan to support these fields (tenant, shouldComputeMulti, fields), or is there an alternative approach to achieve this requirement? thank you so much.

How to reproduce it?