feat(chalice): try to ignore dashboard calls for /chart for clickMaps
This commit is contained in:
parent
dcf853b23c
commit
0ad393ae06
4 changed files with 35 additions and 18 deletions
|
|
@ -580,6 +580,7 @@ def make_chart_from_card(project_id, user_id, metric_id, data: schemas.CardChart
|
|||
if metric.is_template:
|
||||
return get_predefined_metric(key=metric.metric_of, project_id=project_id, data=data.dict())
|
||||
elif __is_click_map(metric):
|
||||
# TODO: remove this when UI is able to stop this endpoint calls for clickMap
|
||||
if from_dashboard:
|
||||
return None
|
||||
if raw_metric["data"]:
|
||||
|
|
|
|||
|
|
@ -230,8 +230,12 @@ def get_custom_metric_errors_list(projectId: int, metric_id: int,
|
|||
@app.post('/{projectId}/custom_metrics/{metric_id}/chart', tags=["customMetrics"])
|
||||
def get_card_chart(projectId: int, metric_id: int, request: Request, data: schemas.CardChartSchema = Body(...),
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
# TODO: remove this when UI is able to stop this endpoint calls for clickMap
|
||||
print("--- headers ---")
|
||||
print(request.headers)
|
||||
print(request.headers.get('REFERER'))
|
||||
print(request.headers.get('referer'))
|
||||
print(request.headers.get('Referer'))
|
||||
import re
|
||||
pattern = re.compile("[0-9]+\/dashboard\/[0-9]+$")
|
||||
from_dashboard = pattern.match(request.headers.get('REFERER')) if request.headers.get('REFERER') \
|
||||
|
|
|
|||
|
|
@ -628,27 +628,31 @@ def get_funnel_sessions_by_issue(user_id, project_id, metric_id, issue_id,
|
|||
"issue": issue}
|
||||
|
||||
|
||||
def make_chart_from_card(project_id, user_id, metric_id, data: schemas.CardChartSchema):
|
||||
def make_chart_from_card(project_id, user_id, metric_id, data: schemas.CardChartSchema, from_dashboard=False):
|
||||
raw_metric: dict = get_card(metric_id=metric_id, project_id=project_id, user_id=user_id, include_data=True)
|
||||
if raw_metric is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="card not found")
|
||||
metric: schemas_ee.CreateCardSchema = schemas_ee.CreateCardSchema(**raw_metric)
|
||||
if metric.is_template:
|
||||
return get_predefined_metric(key=metric.metric_of, project_id=project_id, data=data.dict())
|
||||
elif __is_click_map(metric) and raw_metric["data"]:
|
||||
keys = sessions_mobs. \
|
||||
__get_mob_keys(project_id=project_id, session_id=raw_metric["data"]["sessionId"])
|
||||
mob_exists = False
|
||||
for k in keys:
|
||||
if s3.exists(bucket=config("sessions_bucket"), key=k):
|
||||
mob_exists = True
|
||||
break
|
||||
if mob_exists:
|
||||
raw_metric["data"]['domURL'] = sessions_mobs.get_urls(session_id=raw_metric["data"]["sessionId"],
|
||||
project_id=project_id)
|
||||
raw_metric["data"]['mobsUrl'] = sessions_mobs.get_urls_depercated(
|
||||
session_id=raw_metric["data"]["sessionId"])
|
||||
return raw_metric["data"]
|
||||
elif __is_click_map(metric):
|
||||
# TODO: remove this when UI is able to stop this endpoint calls for clickMap
|
||||
if from_dashboard:
|
||||
return None
|
||||
if raw_metric["data"]:
|
||||
keys = sessions_mobs. \
|
||||
__get_mob_keys(project_id=project_id, session_id=raw_metric["data"]["sessionId"])
|
||||
mob_exists = False
|
||||
for k in keys:
|
||||
if s3.exists(bucket=config("sessions_bucket"), key=k):
|
||||
mob_exists = True
|
||||
break
|
||||
if mob_exists:
|
||||
raw_metric["data"]['domURL'] = sessions_mobs.get_urls(session_id=raw_metric["data"]["sessionId"],
|
||||
project_id=project_id)
|
||||
raw_metric["data"]['mobsUrl'] = sessions_mobs.get_urls_depercated(
|
||||
session_id=raw_metric["data"]["sessionId"])
|
||||
return raw_metric["data"]
|
||||
|
||||
return make_chart(project_id=project_id, user_id=user_id, data=data, metric=metric)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from typing import Union
|
||||
|
||||
from fastapi import Body, Depends
|
||||
from fastapi import Body, Depends, Request
|
||||
|
||||
import schemas
|
||||
import schemas_ee
|
||||
|
|
@ -230,10 +230,18 @@ def get_custom_metric_errors_list(projectId: int, metric_id: int,
|
|||
@app.post('/{projectId}/cards/{metric_id}/chart', tags=["card"])
|
||||
@app.post('/{projectId}/metrics/{metric_id}/chart', tags=["dashboard"])
|
||||
@app.post('/{projectId}/custom_metrics/{metric_id}/chart', tags=["customMetrics"])
|
||||
def get_card_chart(projectId: int, metric_id: int, data: schemas.CardChartSchema = Body(...),
|
||||
def get_card_chart(projectId: int, metric_id: int, request: Request, data: schemas.CardChartSchema = Body(...),
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
# TODO: remove this when UI is able to stop this endpoint calls for clickMap
|
||||
print("--- headers ---")
|
||||
print(request.headers)
|
||||
import re
|
||||
pattern = re.compile("[0-9]+\/dashboard\/[0-9]+$")
|
||||
from_dashboard = pattern.match(request.headers.get('REFERER')) if request.headers.get('REFERER') \
|
||||
else False
|
||||
print(f"from_dashboard:{from_dashboard}")
|
||||
data = custom_metrics.make_chart_from_card(project_id=projectId, user_id=context.user_id, metric_id=metric_id,
|
||||
data=data)
|
||||
data=data, from_dashboard=from_dashboard)
|
||||
return {"data": data}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue