Merge remote-tracking branch 'origin/api-v1.8.2' into dev
This commit is contained in:
commit
b98873817f
8 changed files with 76 additions and 57 deletions
|
|
@ -199,7 +199,8 @@ def process():
|
|||
logging.info(f"Valid alert, notifying users, alertId:{alert['alertId']} name: {alert['name']}")
|
||||
notifications.append(generate_notification(alert, result))
|
||||
except Exception as e:
|
||||
logging.error(f"!!!Error while running alert query for alertId:{alert['alertId']} name: {alert['name']}")
|
||||
logging.error(
|
||||
f"!!!Error while running alert query for alertId:{alert['alertId']} name: {alert['name']}")
|
||||
logging.error(query)
|
||||
logging.error(e)
|
||||
cur = cur.recreate(rollback=True)
|
||||
|
|
@ -212,12 +213,22 @@ def process():
|
|||
alerts.process_notifications(notifications)
|
||||
|
||||
|
||||
def __format_value(x):
|
||||
if x % 1 == 0:
|
||||
x = int(x)
|
||||
else:
|
||||
x = round(x, 2)
|
||||
return f"{x:,}"
|
||||
|
||||
|
||||
def generate_notification(alert, result):
|
||||
left = __format_value(result['value'])
|
||||
right = __format_value(alert['query']['right'])
|
||||
return {
|
||||
"alertId": alert["alertId"],
|
||||
"tenantId": alert["tenantId"],
|
||||
"title": alert["name"],
|
||||
"description": f"has been triggered, {alert['query']['left']} = {round(result['value'], 2)} ({alert['query']['operator']} {alert['query']['right']}).",
|
||||
"description": f"has been triggered, {alert['query']['left']} = {left} ({alert['query']['operator']} {right}).",
|
||||
"buttonText": "Check metrics for more details",
|
||||
"buttonUrl": f"/{alert['projectId']}/metrics",
|
||||
"imageUrl": None,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from decouple import config
|
||||
|
||||
from chalicelib.utils.s3 import client
|
||||
from chalicelib.utils import s3
|
||||
|
||||
|
||||
def __get_devtools_keys(project_id, session_id):
|
||||
|
|
@ -16,7 +16,7 @@ def __get_devtools_keys(project_id, session_id):
|
|||
def get_urls(session_id, project_id):
|
||||
results = []
|
||||
for k in __get_devtools_keys(project_id=project_id, session_id=session_id):
|
||||
results.append(client.generate_presigned_url(
|
||||
results.append(s3.client.generate_presigned_url(
|
||||
'get_object',
|
||||
Params={'Bucket': config("sessions_bucket"), 'Key': k},
|
||||
ExpiresIn=config("PRESIGNED_URL_EXPIRATION", cast=int, default=900)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
from decouple import config
|
||||
|
||||
from chalicelib.utils import s3
|
||||
from chalicelib.utils.s3 import client
|
||||
|
||||
|
||||
def __get_mob_keys(project_id, session_id):
|
||||
|
|
@ -15,10 +14,14 @@ def __get_mob_keys(project_id, session_id):
|
|||
]
|
||||
|
||||
|
||||
def __get_mob_keys_deprecated(session_id):
|
||||
return [str(session_id), str(session_id) + "e"]
|
||||
|
||||
|
||||
def get_urls(project_id, session_id):
|
||||
results = []
|
||||
for k in __get_mob_keys(project_id=project_id, session_id=session_id):
|
||||
results.append(client.generate_presigned_url(
|
||||
results.append(s3.client.generate_presigned_url(
|
||||
'get_object',
|
||||
Params={'Bucket': config("sessions_bucket"), 'Key': k},
|
||||
ExpiresIn=config("PRESIGNED_URL_EXPIRATION", cast=int, default=900)
|
||||
|
|
@ -27,27 +30,18 @@ def get_urls(project_id, session_id):
|
|||
|
||||
|
||||
def get_urls_depercated(session_id):
|
||||
return [
|
||||
client.generate_presigned_url(
|
||||
results = []
|
||||
for k in __get_mob_keys_deprecated(session_id=session_id):
|
||||
results.append(s3.client.generate_presigned_url(
|
||||
'get_object',
|
||||
Params={
|
||||
'Bucket': config("sessions_bucket"),
|
||||
'Key': str(session_id)
|
||||
},
|
||||
Params={'Bucket': config("sessions_bucket"), 'Key': k},
|
||||
ExpiresIn=100000
|
||||
),
|
||||
client.generate_presigned_url(
|
||||
'get_object',
|
||||
Params={
|
||||
'Bucket': config("sessions_bucket"),
|
||||
'Key': str(session_id) + "e"
|
||||
},
|
||||
ExpiresIn=100000
|
||||
)]
|
||||
))
|
||||
return results
|
||||
|
||||
|
||||
def get_ios(session_id):
|
||||
return client.generate_presigned_url(
|
||||
return s3.client.generate_presigned_url(
|
||||
'get_object',
|
||||
Params={
|
||||
'Bucket': config("ios_bucket"),
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ def format_payload(p, truncate_to_first=False):
|
|||
def url_exists(url):
|
||||
try:
|
||||
r = requests.head(url, allow_redirects=False)
|
||||
return r.status_code == 200 and r.headers.get("Content-Type") != "text/html"
|
||||
return r.status_code == 200 and "text/html" not in r.headers.get("Content-Type", "")
|
||||
except Exception as e:
|
||||
print(f"!! Issue checking if URL exists: {url}")
|
||||
print(e)
|
||||
|
|
|
|||
|
|
@ -204,7 +204,8 @@ def process():
|
|||
logging.info(f"Valid alert, notifying users, alertId:{alert['alertId']} name: {alert['name']}")
|
||||
notifications.append(generate_notification(alert, result))
|
||||
except Exception as e:
|
||||
logging.error(f"!!!Error while running alert query for alertId:{alert['alertId']} name: {alert['name']}")
|
||||
logging.error(
|
||||
f"!!!Error while running alert query for alertId:{alert['alertId']} name: {alert['name']}")
|
||||
logging.error(query)
|
||||
logging.error(e)
|
||||
cur = cur.recreate(rollback=True)
|
||||
|
|
@ -217,12 +218,22 @@ def process():
|
|||
alerts.process_notifications(notifications)
|
||||
|
||||
|
||||
def __format_value(x):
|
||||
if x % 1 == 0:
|
||||
x = int(x)
|
||||
else:
|
||||
x = round(x, 2)
|
||||
return f"{x:,}"
|
||||
|
||||
|
||||
def generate_notification(alert, result):
|
||||
left = __format_value(result['value'])
|
||||
right = __format_value(alert['query']['right'])
|
||||
return {
|
||||
"alertId": alert["alertId"],
|
||||
"tenantId": alert["tenantId"],
|
||||
"title": alert["name"],
|
||||
"description": f"has been triggered, {alert['query']['left']} = {round(result['value'], 2)} ({alert['query']['operator']} {alert['query']['right']}).",
|
||||
"description": f"has been triggered, {alert['query']['left']} = {left} ({alert['query']['operator']} {right}).",
|
||||
"buttonText": "Check metrics for more details",
|
||||
"buttonUrl": f"/{alert['projectId']}/metrics",
|
||||
"imageUrl": None,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from fastapi.security import SecurityScopes
|
|||
|
||||
import schemas_ee
|
||||
from chalicelib.core import permissions
|
||||
from chalicelib.utils.s3 import client
|
||||
from chalicelib.utils import s3
|
||||
|
||||
SCOPES = SecurityScopes([schemas_ee.Permissions.dev_tools])
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ def get_urls(session_id, project_id, context: schemas_ee.CurrentContext):
|
|||
return []
|
||||
results = []
|
||||
for k in __get_devtools_keys(project_id=project_id, session_id=session_id):
|
||||
results.append(client.generate_presigned_url(
|
||||
results.append(s3.client.generate_presigned_url(
|
||||
'get_object',
|
||||
Params={'Bucket': config("sessions_bucket"), 'Key': k},
|
||||
ExpiresIn=config("PRESIGNED_URL_EXPIRATION", cast=int, default=900)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from decouple import config
|
||||
|
||||
import schemas_ee
|
||||
from chalicelib.core import sessions, sessions_favorite_exp
|
||||
from chalicelib.core import sessions, sessions_favorite_exp, sessions_mobs, sessions_devtool
|
||||
from chalicelib.utils import pg_client, s3_extra
|
||||
|
||||
|
||||
|
|
@ -34,32 +34,31 @@ def remove_favorite_session(context: schemas_ee.CurrentContext, project_id, sess
|
|||
|
||||
|
||||
def favorite_session(context: schemas_ee.CurrentContext, project_id, session_id):
|
||||
keys = sessions_mobs.__get_mob_keys(project_id=project_id, session_id=session_id)
|
||||
keys += sessions_mobs.__get_mob_keys_deprecated(session_id=session_id) # To support old sessions
|
||||
keys += sessions_devtool.__get_devtools_keys(project_id=project_id, session_id=session_id)
|
||||
|
||||
if favorite_session_exists(user_id=context.user_id, session_id=session_id):
|
||||
key = str(session_id)
|
||||
try:
|
||||
s3_extra.tag_file(session_id=key, tag_value=config('RETENTION_D_VALUE', default='default'))
|
||||
except Exception as e:
|
||||
print(f"!!!Error while tagging: {key} to default")
|
||||
print(str(e))
|
||||
key = str(session_id) + "e"
|
||||
try:
|
||||
s3_extra.tag_file(session_id=key, tag_value=config('RETENTION_D_VALUE', default='default'))
|
||||
except Exception as e:
|
||||
print(f"!!!Error while tagging: {key} to default")
|
||||
print(str(e))
|
||||
tag = config('RETENTION_D_VALUE', default='default')
|
||||
|
||||
for k in keys:
|
||||
try:
|
||||
s3_extra.tag_session(file_key=k, tag_value=tag)
|
||||
except Exception as e:
|
||||
print(f"!!!Error while tagging: {k} to {tag} for removal")
|
||||
print(str(e))
|
||||
|
||||
return remove_favorite_session(context=context, project_id=project_id, session_id=session_id)
|
||||
key = str(session_id)
|
||||
try:
|
||||
s3_extra.tag_file(session_id=key, tag_value=config('RETENTION_L_VALUE', default='vault'))
|
||||
except Exception as e:
|
||||
print(f"!!!Error while tagging: {key} to vault")
|
||||
print(str(e))
|
||||
key = str(session_id) + "e"
|
||||
try:
|
||||
s3_extra.tag_file(session_id=key, tag_value=config('RETENTION_L_VALUE', default='vault'))
|
||||
except Exception as e:
|
||||
print(f"!!!Error while tagging: {key} to vault")
|
||||
print(str(e))
|
||||
|
||||
tag = config('RETENTION_L_VALUE', default='vault')
|
||||
|
||||
for k in keys:
|
||||
try:
|
||||
s3_extra.tag_session(file_key=k, tag_value=tag)
|
||||
except Exception as e:
|
||||
print(f"!!!Error while tagging: {k} to {tag} for vault")
|
||||
print(str(e))
|
||||
|
||||
return add_favorite_session(context=context, project_id=project_id, session_id=session_id)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,16 @@
|
|||
from decouple import config
|
||||
|
||||
from chalicelib.utils.s3 import client
|
||||
from chalicelib.utils import s3
|
||||
|
||||
|
||||
def tag_file(session_id, tag_key='retention', tag_value='vault'):
|
||||
return client.put_object_tagging(
|
||||
Bucket=config("sessions_bucket"),
|
||||
Key=session_id,
|
||||
def tag_session(file_key, tag_key='retention', tag_value='vault'):
|
||||
return tag_file(file_key=file_key, bucket=config("sessions_bucket"), tag_key=tag_key, tag_value=tag_value)
|
||||
|
||||
|
||||
def tag_file(file_key, bucket, tag_key, tag_value):
|
||||
return s3.client.put_object_tagging(
|
||||
Bucket=bucket,
|
||||
Key=file_key,
|
||||
Tagging={
|
||||
'TagSet': [
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue