Skip to content
This repository has been archived by the owner on Aug 25, 2023. It is now read-only.

Commit

Permalink
YACHT-964: SLITableExistsFilter no longer ignores 403 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-kolda committed Aug 30, 2018
1 parent 28e2976 commit e6fd4fa
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions src/slo/x_days_sli/sli_table_exists_filter.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,29 @@
import logging

from apiclient.errors import HttpError


class SLITableExistsFilter(object):

def __init__(self, big_query):
self.big_query = big_query

def exists(self, table_reference):
try:
table = self.big_query.get_table(
project_id=table_reference.project_id,
dataset_id=table_reference.dataset_id,
table_id=table_reference.table_id)

if not table:
logging.info("Table doesn't exist anymore: %s", table_reference)
return False
table = self.big_query.get_table(
project_id=table_reference.project_id,
dataset_id=table_reference.dataset_id,
table_id=table_reference.table_id)

if not table_reference.is_partition():
return True
if not table:
logging.info("Table doesn't exist anymore: %s", table_reference)
return False

if self.__is_partition_exists(table_reference):
return True
if not table_reference.is_partition():
return True

logging.info("Partition doesn't exist anymore: %s", table_reference)
return False
if self.__is_partition_exists(table_reference):
return True

except HttpError as ex:
if ex.resp.status == 403:
logging.warning("Application has no access to '%s'",
table_reference)
return False
raise ex
logging.info("Partition doesn't exist anymore: %s", table_reference)
return False

def __is_partition_exists(self, table_reference):
partitions = self.big_query.list_table_partitions(
Expand Down

0 comments on commit e6fd4fa

Please sign in to comment.