Skip to content

Commit

Permalink
Merge pull request #7 from insight-platform/fix-optional-config
Browse files Browse the repository at this point in the history
Do not start watching optional sections
  • Loading branch information
placccebo authored Aug 23, 2024
2 parents 63f9293 + 50abe7a commit 8d23d21
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/pipeline_watchdog/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,20 @@ async def watch_ingress(docker_client: DockerClient, buffer: str, config: FlowCo


async def watch_buffer(docker_client: DockerClient, config: WatchConfig):
logger.info('Watching buffer metrics %s', config.buffer)
await asyncio.gather(
watch_queue(docker_client, config.buffer, config.queue),
watch_egress(docker_client, config.buffer, config.egress),
watch_ingress(docker_client, config.buffer, config.ingress),
)
logger.info('Watching buffer [%s] metrics', config.buffer)
watches = []

if config.queue:
logger.info('Watching queue: %s', config.queue)
watches.append(watch_queue(docker_client, config.buffer, config.queue))
if config.egress:
logger.info('Watching egress flow: %s', config.egress)
watches.append(watch_egress(docker_client, config.buffer, config.egress))
if config.ingress:
logger.info('Watching ingress flow: %s', config.ingress)
watches.append(watch_ingress(docker_client, config.buffer, config.ingress))

await asyncio.gather(*watches)


def main():
Expand Down
72 changes: 72 additions & 0 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,78 @@ async def test_watch_buffer(
)


@pytest.mark.asyncio
@mock.patch('src.pipeline_watchdog.run.watch_ingress')
@mock.patch('src.pipeline_watchdog.run.watch_egress')
@mock.patch('src.pipeline_watchdog.run.watch_queue')
@mock.patch('src.pipeline_watchdog.run.DockerClient')
async def test_watch_buffer_queue_only(
docker_client_mock,
watch_queue_mock,
watch_egress_mock,
watch_ingress_mock,
config_with_queue_only,
):
docker_client = docker_client_mock()

watch_config = config_with_queue_only.watch_configs[0]

await watch_buffer(docker_client, watch_config)
watch_queue_mock.assert_awaited_once_with(
docker_client, watch_config.buffer, watch_config.queue
)
watch_egress_mock.assert_not_awaited()
watch_ingress_mock.assert_not_awaited()


@pytest.mark.asyncio
@mock.patch('src.pipeline_watchdog.run.watch_ingress')
@mock.patch('src.pipeline_watchdog.run.watch_egress')
@mock.patch('src.pipeline_watchdog.run.watch_queue')
@mock.patch('src.pipeline_watchdog.run.DockerClient')
async def test_watch_buffer_egress_only(
docker_client_mock,
watch_queue_mock,
watch_egress_mock,
watch_ingress_mock,
config_with_egress_only,
):
docker_client = docker_client_mock()

watch_config = config_with_egress_only.watch_configs[0]

await watch_buffer(docker_client, watch_config)
watch_egress_mock.assert_awaited_once_with(
docker_client, watch_config.buffer, watch_config.egress
)
watch_queue_mock.assert_not_awaited()
watch_ingress_mock.assert_not_awaited()


@pytest.mark.asyncio
@mock.patch('src.pipeline_watchdog.run.watch_ingress')
@mock.patch('src.pipeline_watchdog.run.watch_egress')
@mock.patch('src.pipeline_watchdog.run.watch_queue')
@mock.patch('src.pipeline_watchdog.run.DockerClient')
async def test_watch_buffer_ingress_only(
docker_client_mock,
watch_queue_mock,
watch_egress_mock,
watch_ingress_mock,
config_with_ingress_only,
):
docker_client = docker_client_mock()

watch_config = config_with_ingress_only.watch_configs[0]

await watch_buffer(docker_client, watch_config)
watch_ingress_mock.assert_awaited_once_with(
docker_client, watch_config.buffer, watch_config.ingress
)
watch_queue_mock.assert_not_awaited()
watch_egress_mock.assert_not_awaited()


@pytest.mark.asyncio
@mock.patch('src.pipeline_watchdog.run.watch_ingress')
@mock.patch('src.pipeline_watchdog.run.watch_egress')
Expand Down

0 comments on commit 8d23d21

Please sign in to comment.