Skip to content

Commit bfdefc9

Browse files
authored
Fixes on webserver diagnostics submodule and setup in dev-mode (#1430)
* Fixes failure upon setup of static module During startup, os.makedirs would fail to create /devel/services/web/client/resources * Makefile: MAKE_C as shortcut for make -C ... * Fixed debug assertion when resp is FileResponse This has an effect only in devel mode * Diagnosis probes avoid collecting from /socket.io
1 parent a957016 commit bfdefc9

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

Makefile

+22-19
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
#
88
# by sanderegg, pcrespov
99
.DEFAULT_GOAL := help
10+
SHELL := /bin/bash
11+
1012

1113
# TOOLS --------------------------------------
1214

15+
MAKE_C := $(MAKE) --no-print-directory --directory
16+
1317
# Operating system
1418
ifeq ($(filter Windows_NT,$(OS)),)
1519
IS_WSL := $(if $(findstring Microsoft,$(shell uname -a)),WSL,)
@@ -20,7 +24,6 @@ endif
2024
IS_WIN := $(strip $(if $(or $(IS_LINUX),$(IS_OSX),$(IS_WSL)),,$(OS)))
2125
$(if $(IS_WIN),$(error Windows is not supported in all recipes. Use WSL instead. Follow instructions in README.md),)
2226

23-
SHELL := /bin/bash
2427

2528
# VARIABLES ----------------------------------------------
2629
# TODO: read from docker-compose file instead $(shell find $(CURDIR)/services -type f -name 'Dockerfile')
@@ -88,7 +91,7 @@ ifeq ($(target),)
8891
# Compiling front-end
8992

9093
@$(if $(findstring -kit,$@),export DOCKER_BUILDKIT=1;export COMPOSE_DOCKER_CLI_BUILD=1;,) \
91-
$(MAKE) -C services/web/client compile$(if $(findstring -x,$@),-x,)
94+
$(MAKE_C) services/web/client compile$(if $(findstring -x,$@),-x,)
9295

9396
# Building services
9497
@$(if $(findstring -kit,$@),export DOCKER_BUILDKIT=1;export COMPOSE_DOCKER_CLI_BUILD=1;,) \
@@ -97,7 +100,7 @@ else
97100
ifeq ($(findstring webserver,$(target)),webserver)
98101
# Compiling front-end
99102
@$(if $(findstring -kit,$@),export DOCKER_BUILDKIT=1;export COMPOSE_DOCKER_CLI_BUILD=1;,) \
100-
$(MAKE) -C services/web/client clean compile$(if $(findstring -x,$@),-x,)
103+
$(MAKE_C) services/web/client clean compile$(if $(findstring -x,$@),-x,)
101104
endif
102105
# Building service $(target)
103106
@$(if $(findstring -kit,$@),export DOCKER_BUILDKIT=1;export COMPOSE_DOCKER_CLI_BUILD=1;,) \
@@ -114,7 +117,7 @@ else
114117
ifeq ($(findstring webserver,$(target)),webserver)
115118
# Compiling front-end
116119
@$(if $(findstring -kit,$@),export DOCKER_BUILDKIT=1;export COMPOSE_DOCKER_CLI_BUILD=1;,) \
117-
$(MAKE) -C services/web/client touch$(if $(findstring -x,$@),-x,) compile-dev
120+
$(MAKE_C) services/web/client touch$(if $(findstring -x,$@),-x,) compile-dev
118121
endif
119122
# Building service $(target)
120123
@$(if $(findstring -kit,$@),export DOCKER_BUILDKIT=1;export COMPOSE_DOCKER_CLI_BUILD=1;,) \
@@ -127,7 +130,7 @@ build-cache build-cache-nc build-cache-kit build-cache-x: .env ## Build cache im
127130
ifeq ($(target),)
128131
# Compiling front-end
129132
@$(if $(findstring -kit,$@),export DOCKER_BUILDKIT=1;export COMPOSE_DOCKER_CLI_BUILD=1;,)
130-
$(MAKE) -C services/web/client compile$(if $(findstring -x,$@),-x,)
133+
$(MAKE_C) services/web/client compile$(if $(findstring -x,$@),-x,)
131134
# Building cache images
132135
@$(if $(findstring -kit,$@),export DOCKER_BUILDKIT=1;export COMPOSE_DOCKER_CLI_BUILD=1;,)
133136
$(_docker_compose_build)
@@ -191,7 +194,7 @@ up-devel: .stack-simcore-development.yml .init-swarm $(CLIENT_WEB_OUTPUT) ## Dep
191194
$(MAKE) .deploy-ops
192195
# Start compile+watch front-end container [front-end]
193196
$(if $(IS_WSL),$(warning WINDOWS: Do not forget to run scripts/win-watcher.bat in cmd),)
194-
$(MAKE) -C services/web/client compile-dev flags=--watch
197+
$(MAKE_C) services/web/client compile-dev flags=--watch
195198

196199
up-prod: .stack-simcore-production.yml .init-swarm ## Deploys local production stack and ops stack (pass 'make ops_disabled=1 up-...' to disable)
197200
# Deploy stack $(SWARM_STACK_NAME)
@@ -215,7 +218,7 @@ down: ## Stops and removes stack
215218
$(shell docker stack ls --format={{.Name}} | tac),\
216219
docker stack rm $(stack);)
217220
# Removing client containers (if any)
218-
-$(MAKE) -C services/web/client down
221+
-$(MAKE_C) services/web/client down
219222
# Removing generated docker compose configurations, i.e. .stack-*
220223
-$(shell rm $(wildcard .stack-*))
221224

@@ -322,9 +325,9 @@ devenv: .venv ## create a python virtual environment with dev tools (e.g. linter
322325

323326
devenv-all: devenv ## sets up extra development tools (everything else besides python)
324327
# Upgrading client compiler
325-
@$(MAKE) --directory services/web/client upgrade
328+
@$(MAKE_C) services/web/client upgrade
326329
# Building tools
327-
@$(MAKE) --directory scripts/json-schema-to-openapi-schema
330+
@$(MAKE_C) scripts/json-schema-to-openapi-schema
328331

329332

330333
## MISC -------------------------------
@@ -348,9 +351,9 @@ new-service: .venv ## Bakes a new project from cookiecutter-simcore-pyservice an
348351

349352
.PHONY: openapi-specs
350353
openapi-specs: ## bundles and validates openapi specifications and schemas of ALL service's API
351-
@$(MAKE) --directory services/web/server $@
352-
@$(MAKE) --directory services/storage $@
353-
@$(MAKE) --directory services/director $@
354+
@$(MAKE_C) services/web/server $@
355+
@$(MAKE_C) services/storage $@
356+
@$(MAKE_C) services/director $@
354357

355358

356359
.PHONY: code-analysis
@@ -397,7 +400,7 @@ ifeq ($(target),)
397400
$(call show-meta,$(service))\
398401
)
399402
## Client images:
400-
@$(MAKE) -C services/web/client info
403+
@$(MAKE_C) services/web/client info
401404
else
402405
## $(target) images:
403406
@$(call show-meta,$(target))
@@ -437,27 +440,27 @@ clean: .check-clean clean-venv ## cleans all unversioned files in project and te
437440
# Cleaning unversioned
438441
@git clean $(git_clean_args)
439442
# Cleaning web/client
440-
@$(MAKE) -C services/web/client clean
443+
@$(MAKE_C) services/web/client clean
441444
# Cleaning postgres maintenance
442-
@$(MAKE) -C packages/postgres-database/docker clean
445+
@$(MAKE_C) packages/postgres-database/docker clean
443446

444447
clean-images: ## removes all created images
445448
# Cleaning all service images
446449
-$(foreach service,$(SERVICES_LIST)\
447450
,docker image rm -f $(shell docker images */$(service):* -q);)
448451
# Cleaning webclient
449-
@$(MAKE) -C services/web/client clean
452+
@$(MAKE_C) services/web/client clean
450453
# Cleaning postgres maintenance
451-
@$(MAKE) -C packages/postgres-database/docker clean
454+
@$(MAKE_C) packages/postgres-database/docker clean
452455

453456
clean-all: clean clean-images # Deep clean including .venv and produced images
454457
-rm -rf .venv
455458

456459

457460
.PHONY: postgres-upgrade
458461
postgres-upgrade: ## initalize or upgrade postgres db to latest state
459-
@$(MAKE) -C packages/postgres-database/docker build
460-
@$(MAKE) -C packages/postgres-database/docker upgrade
462+
@$(MAKE_C) packages/postgres-database/docker build
463+
@$(MAKE_C) packages/postgres-database/docker upgrade
461464

462465
.PHONY: reset
463466
reset: ## restart docker daemon (LINUX ONLY)

services/web/Dockerfile

+4-3
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,10 @@ ENV SC_BUILD_TARGET development
154154
ENV SIMCORE_WEB_OUTDIR /devel/services/web/client
155155

156156
WORKDIR /devel
157-
VOLUME /devel/packages
158-
VOLUME /devel/services/web/server/
159-
VOLUME /devel/services/web/client/
157+
158+
# NOTE: declaring VOLUMEs here makes troubles mounting
159+
# the client's output folder to /devel/services/web/client.
160+
# The latter ls no files
160161

161162
ENTRYPOINT [ "/bin/sh", "services/web/server/docker/entrypoint.sh" ]
162163
CMD ["/bin/sh", "services/web/server/docker/boot.sh"]

services/web/server/src/simcore_service_webserver/diagnostics_monitoring.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async def _middleware_handler(request: web.Request, handler):
4343
resp = await handler(request)
4444
log_exception = None
4545

46-
assert isinstance(resp, web.Response), "Forgot envelope middleware?" # nsec
46+
assert isinstance(resp, web.StreamResponse), "Forgot envelope middleware?" # nsec
4747

4848
except web.HTTPServerError as exc:
4949
# Transforms exception into response object and log exception
@@ -62,18 +62,17 @@ async def _middleware_handler(request: web.Request, handler):
6262
log_exception = exc
6363

6464
finally:
65-
assert isinstance( # nsec
66-
resp, web.Response # nsec
67-
), "Forgot envelope middleware or transformation?" # nsec
68-
6965
resp_time_secs: float = time.time() - request[kSTART_TIME]
7066

7167
exc_name = ""
7268
if log_exception:
7369
exc_name: str = log_exception.__class__.__name__
7470

7571
# Probes request latency
76-
request.app[kLATENCY_PROBE].observe(resp_time_secs)
72+
# NOTE: sockets connection is long
73+
# FIXME: tmp by hand, add filters directly in probe
74+
if not str(request.path).startswith("/socket.io"):
75+
request.app[kLATENCY_PROBE].observe(resp_time_secs)
7776

7877
# prometheus probes
7978
request.app[kREQUEST_LATENCY].labels(app_name, request.path).observe(

0 commit comments

Comments
 (0)