Skip to content

Acceptable solution for tenant names #69

@na50r

Description

I noticed that there are many metrics where the tenant name were still missing. It is possible to import keystonedb and get the tenant name by tenant id but making a query each time for this seems inefficient. I tried out two solutions and both work.

Main solutions: Create a hash map of tenant id to tenant name once and then re-use it.

Solution 1: Wrapper around the Registry
Before placing the registry in promhttp.HandlerFor, use a wrapper to iterate over all labels and if tenant id is present, add a tenant name label. This works but may be an overkill. It creates metrics that were never present in Niedbalski exporter. Too many labels will not break a monitoring setup but feels excessive. Code changes are limited since we only touch one or two files (main.go and collector.go for example)

Solution 2: Global accessible hash map
You can use the util package or create special package where a hash map is initialized. Initialize the hash map right before starting the listener, so it is run only once. The collectors can then access that variable by importing the package, util.TenantMap and you can set the tenant name everywhere you like. This requires code changes at multiple places, namely everywhere were Niedbalski and co. decided to add tenant names but feels like the appropriate solution. This idea can be also used for other metrics where we require data involving multiple dbs. I prefer this solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions