Skip to content

Commit 90129ef

Browse files
authored
Accomodate back-end change making 'Sink.filter' optional. (googleapis#4699)
Closes googleapis#4696.
1 parent d16f5c1 commit 90129ef

2 files changed

Lines changed: 8 additions & 16 deletions

File tree

logging/google/cloud/logging/sink.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ class Sink(object):
2727
:param name: the name of the sink
2828
2929
:type filter_: str
30-
:param filter_: the advanced logs filter expression defining the entries
31-
exported by the sink. If not passed, the instance should
32-
already exist, to be refreshed via :meth:`reload`.
30+
:param filter_: (optional) the advanced logs filter expression defining
31+
the entries exported by the sink.
3332
3433
:type destination: str
3534
:param destination: destination URI for the entries exported by the sink.
@@ -91,8 +90,8 @@ def from_api_repr(cls, resource, client):
9190
from the client.
9291
"""
9392
sink_name = resource['name']
94-
filter_ = resource['filter']
9593
destination = resource['destination']
94+
filter_ = resource.get('filter')
9695
return cls(sink_name, filter_, destination, client=client)
9796

9897
def _require_client(self, client):
@@ -163,8 +162,8 @@ def reload(self, client=None):
163162
"""
164163
client = self._require_client(client)
165164
data = client.sinks_api.sink_get(self.project, self.name)
166-
self.filter_ = data['filter']
167165
self.destination = data['destination']
166+
self.filter_ = data.get('filter')
168167

169168
def update(self, client=None):
170169
"""API call: update sink configuration via a PUT request

logging/tests/unit/test_sink.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,12 @@ def test_from_api_repr_minimal(self):
6262
FULL = 'projects/%s/sinks/%s' % (self.PROJECT, self.SINK_NAME)
6363
RESOURCE = {
6464
'name': self.SINK_NAME,
65-
'filter': self.FILTER,
6665
'destination': self.DESTINATION_URI,
6766
}
6867
klass = self._get_target_class()
6968
sink = klass.from_api_repr(RESOURCE, client=client)
7069
self.assertEqual(sink.name, self.SINK_NAME)
71-
self.assertEqual(sink.filter_, self.FILTER)
70+
self.assertIsNone(sink.filter_)
7271
self.assertEqual(sink.destination, self.DESTINATION_URI)
7372
self.assertIs(sink._client, client)
7473
self.assertEqual(sink.project, self.PROJECT)
@@ -164,24 +163,20 @@ def test_exists_hit_w_alternate_client(self):
164163
(self.PROJECT, self.SINK_NAME))
165164

166165
def test_reload_w_bound_client(self):
167-
NEW_FILTER = 'logName:syslog AND severity>=INFO'
168166
NEW_DESTINATION_URI = 'faux.googleapis.com/other'
169167
RESOURCE = {
170168
'name': self.SINK_NAME,
171-
'filter': NEW_FILTER,
172169
'destination': NEW_DESTINATION_URI,
173170
}
174171
client = _Client(project=self.PROJECT)
175172
api = client.sinks_api = _DummySinksAPI()
176173
api._sink_get_response = RESOURCE
177-
sink = self._make_one(self.SINK_NAME, self.FILTER,
178-
self.DESTINATION_URI,
179-
client=client)
174+
sink = self._make_one(self.SINK_NAME, client=client)
180175

181176
sink.reload()
182177

183-
self.assertEqual(sink.filter_, NEW_FILTER)
184178
self.assertEqual(sink.destination, NEW_DESTINATION_URI)
179+
self.assertIsNone(sink.filter_)
185180
self.assertEqual(api._sink_get_called_with,
186181
(self.PROJECT, self.SINK_NAME))
187182

@@ -197,9 +192,7 @@ def test_reload_w_alternate_client(self):
197192
client2 = _Client(project=self.PROJECT)
198193
api = client2.sinks_api = _DummySinksAPI()
199194
api._sink_get_response = RESOURCE
200-
sink = self._make_one(self.SINK_NAME, self.FILTER,
201-
self.DESTINATION_URI,
202-
client=client1)
195+
sink = self._make_one(self.SINK_NAME, client=client1)
203196

204197
sink.reload(client=client2)
205198

0 commit comments

Comments
 (0)