-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Firebreak/data hub test data contacts #5348
Closed
Closed
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
7c48b7d
Merge branch 'main' of https://github.com/uktrade/data-hub-api
bau123 921f1dd
Merge branch 'main' of https://github.com/uktrade/data-hub-api
bau123 03a4447
Update redis
marijnkampf 2ffc6ae
Update open search
marijnkampf dba86b0
Update pingdom end point url
marijnkampf e9da205
Feature/dpm 174 data hub api investigate rq health check (#5266)
marijnkampf 542a1b5
DPM 199 Data Hub API logging (#5304)
marijnkampf c5d7bb3
do not run collectstatic at run time on DBT Platform
acodeninja f34159a
add build configuration for DBT Platform
acodeninja 9e852f4
remove debug setup
acodeninja 565d4c5
Initial commit for factories
marijnkampf 8ab6646
Added progress indicator
marijnkampf 2e20d7f
Reduce default number for testing
marijnkampf 810af9f
Update company factories calls so that they use existing objects when…
swenban 6682b4a
Fix linting errors and improve query efficiency
swenban 4efd9e5
Fix print linting errors
swenban 59ac8ee
Initial commit for factories
marijnkampf 7cc4b96
Added progress indicator
marijnkampf 13787c3
Reduce default number for testing
marijnkampf 161e68d
Update company factories calls so that they use existing objects when…
swenban 1033048
Fix linting errors and improve query efficiency
swenban de6eaa3
Fix print linting errors
swenban 1c3c20a
generate contact records
bau123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
repository: data-hub-api | ||
builder: | ||
name: paketobuildpacks/builder-jammy-full | ||
version: 0.3.339 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Exit early if something goes wrong | ||
set -e | ||
|
||
# Add commands below to run inside the container after all the other buildpacks have been applied | ||
export ADMIN_OAUTH2_ENABLED="True" | ||
export ADMIN_OAUTH2_BASE_URL="" | ||
export ADMIN_OAUTH2_TOKEN_FETCH_PATH="/o/token/" | ||
export ADMIN_OAUTH2_USER_PROFILE_PATH="/o/v1/user/me/" | ||
export ADMIN_OAUTH2_AUTH_PATH="/o/authorize/" | ||
export ADMIN_OAUTH2_CLIENT_ID="client-id" | ||
export ADMIN_OAUTH2_CLIENT_SECRET="client-secret" | ||
export ADMIN_OAUTH2_LOGOUT_PATH="/o/logout" | ||
export ACTIVITY_STREAM_ACCESS_KEY_ID="some-id" | ||
export ACTIVITY_STREAM_SECRET_ACCESS_KEY="some-secret" | ||
export DATABASE_URL="postgresql://postgres:datahub@postgres/datahub" | ||
export DEBUG="True" | ||
export DJANGO_SECRET_KEY="changeme" | ||
export DJANGO_SETTINGS_MODULE="config.settings.local" | ||
export ES_INDEX_PREFIX="test_index" | ||
export ES5_URL="http://localhost:9200" | ||
export OPENSEARCH_URL="http://localhost:9200" | ||
export OPENSEARCH_INDEX_PREFIX="test_index" | ||
export PAAS_IP_ALLOWLIST="1.2.3.4" | ||
export AWS_DEFAULT_REGION="eu-west-2" | ||
export AWS_ACCESS_KEY_ID="foo" | ||
export AWS_SECRET_ACCESS_KEY="bar" | ||
export DEFAULT_BUCKET="baz" | ||
export SSO_ENABLED="True" | ||
export STAFF_SSO_BASE_URL="http://sso.invalid/" | ||
export STAFF_SSO_AUTH_TOKEN="sso-token" | ||
export DIT_EMAIL_DOMAINS="trade.gov.uk,digital.trade.gov.uk" | ||
export DATA_HUB_FRONTEND_ACCESS_KEY_ID="frontend-key-id" | ||
export DATA_HUB_FRONTEND_SECRET_ACCESS_KEY="frontend-key" | ||
export ES_APM_ENABLED="False" | ||
export ES_APM_SERVICE_NAME="datahub" | ||
export ES_APM_SECRET_TOKEN="" | ||
export ES_APM_SERVER_URL="http://localhost:8200" | ||
export ES_APM_ENVIRONMENT="circleci" | ||
export REDIS_BASE_URL="redis://localhost:6379" | ||
|
||
python manage.py collectstatic --noinput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Exit early if something goes wrong | ||
set -e | ||
|
||
# Add commands below to run as part of the build phase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Exit early if something goes wrong | ||
set -e | ||
|
||
# Add commands below to run as part of the install phase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Exit early if something goes wrong | ||
set -e | ||
|
||
# Add commands below to run as part of the post_build phase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Exit early if something goes wrong | ||
set -e | ||
|
||
# Add commands below to run as part of the pre_build phase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,42 @@ | ||||||
import sys | ||||||
|
||||||
from functools import reduce | ||||||
from logging import getLogger | ||||||
from operator import concat | ||||||
|
||||||
from django.conf import settings | ||||||
from django.core.management.base import BaseCommand | ||||||
from redis import Redis | ||||||
from rq import Worker | ||||||
|
||||||
|
||||||
logger = getLogger(__name__) | ||||||
|
||||||
|
||||||
class Command(BaseCommand): | ||||||
help = 'RQ Health Check' | ||||||
|
||||||
def add_arguments(self, parser): | ||||||
"""Define extra arguments.""" | ||||||
parser.add_argument( | ||||||
'--queue', | ||||||
type=str, | ||||||
help='Name of the queue to perform health check on.', | ||||||
) | ||||||
|
||||||
def handle(self, *args, **options): | ||||||
if options['queue']: | ||||||
queue = str(options['queue']) | ||||||
redis = Redis.from_url(settings.REDIS_BASE_URL) | ||||||
workers = Worker.all(connection=redis) | ||||||
queue_names = reduce(concat, [worker.queue_names() for worker in workers], []) | ||||||
missing_queues = set([queue]) - set(queue_names) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Using set literal syntax is simpler and computationally quicker. More info. |
||||||
|
||||||
if missing_queues: | ||||||
logger.error(f'RQ queue not running: {missing_queues}') | ||||||
sys.exit(1) | ||||||
logger.info('OK') | ||||||
sys.exit(0) | ||||||
|
||||||
logger.error('Nothing checked! Please provide --queue parameter') | ||||||
sys.exit(1) |
63 changes: 63 additions & 0 deletions
63
datahub/core/test/management/commands/test_rq_health_check.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import logging | ||
from unittest import mock | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from django.core.management import call_command | ||
|
||
|
||
class MockWorker: | ||
""" | ||
Mock queue names object returned by worker | ||
""" | ||
|
||
queue_name = '' | ||
|
||
def __init__(self, queue_name, *args, **kwargs): | ||
self.queue_name = queue_name | ||
|
||
def queue_names(self): | ||
return self.queue_name | ||
|
||
|
||
def test_rq_health_check_ok(): | ||
logger = logging.getLogger('datahub.core.management.commands.rq_health_check') | ||
with patch( | ||
'datahub.core.management.commands.rq_health_check.Worker.all', | ||
return_value=[MockWorker(['short-running']), MockWorker(['long-running'])], | ||
): | ||
with mock.patch.object(logger, 'info') as mock_info: | ||
with pytest.raises(SystemExit) as exception_info: | ||
call_command('rq_health_check', '--queue=short-running') | ||
|
||
assert exception_info.value.code == 0 | ||
assert 'OK' in str(mock_info.call_args_list) | ||
assert mock_info.call_count == 1 | ||
|
||
|
||
def test_rq_health_check_rq_not_running(): | ||
logger = logging.getLogger('datahub.core.management.commands.rq_health_check') | ||
with patch( | ||
'datahub.core.management.commands.rq_health_check.Worker.all', | ||
return_value=[MockWorker(['long-running'])], | ||
): | ||
with mock.patch.object(logger, 'error') as mock_error: | ||
with pytest.raises(SystemExit) as exception_info: | ||
call_command('rq_health_check', '--queue=short-running') | ||
|
||
assert exception_info.value.code == 1 | ||
assert "RQ queue not running: {\'short-running\'}" in str(mock_error.call_args_list) | ||
assert mock_error.call_count == 1 | ||
|
||
|
||
def test_command_called_without_parameter(): | ||
logger = logging.getLogger('datahub.core.management.commands.rq_health_check') | ||
with mock.patch.object(logger, 'error') as mock_error: | ||
with pytest.raises(SystemExit) as exception_info: | ||
call_command('rq_health_check') | ||
|
||
assert exception_info.value.code == 1 | ||
assert 'Nothing checked! Please provide --queue parameter' \ | ||
in str(mock_error.call_args_list) | ||
assert mock_error.call_count == 1 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using set literal syntax is simpler and computationally quicker. More info.