netbox-plugin-prometheus-sd icon indicating copy to clipboard operation
netbox-plugin-prometheus-sd copied to clipboard

Proposal: Support tenant filtering in services

Open jkrcma opened this issue 2 years ago • 1 comments

Describe your changes

As I am building a full Prometheus service discovery based on Netbox's services, I stumbled upon an issue to be able to filter services by tenant. Netbox on its own doesn't support the tenant field in the views or filters of services, unlike for all other objects the SD plugin is available for, so I coded the support from scratch using a custom filterset.

Unfortunately tenancy in Netbox is very inconsistently assigned to objects with any sort of relation to the devices or VMs, such as clusters, cluster groups, sites, racks etc, so I decided to stay within the "one-FK away" distance from the service. When I was considering to go further (for example clusters) I wasn't able to come up with any consistent solution, which would also consider other objects, like IP addresses. IP addresses on the other hand are implemented entirely differently on the ORM side than services.

This change represents the minimal amount of work which makes the tenant filtering working for services, by introducing two filtering GET parameters tenant=<slug> and tenant_id=<id>. Not sure you will like this change, but we need it to be able to split discovered services to Prometheus instances owned by various teams without duplicating the tenancy structure through Netbox tags.

Issue ticket number and link

None.

Checklist before requesting a review

  • [x] I have performed a self-review of my code
  • [x] If it is a core feature, I have added thorough tests.

jkrcma avatar Apr 22 '24 16:04 jkrcma

Thanks for your contribution! Looks good to me after a quick scan. Give me some time to check it out again, but I think we'll get it upstream quickly.

FlxPeters avatar Apr 22 '24 18:04 FlxPeters