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

Fix phantom js checks #5159

Merged
merged 6 commits into from
Jul 18, 2019
Merged
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
2 changes: 1 addition & 1 deletion ci/test-app
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ docker-compose exec geoportal theme2fts
#git commit -m "Upgrade the po files"

ci/run-dc-logs docker-compose exec geoportal ci/waitwsgi https://front/
for path in c2c/health_check c2c/health_check?max_level=9 c2c/health_check?checks=check_collector layers/test/values/type enum admin/layertree admin/layertree/children
for path in c2c/health_check c2c/health_check?max_level=9 c2c/health_check?checks=check_collector "layers/test/values/type enum" admin/layertree admin/layertree/children
do
ci/run-dc-logs docker-compose exec geoportal ci/test-new-project https://front/${path}
#docker-compose exec geoportal curl --insecure https://front/c2c/debug/stacks?secret=c2c
Expand Down
11 changes: 8 additions & 3 deletions ci/test-new-project
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ url = sys.argv[1]
result = requests.get(url, timeout=240, verify=False)

if len(sys.argv) == 3 and sys.argv[2] == "enum":
if result.status_code == 200 and result.json() == {
if result.ok and result.json() == {
"items": [{
"value": "car"
}, {
Expand All @@ -56,5 +56,10 @@ if len(sys.argv) == 3 and sys.argv[2] == "enum":
print("Incorrect result ({}):".format(result.status_code))
print(result.text)
exit(2)
#print(result.text)
print("OK")

if result.ok:
print("OK")
else:
print("NOT OK")
print(result.text)
exit(2)
19 changes: 2 additions & 17 deletions ci/vars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ vars:
travis_test:
url: postgresql://{PGUSER}:{PGPASSWORD}@externaldb:{PGPORT}/test

admin_interface:
available_metadata:
- name: _color
type: regex
regex: "^#([A-Fa-f0-9]{{{{6}}}}|[A-Fa-f0-9]{{{{3}}}})$"
error_message: "Expecting hex format for color, e.g. #007DCD"

layers:
enum:
test:
Expand All @@ -25,15 +18,9 @@ vars:
checker:
fulltextsearch:
disable: true
lang:
files: [ngeo]
routes:
disable: [apijs, xapijs]
routes:
- name: dynamic
params:
interface: desktop
level: 3
disable:
- printproxy_capabilities

check_collector:
hosts:
Expand All @@ -43,7 +30,5 @@ vars:
update_paths:
- layers
- checker.fulltextsearch
- checker.lang
- checker.routes
- check_collector
- admin_interface.available_metadata
2 changes: 1 addition & 1 deletion geoportal/c2cgeoportal_geoportal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def add_api_route(name: str, attr: str, path: str, renderer: str):
config.add_route(name, path, request_method="GET")
config.add_view(
Entry, attr=attr, route_name=name,
renderer='/etc/static-ngeo/{}'.format(renderer)
renderer='/etc/geomapfish/static/{}'.format(renderer)
)
add_api_route('favicon', 'favicon', '/favicon.ico', 'js/apps/image/favicon.ico')
add_api_route('apijsmap', 'apijsmap', '/api.js.map', "api.js.map")
Expand Down
77 changes: 50 additions & 27 deletions geoportal/c2cgeoportal_geoportal/lib/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@

import logging
import subprocess
import c2cwsgiutils.health_check
from time import sleep
from urllib.parse import urljoin

import c2cwsgiutils.health_check
import requests

log = logging.getLogger(__name__)
LOG = logging.getLogger(__name__)


def build_url(name, path, request, headers=None):
""" Build an URL and headers for the checkers """
base_internal_url = request.registry.settings["checker"]["base_internal_url"]
url = urljoin(base_internal_url, path)

Expand All @@ -47,7 +48,7 @@ def build_url(name, path, request, headers=None):
if forward_host:
headers["Host"] = request.host

log.debug("%s, URL: %s", name, url)
LOG.warning("%s, URL: %s", name, url)
return {"url": url, "headers": headers}


Expand Down Expand Up @@ -213,19 +214,33 @@ def _lang_files(global_settings, settings, health_check):
else:
raise Exception("Your language type value '%s' is not valid, "
"available values [ngeo]" % type_)

name = "checker_lang_{}_{}".format(type_, lang)

def get_both(url, lang, request):
return build_url(
name,
request.static_path(url.format(package=global_settings["package"], lang=lang)),
request
)
class GetRequest:
"""
Get the request information about the current route name
"""
def __init__(self, name, url, lang, type_):
self.name = name
self.url = url
self.lang = lang
self.type = type_

def __call__(self, request):
return build_url(
self.name,
request.static_path(self.url.format(
package=global_settings["package"],
lang=self.lang
)),
request
)[self.type]

health_check.add_url_check(
name=name,
url=lambda r, u=url, la=lang: get_both(u, la, r)["url"],
headers=lambda r, u=url, la=lang: get_both(u, la, r)["headers"],
url=GetRequest(name, url, lang, 'url'),
headers=GetRequest(name, url, lang, 'headers'),
level=lang_settings["level"],
)

Expand All @@ -236,28 +251,36 @@ def _phantomjs(settings, health_check):
if route.get("checker_name", route["name"]) in phantomjs_settings["disable"]:
continue

def check(request):
path = request.route_path(route["name"], _query=route.get("params", {}))
url = build_url("Check", path, request)["url"]

cmd = [
"node", "/usr/bin/check-example.js", url
]

try:
subprocess.check_output(cmd, timeout=10)
except subprocess.CalledProcessError as e:
raise Exception(e.output.decode("utf-8"))
except subprocess.TimeoutExpired as e:
raise Exception("""Timeout:
class _Check:
def __init__(self, route):
self.route = route

def __call__(self, request):
path = request.route_path(self.route["name"], _query=self.route.get("params", {}))
url = build_url("Check", path, request)["url"]

cmd = [
"node", "/usr/bin/check-example.js", url
]

try:
subprocess.check_output(cmd, timeout=10)
except subprocess.CalledProcessError as exception:
raise Exception("{} exit with code: {}\n{}".format(
' '.join(exception.cmd),
exception.returncode, exception.output.decode("utf-8")
))
except subprocess.TimeoutExpired as exception:
raise Exception("""Timeout:
command: {}
output:
{}""".format(" ".join(e.cmd), e.output.decode("utf-8")))
{}""".format(" ".join(exception.cmd), exception.output.decode("utf-8")))
name = "checker_phantomjs_" + route.get("checker_name", route["name"])
health_check.add_custom_check(name=name, check_cb=check, level=route["level"])
health_check.add_custom_check(name=name, check_cb=_Check(route), level=route["level"])


def init(config, health_check):
""" Init the ckeckers """
global_settings = config.get_settings()
if "checker" not in global_settings:
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ vars:
# layers: []
# legend: {}
phantomjs:
disable: [desktop, mobile]
disable: [desktop, mobile, apihelp]

check_collector:
hosts: []
Expand Down