Skip to content

Commit c39ba74

Browse files
committed
Don't emit a Prometheus error for empty tables
Fixes #79 Causes #81
1 parent f03e3c1 commit c39ba74

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

partitionmanager/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ def do_partition(conf):
360360
except partitionmanager.types.DatabaseCommandException as e:
361361
log.warning("Failed to automatically handle %s: %s", table, e)
362362
metrics.add("alter_errors", table.name, 1)
363+
except partitionmanager.types.TableEmptyException:
364+
log.warning("Table %s appears to be empty. Skipping.", table)
363365
except (ValueError, Exception) as e:
364366
log.warning("Failed to handle %s: %s", table, e)
365367
metrics.add("alter_errors", table.name, 1)

partitionmanager/database_helpers_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
SqlInput,
1010
SqlQuery,
1111
Table,
12+
TableEmptyException,
1213
)
1314

1415

@@ -46,6 +47,16 @@ def test_position_of_table(self):
4647
pos = get_position_of_table(db, table, data)
4748
self.assertEqual(pos.as_list(), [90210])
4849

50+
def test_empty_table(self):
51+
db = MockDatabase()
52+
db.add_response("SELECT id FROM `burgers` ORDER BY", [])
53+
54+
table = Table("burgers")
55+
data = {"range_cols": ["id"]}
56+
57+
with self.assertRaises(TableEmptyException):
58+
get_position_of_table(db, table, data)
59+
4960
def test_exact_timestamp_no_query(self):
5061
db = MockDatabase()
5162
db.add_response("SELECT id FROM `burgers` ORDER BY", [{"id": 42}])

partitionmanager/table_append_partition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def get_current_positions(database, table, columns):
6161
f"Expected one result from {table.name}"
6262
)
6363
if not rows:
64-
raise partitionmanager.types.TableInformationException(
64+
raise partitionmanager.types.TableEmptyException(
6565
f"Table {table.name} appears to be empty. (No results)"
6666
)
6767
positions[column] = rows[0][column]

partitionmanager/types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,10 @@ class TableInformationException(Exception):
596596
"""Raised when the table's status doesn't include the information we need."""
597597

598598

599+
class TableEmptyException(Exception):
600+
"""Raised when the table is empty."""
601+
602+
599603
class NoEmptyPartitionsAvailableException(Exception):
600604
"""Raised if no empty partitions are available to safely modify."""
601605

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,4 @@ max-complexity = 16 # default is 10
116116
[tool.ruff.lint.pylint]
117117
max-args = 7 # default is 5
118118
max-branches = 15 # default is 12
119-
max-statements = 52 # default is 50
119+
max-statements = 54 # default is 50

0 commit comments

Comments
 (0)