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

Commit

Permalink
NON-JIRA: problem_with_filtering_one_table_should_not_spoil_the_whole…
Browse files Browse the repository at this point in the history
…_SLI_processing
  • Loading branch information
jarekdrabek committed Sep 13, 2018
1 parent 421b76f commit 5a85d7f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/slo/x_days_sli/x_days_sli_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,22 @@ def recalculate_sli(self):

all_tables = self.querier.query(self.x_days)
filtered_tables = [table for table in all_tables
if self.__exists(table)]
if self.__should_stay_as_SLI_violation(table)]

logging.info("%s days SLI tables filtered from %s to %s", self.x_days,
len(all_tables), len(filtered_tables))
self.streamer.stream(filtered_tables)

def __exists(self, table):
return self.filter.exists(self.__create_table_reference(table))
# def __should_stay_as_SLI_violation(self, table):
# return self.filter.exists(self.__create_table_reference(table))

def __should_stay_as_SLI_violation(self, table):
try:
exist = self.filter.exists(self.__create_table_reference(table))
except:
logging.error("An error occured while filtering table %s", table)
return True
return exist

@staticmethod
def __create_table_reference(table):
Expand Down
20 changes: 20 additions & 0 deletions tests/slo/x_days_sli/test_x_days_sli_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import unittest

from mock import patch

from src.slo.x_days_sli.sli_results_streamer import SLIResultsStreamer
from src.slo.x_days_sli.sli_table_exists_filter import SLITableExistsFilter
from src.slo.x_days_sli.sli_view_querier import SLIViewQuerier
from src.slo.x_days_sli.x_days_sli_service import XDaysSLIService


class TestXDaysSLIService(unittest.TestCase):

@patch.object(SLIViewQuerier, 'query', return_value=[
{"projectId":"p1", "datasetId":"d1", "tableId":"t1", "partitionId":"part1"}
])
@patch.object(SLITableExistsFilter, 'exists', side_effect=Exception("An error"))
@patch.object(SLIResultsStreamer, 'stream')
def test_table_that_caused_exception_should_not_be_filtered_out(self, stream, _, query):
XDaysSLIService(3).recalculate_sli()
stream.assert_called_with([{"projectId":"p1", "datasetId":"d1", "tableId":"t1", "partitionId":"part1"}])

0 comments on commit 5a85d7f

Please sign in to comment.