Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't emit a Prometheus error for empty tables #80

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions partitionmanager/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ def do_partition(conf):
except partitionmanager.types.DatabaseCommandException as e:
log.warning("Failed to automatically handle %s: %s", table, e)
metrics.add("alter_errors", table.name, 1)
except partitionmanager.types.TableEmptyException:
log.warning("Table %s appears to be empty. Skipping.", table)
except (ValueError, Exception) as e:
log.warning("Failed to handle %s: %s", table, e)
metrics.add("alter_errors", table.name, 1)
Expand Down
11 changes: 11 additions & 0 deletions partitionmanager/database_helpers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
SqlInput,
SqlQuery,
Table,
TableEmptyException,
)


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

def test_empty_table(self):
db = MockDatabase()
db.add_response("SELECT id FROM `burgers` ORDER BY", [])

table = Table("burgers")
data = {"range_cols": ["id"]}

with self.assertRaises(TableEmptyException):
get_position_of_table(db, table, data)

def test_exact_timestamp_no_query(self):
db = MockDatabase()
db.add_response("SELECT id FROM `burgers` ORDER BY", [{"id": 42}])
Expand Down
2 changes: 1 addition & 1 deletion partitionmanager/table_append_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_current_positions(database, table, columns):
f"Expected one result from {table.name}"
)
if not rows:
raise partitionmanager.types.TableInformationException(
raise partitionmanager.types.TableEmptyException(
f"Table {table.name} appears to be empty. (No results)"
)
positions[column] = rows[0][column]
Expand Down
4 changes: 4 additions & 0 deletions partitionmanager/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,10 @@ class TableInformationException(Exception):
"""Raised when the table's status doesn't include the information we need."""


class TableEmptyException(Exception):
"""Raised when the table is empty."""


class NoEmptyPartitionsAvailableException(Exception):
"""Raised if no empty partitions are available to safely modify."""

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ max-complexity = 16 # default is 10
[tool.ruff.lint.pylint]
max-args = 7 # default is 5
max-branches = 15 # default is 12
max-statements = 52 # default is 50
max-statements = 54 # default is 50