Skip to content
This repository was archived by the owner on Jan 26, 2025. It is now read-only.

Commit 8d23d21

Browse files
authored
Merge pull request #7 from insight-platform/fix-optional-config
Do not start watching optional sections
2 parents 63f9293 + 50abe7a commit 8d23d21

File tree

2 files changed

+86
-6
lines changed

2 files changed

+86
-6
lines changed

src/pipeline_watchdog/run.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,20 @@ async def watch_ingress(docker_client: DockerClient, buffer: str, config: FlowCo
148148

149149

150150
async def watch_buffer(docker_client: DockerClient, config: WatchConfig):
151-
logger.info('Watching buffer metrics %s', config.buffer)
152-
await asyncio.gather(
153-
watch_queue(docker_client, config.buffer, config.queue),
154-
watch_egress(docker_client, config.buffer, config.egress),
155-
watch_ingress(docker_client, config.buffer, config.ingress),
156-
)
151+
logger.info('Watching buffer [%s] metrics', config.buffer)
152+
watches = []
153+
154+
if config.queue:
155+
logger.info('Watching queue: %s', config.queue)
156+
watches.append(watch_queue(docker_client, config.buffer, config.queue))
157+
if config.egress:
158+
logger.info('Watching egress flow: %s', config.egress)
159+
watches.append(watch_egress(docker_client, config.buffer, config.egress))
160+
if config.ingress:
161+
logger.info('Watching ingress flow: %s', config.ingress)
162+
watches.append(watch_ingress(docker_client, config.buffer, config.ingress))
163+
164+
await asyncio.gather(*watches)
157165

158166

159167
def main():

tests/test_run.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,78 @@ async def test_watch_buffer(
110110
)
111111

112112

113+
@pytest.mark.asyncio
114+
@mock.patch('src.pipeline_watchdog.run.watch_ingress')
115+
@mock.patch('src.pipeline_watchdog.run.watch_egress')
116+
@mock.patch('src.pipeline_watchdog.run.watch_queue')
117+
@mock.patch('src.pipeline_watchdog.run.DockerClient')
118+
async def test_watch_buffer_queue_only(
119+
docker_client_mock,
120+
watch_queue_mock,
121+
watch_egress_mock,
122+
watch_ingress_mock,
123+
config_with_queue_only,
124+
):
125+
docker_client = docker_client_mock()
126+
127+
watch_config = config_with_queue_only.watch_configs[0]
128+
129+
await watch_buffer(docker_client, watch_config)
130+
watch_queue_mock.assert_awaited_once_with(
131+
docker_client, watch_config.buffer, watch_config.queue
132+
)
133+
watch_egress_mock.assert_not_awaited()
134+
watch_ingress_mock.assert_not_awaited()
135+
136+
137+
@pytest.mark.asyncio
138+
@mock.patch('src.pipeline_watchdog.run.watch_ingress')
139+
@mock.patch('src.pipeline_watchdog.run.watch_egress')
140+
@mock.patch('src.pipeline_watchdog.run.watch_queue')
141+
@mock.patch('src.pipeline_watchdog.run.DockerClient')
142+
async def test_watch_buffer_egress_only(
143+
docker_client_mock,
144+
watch_queue_mock,
145+
watch_egress_mock,
146+
watch_ingress_mock,
147+
config_with_egress_only,
148+
):
149+
docker_client = docker_client_mock()
150+
151+
watch_config = config_with_egress_only.watch_configs[0]
152+
153+
await watch_buffer(docker_client, watch_config)
154+
watch_egress_mock.assert_awaited_once_with(
155+
docker_client, watch_config.buffer, watch_config.egress
156+
)
157+
watch_queue_mock.assert_not_awaited()
158+
watch_ingress_mock.assert_not_awaited()
159+
160+
161+
@pytest.mark.asyncio
162+
@mock.patch('src.pipeline_watchdog.run.watch_ingress')
163+
@mock.patch('src.pipeline_watchdog.run.watch_egress')
164+
@mock.patch('src.pipeline_watchdog.run.watch_queue')
165+
@mock.patch('src.pipeline_watchdog.run.DockerClient')
166+
async def test_watch_buffer_ingress_only(
167+
docker_client_mock,
168+
watch_queue_mock,
169+
watch_egress_mock,
170+
watch_ingress_mock,
171+
config_with_ingress_only,
172+
):
173+
docker_client = docker_client_mock()
174+
175+
watch_config = config_with_ingress_only.watch_configs[0]
176+
177+
await watch_buffer(docker_client, watch_config)
178+
watch_ingress_mock.assert_awaited_once_with(
179+
docker_client, watch_config.buffer, watch_config.ingress
180+
)
181+
watch_queue_mock.assert_not_awaited()
182+
watch_egress_mock.assert_not_awaited()
183+
184+
113185
@pytest.mark.asyncio
114186
@mock.patch('src.pipeline_watchdog.run.watch_ingress')
115187
@mock.patch('src.pipeline_watchdog.run.watch_egress')

0 commit comments

Comments
 (0)