Skip to content

Commit

Permalink
Merge pull request #5842 from tomachalek/indirect_call_b
Browse files Browse the repository at this point in the history
Log indirect (api) calls, improve pquery logging
  • Loading branch information
tomachalek authored May 23, 2023
2 parents 84ad31a + 2707e1c commit df75fee
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
17 changes: 14 additions & 3 deletions lib/action/argmapping/log_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def query_submit(request: KRequest):
qmcase=q0.get('qmcase'),
extended_query=any(p for p in parsed if p[1] is True),
uses_context=request.json.get('fc_lemword') or len(request.json.get('fc_pos', [])),
uses_tt=len(request.json.get('text_types', {})) > 0)
uses_tt=len(request.json.get('text_types', {})) > 0
)
return {}


Expand All @@ -52,10 +53,20 @@ def view(request: KRequest):

def wordlist(request: KRequest):
return dict(
corpname=request.form.get('corpname'), wlsort=request.form.get('wlsort'),
wlnums=request.form.get('wlnums'), wltype=request.form.get('wltype'))
corpname=request.form.get('corpname'),
wlsort=request.form.get('wlsort'),
wlnums=request.form.get('wlnums'),
wltype=request.form.get('wltype'))


def pquery(request: KRequest):
return dict(
corpname=request.json.get('corpname'),
pquery_type=request.json.get('pquery_type'),
attr=request.json.get('attr'),
num_conc=len(request.json.get('conc_ids', []))
)

def widectx(request: KRequest):
attrs = request.args.get('attrs', '').split(',')
structs = list(set(x.split('.')[0] for x in request.args.get('structs', '').split(',')))
Expand Down
5 changes: 4 additions & 1 deletion lib/plugins/default_action_log/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def expand_error_desc(e: Tuple[Exception, str]) -> Tuple[str, Union[str, None],
return e[0].__class__.__name__, str(e[0]), e[1]

def collect_args(self, request, args_map, action_log_mapper, full_action_name, err_desc):
log_data = {'args': {}}
log_data = {
'args': {},
'is_indirect_call': 'x-indirect-call' in request.headers
}
if action_log_mapper:
try:
log_data['args'] = action_log_mapper(request)
Expand Down
5 changes: 4 additions & 1 deletion lib/views/pquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from action.argmapping.pquery import PqueryFormArgs
from action.control import http_action
from action.argmapping.action import IntOpt
from action.argmapping import log_mapping
from action.errors import NotFoundException
from action.krequest import KRequest
from action.model.pquery import ParadigmaticQueryActionModel
Expand Down Expand Up @@ -98,7 +99,9 @@ async def result(amodel: ParadigmaticQueryActionModel, req: KRequest, resp: KRes


@bp.route('/freq_intersection', ['POST'])
@http_action(return_type='json', mutates_result=True, action_model=ParadigmaticQueryActionModel)
@http_action(
return_type='json', mutates_result=True, action_model=ParadigmaticQueryActionModel,
action_log_mapper=log_mapping.pquery)
async def freq_intersection(amodel: ParadigmaticQueryActionModel, req: KRequest, resp: KResponse):
"""
Run a paradigmatic query out of existing concordances.
Expand Down

0 comments on commit df75fee

Please sign in to comment.