Skip to content

Commit

Permalink
add ConstantRouter
Browse files Browse the repository at this point in the history
  • Loading branch information
bucko909 committed Aug 29, 2024
1 parent 52b40b2 commit 758a5bb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions lib/carbon/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,29 @@ def getDestinations(self, key):
raise NotImplementedError()


class ConstantRouter(DatapointRouter):
plugin_name = 'constant'

def __init__(self, settings):
self.destinations = set()

def addDestination(self, destination):
self.destinations.add(destination)

def removeDestination(self, destination):
self.destinations.discard(destination)

def hasDestination(self, destination):
return destination in self.destinations

def countDestinations(self):
return len(self.destinations)

def getDestinations(self, key):
for destination in self.destinations:
yield destination


class RelayRulesRouter(DatapointRouter):
plugin_name = 'rules'

Expand Down
2 changes: 1 addition & 1 deletion lib/carbon/tests/test_routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ def testBasic(self):
router.addDestination(parseDestination(destination))
self.assertEqual(
len(list(router.getDestinations('foo.bar'))),
settings['REPLICATION_FACTOR']
len(DESTINATIONS) if plugin == 'constant' else settings['REPLICATION_FACTOR']
)

0 comments on commit 758a5bb

Please sign in to comment.