Skip to content

Commit

Permalink
kettle: add logging to monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
spiffxp committed Oct 31, 2022
1 parent 89cd414 commit 5bdd8ee
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions kettle/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@


def collect(tables, stale_hours):
lines = []
stale = False
for table_spec in tables:
print(f'checking {table_spec}...')
print(f'Checking {table_spec}...')
project, dataset_name = table_spec.split(':')
dataset, name = dataset_name.split('.')

Expand All @@ -49,19 +48,21 @@ def collect(tables, stale_hours):
# converting datetimes back into epoch-milliseconds is tiresome
# pylint: disable=protected-access
fields = {
'table_spec': table_spec,
'size_bytes': table.num_bytes,
'modified_time': int(table._properties.get('lastModifiedTime')),
'row_count': table.num_rows
}

hours_old = (time.time() - fields['modified_time'] / 1000) / (3600.0)
fields['hours_old'] = hours_old

if stale_hours and hours_old > stale_hours:
print('ERROR: table %s is %.1f hours old. Max allowed: %s hours.' % (
table.table_id, hours_old, stale_hours))
stale = True
print(json.dumps(fields))

print('Collected data:')
print(''.join(lines))
print(f'Finished checking tables')

return int(stale)

Expand Down

0 comments on commit 5bdd8ee

Please sign in to comment.