Skip to content
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

Customize Health Page Title #288

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
if: ${{ matrix.test_type == 'INDEXING' }}
env:
S3_ENCRYPT_KEY: ${{ secrets.S3_ENCRYPT_KEY }}
GLOBAL_ENV_BUCKET: "foursight-prod-envs"
# # The need for this old environment variable name will go away soon.
# TRAVIS_JOB_ID: sno-x-test-${{ github.run_number }}-
# This will be the new environment variable name.
Expand All @@ -72,6 +73,7 @@ jobs:
if: ${{ matrix.test_type == 'UNIT' }}
env:
S3_ENCRYPT_KEY: ${{ secrets.S3_ENCRYPT_KEY }}
GLOBAL_ENV_BUCKET: "foursight-prod-envs"
# # The need for this old environment variable name will go away soon.
# TRAVIS_JOB_ID: sno-x-test-${{ github.run_number }}-
# This will be the new environment variable name.
Expand All @@ -83,6 +85,7 @@ jobs:
if: ${{ always() && matrix.test_type == 'INDEXING' }}
env:
S3_ENCRYPT_KEY: ${{ secrets.S3_ENCRYPT_KEY }}
GLOBAL_ENV_BUCKET: "foursight-prod-envs"
# The need for this old environment variable name will go away soon.
# TRAVIS_JOB_ID: sno-x-test-${{ github.run_number }}-
# This will be the new environment variable name.
Expand All @@ -94,6 +97,7 @@ jobs:
if: ${{ always() && matrix.test_type == 'UNIT' }}
env:
S3_ENCRYPT_KEY: ${{ secrets.S3_ENCRYPT_KEY }}
GLOBAL_ENV_BUCKET: "foursight-prod-envs"
# The need for this old environment variable name will go away soon.
# TRAVIS_JOB_ID: sno-x-test-${{ github.run_number }}-
# This will be the new environment variable name.
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ snovault
Change Log
----------

11.14.0
=======

* Allow customization of health page title


11.13.0
=======

Expand Down
939 changes: 567 additions & 372 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicsnovault"
version = "11.13.0"
version = "11.14.0"
description = "Storage support for 4DN Data Portals."
authors = ["4DN-DCIC Team <[email protected]>"]
license = "MIT"
Expand Down Expand Up @@ -84,6 +84,7 @@ xlrd = "^1.0.0"
"zope.interface" = ">=4.7.2,<6"
"zope.sqlalchemy" = "1.6"
jsonschema = {extras = ["format-nongpl"], version = "^4.19.0"}
uptime = "^3.0.1"

[tool.poetry.dev-dependencies]
boto3-stubs = ">=1.28.62" # no particular version required, but this speeds up search
Expand Down
20 changes: 20 additions & 0 deletions snovault/crud_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ def build_diff_from_request(context, request):
return dm.patch_diffs(body)


def build_comparison_from_request(context, request, props):
""" Very similar to above method but runs a comparison instead """
try:
item_type = context.type_info.name
body = json.loads(request.body)
extract_and_populate_deleted_fields(request, body)
dm = DiffManager(label=item_type)
except json.decoder.JSONDecodeError:
log.info('Request body is not valid JSON!') # can happen from indirect patch, such as with access key
return None
except Exception as e:
log.error('Unknown error encountered building diff from request: %s' % e)
return None
return dm._diffs(props, body)


def create_item(type_info, request, properties, sheets=None):
'''
Validates or generates new UUID, instantiates & saves an Item in
Expand Down Expand Up @@ -240,6 +256,10 @@ def item_edit(context, request, render=None):
render = request.params.get('render', True)

# This *sets* the property sheet and adds the item to the indexing queue
check_diff = asbool(request.params.get('check_diff', False))
if check_diff:
comparison = build_comparison_from_request(context, request, context.properties)
import pdb; pdb.set_trace()
update_item(context, request, request.validated)

rendered = render_item(request, context, render)
Expand Down
6 changes: 4 additions & 2 deletions snovault/loadxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,13 +684,15 @@ def get_schema_info(type_name: str) -> (list, list):
if not identifying_path:
raise Exception("Item has no uuid nor any other identifying property; cannot PATCH.")
normalized_item, deleted_properties = normalize_deleted_properties(an_item)
identifying_path += '?check_diff=true'
if deleted_properties:
if validate_only and skip_links:
identifying_path += f"?delete_fields={','.join(deleted_properties)}&skip_links=true"
identifying_path += f"&delete_fields={','.join(deleted_properties)}&skip_links=true"
else:
identifying_path += f"?delete_fields={','.join(deleted_properties)}"
identifying_path += f"&delete_fields={','.join(deleted_properties)}"
elif validate_only and skip_links:
identifying_path += f"?skip_links=true"

res = testapp.patch_json(identifying_path, normalized_item)
assert res.status_code == 200
patched += 1
Expand Down
5 changes: 5 additions & 0 deletions snovault/project/health.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class SnovaultProjectHealthValue:

@staticmethod
def get_app_namespace():
return 'ENCODED'
2 changes: 2 additions & 0 deletions snovault/project_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .project.loadxl import SnovaultProjectLoadxl
from .project.renderers import SnovaultProjectRenderers
from .project.schema_views import SnovaultProjectSchemaViews
from .project.health import SnovaultProjectHealthValue


@C4ProjectRegistry.register("dcicsnovault")
Expand All @@ -16,6 +17,7 @@ class SnovaultProject(SnovaultProjectAccessKey,
SnovaultProjectLoadxl,
SnovaultProjectRenderers,
SnovaultProjectSchemaViews,
SnovaultProjectHealthValue,
C4Project):
NAMES = {"NAME": "snovault", "PYPI_NAME": "dcicsnovault"}
ACCESSION_PREFIX = "SNO"
10 changes: 7 additions & 3 deletions snovault/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .appdefs import APP_VERSION_REGISTRY_KEY, ITEM_INDEX_ORDER
from .schema_formats import is_accession
from .util import SettingsKey
from .project_app import app_project


def includeme(config):
Expand Down Expand Up @@ -111,7 +112,10 @@ class ExtendedHealthPageKey(HealthPageKey):
settings = request.registry.settings

env_name = settings.get('env.name')
foursight_url = infer_foursight_url_from_env(request=request, envname=env_name)
try:
foursight_url = infer_foursight_url_from_env(request=request, envname=env_name)
except Exception: # this can fail in unit testing depending on env_name
foursight_url = 'Could-not-resolve-foursight'

response_dict = {

Expand All @@ -124,8 +128,8 @@ class ExtendedHealthPageKey(HealthPageKey):
h.BEANSTALK_APP_VERSION: settings.get(s.EB_APP_VERSION),
h.BEANSTALK_ENV: env_name,
h.BLOB_BUCKET: settings.get(s.BLOB_BUCKET),
h.DATABASE: settings.get(s.SQLALCHEMY_URL).split('@')[1], # don't show user /password
h.DISPLAY_TITLE: "ENCODED Portal Status and Foursight Monitoring",
h.DATABASE: settings.get(s.SQLALCHEMY_URL, 'dummy@postgres').split('@')[1], # don't show user /password
h.DISPLAY_TITLE: f"{app_project().get_app_namespace()} Portal Status and Foursight Monitoring",
h.ELASTICSEARCH: settings.get(s.ELASTICSEARCH_SERVER),
h.FILE_UPLOAD_BUCKET: settings.get(s.FILE_UPLOAD_BUCKET),
h.FOURSIGHT: foursight_url,
Expand Down
2 changes: 2 additions & 0 deletions snovault/tests/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Deny,
Everyone,
)
from ..root import health_check
from ..schema_utils import format_checker
from ..calculated import calculated_property
from ..resources import Root
Expand All @@ -19,6 +20,7 @@


def includeme(config):
config.include(health_check)
config.scan(__name__)


Expand Down
12 changes: 12 additions & 0 deletions snovault/tests/test_health_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest
from dcicutils.misc_utils import ignored


ignored(pytest)


def test_health_page_basic(testapp):
""" Tests that we can reach the health page and that the customization works """
health = testapp.get('/health').json
assert health['display_title'] == 'ENCODED Portal Status and Foursight Monitoring'
assert health['database'] == 'postgres'
2 changes: 1 addition & 1 deletion snovault/tests/test_post_put_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_patch(content, testapp):
assert res.json['simple1'] == 'simple1 default'
assert res.json['simple2'] == 'simple2 default'

res = testapp.patch_json(url, {}, status=200)
res = testapp.patch_json(url+'?check_diff=true', {}, status=200)
assert res.json['@graph'][0]['simple1'] == 'simple1 default'
assert res.json['@graph'][0]['simple2'] == 'simple2 default'

Expand Down
1 change: 1 addition & 0 deletions snovault/tests/testappfixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .. import main # Function main actually defined in __init__.py (should maybe be defined elsewhere)

_app_settings = {
'env.name': 'snovault',
'collection_datastore': 'database',
'item_datastore': 'database',
'load_test_only': True,
Expand Down