Skip to content

Commit

Permalink
rename a few things
Browse files Browse the repository at this point in the history
  • Loading branch information
krav committed Apr 19, 2022
1 parent 41467d3 commit 995d2bf
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 31 deletions.
14 changes: 7 additions & 7 deletions baseplate/clients/memcache/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,31 +133,31 @@ class MemcacheContextFactory(ContextFactory):
PROM_PREFIX = "bp_memcached_pool"
PROM_LABELS = ["pool"]

promTotalConnections = Gauge(
prom_total_connections = Gauge(
f"{PROM_PREFIX}_size",
"Maximum size of this pool",
PROM_LABELS,
)

promUsedConnections = Gauge(
prom_used_connections = Gauge(
f"{PROM_PREFIX}_in_use",
"Number of connections in this pool currently in use",
PROM_LABELS,
)

promFreeConnections = Gauge(
prom_free_connections = Gauge(
f"{PROM_PREFIX}_free",
"Number of free connections in this pool",
PROM_LABELS,
)

def __init__(self, pooled_client: PooledClient, name: str = "memcache"):
def __init__(self, pooled_client: PooledClient, name: str = "default"):
self.pooled_client = pooled_client

pool = self.pooled_client.client_pool
self.promTotalConnections.labels(name).set_function(lambda: pool.max_size)
self.promFreeConnections.labels(name).set_function(lambda: len(pool.free))
self.promUsedConnections.labels(name).set_function(lambda: len(pool.used))
self.prom_total_connections.labels(name).set_function(lambda: pool.max_size)
self.prom_free_connections.labels(name).set_function(lambda: len(pool.free))
self.prom_used_connections.labels(name).set_function(lambda: len(pool.used))

def report_memcache_runtime_metrics(self, batch: metrics.Client) -> None:
pool = self.pooled_client.client_pool
Expand Down
18 changes: 10 additions & 8 deletions baseplate/clients/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,18 @@ class RedisContextFactory(ContextFactory):
PROM_PREFIX = "bp_redis_pool"
PROM_LABELS = ["pool"]

totalConnections = Gauge(
total_connections = Gauge(
f"{PROM_PREFIX}_connections",
"Number of connections in this redisbp pool",
PROM_LABELS,
)
idleConnections = Gauge(
f"{PROM_PREFIX}_idle_connections",
idle_connections = Gauge(
f"{PROM_PREFIX}_connections_idle",
"Number of idle connections in this redisbp pool",
PROM_LABELS,
)
openConnections = Gauge(
f"{PROM_PREFIX}_open_connections",
open_connections = Gauge(
f"{PROM_PREFIX}_connections_open",
"Number of open connections in this redisbp pool",
PROM_LABELS,
)
Expand All @@ -117,9 +117,11 @@ def __init__(self, connection_pool: redis.ConnectionPool, name: str = "redis"):
self.connection_pool = connection_pool

if isinstance(connection_pool, redis.BlockingConnectionPool):
self.totalConnections.labels(name).set_function(lambda: connection_pool.max_connections)
self.idleConnections.labels(name).set_function(connection_pool.pool.qsize)
self.openConnections.labels(name).set_function(
self.total_connections.labels(name).set_function(
lambda: connection_pool.max_connections
)
self.idle_connections.labels(name).set_function(connection_pool.pool.qsize)
self.open_connections.labels(name).set_function(
lambda: len(connection_pool._connections) # type: ignore
)

Expand Down
22 changes: 11 additions & 11 deletions baseplate/clients/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,25 @@ class SQLAlchemyEngineContextFactory(ContextFactory):
PROM_PREFIX = "bp_sqlalchemy_pool"
PROM_LABELS = ["pool"]

promTotalConnections = Gauge(
f"{PROM_PREFIX}_size",
prom_total_connections = Gauge(
f"{PROM_PREFIX}_connections",
"Total number of connections in this pool",
PROM_LABELS,
)

promCheckedInConnections = Gauge(
f"{PROM_PREFIX}_checked_in",
prom_checked_in_connections = Gauge(
f"{PROM_PREFIX}_idle",
"Number of available, checked in, connections in this pool",
PROM_LABELS,
)

promCheckedOutConnections = Gauge(
f"{PROM_PREFIX}_checked_out",
prom_checked_out_connections = Gauge(
f"{PROM_PREFIX}_active",
"Number of connections in use, or checked out, in this pool",
PROM_LABELS,
)

promOverflowConnections = Gauge(
prom_overflow_connections = Gauge(
f"{PROM_PREFIX}_overflow_connections",
"Number of connections over the desired size of this pool",
PROM_LABELS,
Expand All @@ -191,10 +191,10 @@ def __init__(self, engine: Engine, name: str = "sqlalchemy"):

pool = self.engine.pool
if isinstance(pool, QueuePool):
self.promTotalConnections.labels(name).set_function(pool.size)
self.promCheckedInConnections.labels(name).set_function(pool.checkedin)
self.promCheckedOutConnections.labels(name).set_function(pool.checkedout)
self.promOverflowConnections.labels(name).set_function(pool.overflow)
self.prom_total_connections.labels(name).set_function(pool.size)
self.prom_checked_in_connections.labels(name).set_function(pool.checkedin)
self.prom_checked_out_connections.labels(name).set_function(pool.checkedout)
self.prom_overflow_connections.labels(name).set_function(pool.overflow)

def report_runtime_metrics(self, batch: metrics.Client) -> None:
pool = self.engine.pool
Expand Down
8 changes: 4 additions & 4 deletions baseplate/clients/thrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ class ThriftContextFactory(ContextFactory):
PROM_PREFIX = "bp_thrift_pool"
PROM_LABELS = ["client_cls"]

promTotalConnections = Gauge(
prom_total_connections = Gauge(
f"{PROM_PREFIX}_size",
"Number of connections in this thrift pool",
PROM_LABELS,
)

promUsedConnections = Gauge(
prom_used_connections = Gauge(
f"{PROM_PREFIX}_in_use",
"Number of connections currently in use in this thrift pool",
PROM_LABELS,
Expand All @@ -99,8 +99,8 @@ def __init__(self, pool: ThriftConnectionPool, client_cls: Any):
)

pool_name = type(self.client_cls).__name__
self.promTotalConnections.labels(pool_name).set_function(lambda: self.pool.size)
self.promUsedConnections.labels(pool_name).set_function(lambda: self.pool.checkedout)
self.prom_total_connections.labels(pool_name).set_function(lambda: self.pool.size)
self.prom_used_connections.labels(pool_name).set_function(lambda: self.pool.checkedout)

def report_runtime_metrics(self, batch: metrics.Client) -> None:
batch.gauge("pool.size").replace(self.pool.size)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/clients/redis_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_metrics(self):
{"redis.url": "redis://localhost:1234/0", "redis.max_connections": max_connections}
)
)
metric = ctx.totalConnections.collect()
metric = ctx.total_connections.collect()
self.assertEqual(metric[0].samples[0].value, float(max_connections))

def test_timeouts(self):
Expand Down

0 comments on commit 995d2bf

Please sign in to comment.