* refactor(chalice): upgraded dependencies

* refactor(chalice): upgraded dependencies
feat(chalice): support heatmaps

* fix(chalice): fixed Math-operators validation
refactor(chalice): search for sessions that have events for heatmaps

* refactor(chalice): search for sessions that have at least 1 location event for heatmaps

* refactor(chalice): upgraded dependencies

* refactor(chalice): upgraded dependencies
feat(chalice): support heatmaps

* fix(chalice): fixed Math-operators validation
refactor(chalice): search for sessions that have events for heatmaps

* refactor(chalice): search for sessions that have at least 1 location event for heatmaps

* refactor(chalice): upgraded dependencies
refactor(crons): upgraded dependencies
refactor(alerts): upgraded dependencies

* feat(chalice): get top 10 values for autocomplete CH

* refactor(chalice): cleaned code
refactor(chalice): upgraded dependencies
refactor(alerts): upgraded dependencies
refactor(crons): upgraded dependencies

* feat(chalice): autocomplete return top 10 with stats

* fix(chalice): fixed autocomplete top 10 meta-filters

* refactor(DB): enhanced top-events caching

* feat(DB): support OR scope
feat(chalice): support OR scope
This commit is contained in:
Kraiem Taha Yassine 2024-08-08 17:15:51 +02:00 committed by GitHub
parent b618d47b38
commit 8c54a74f04
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 65 additions and 18 deletions

View file

@ -0,0 +1,27 @@
from cachetools import cached, TTLCache
import schemas
from chalicelib.utils import helper
from chalicelib.utils import pg_client
cache = TTLCache(maxsize=1, ttl=24 * 60 * 60)
@cached(cache)
def get_scope(tenant_id) -> schemas.ScopeType:
with pg_client.PostgresClient() as cur:
query = cur.mogrify(f"""SELECT scope
FROM public.tenants;""")
cur.execute(query)
return helper.dict_to_camel_case(cur.fetchone())["scope"]
def update_scope(tenant_id, scope: schemas.ScopeType):
with pg_client.PostgresClient() as cur:
query = cur.mogrify(f"""UPDATE public.tenants
SET scope = %(scope)s;""",
{"scope": scope})
cur.execute(query)
if tenant_id in cache:
cache.pop(tenant_id)
return scope

View file

@ -11,7 +11,8 @@ def get_by_tenant_id(tenant_id):
tenants.created_at,
'{license.EDITION}' AS edition,
openreplay_version() AS version_number,
tenants.opt_out
tenants.opt_out,
scope
FROM public.tenants
LIMIT 1;""",
{"tenantId": tenant_id})

View file

@ -879,8 +879,6 @@ def health_check():
return {}
# tags
@app.post('/{projectId}/tags', tags=["tags"])
def tags_create(projectId: int, data: schemas.TagCreate = Body(),
context: schemas.CurrentContext = Depends(OR_context)):

View file

@ -11,6 +11,7 @@ from chalicelib.core import sessions, errors, errors_viewed, errors_favorite, se
from chalicelib.core import sessions_viewed
from chalicelib.core import tenants, users, projects, license
from chalicelib.core import webhook
from chalicelib.core import scope
from chalicelib.core.collaboration_slack import Slack
from chalicelib.utils import captcha, smtp
from chalicelib.utils import helper
@ -72,7 +73,8 @@ def login_user(response: JSONResponse, spot: Optional[bool] = False, data: schem
content = {
'jwt': r.pop('jwt'),
'data': {
"user": r
"user": r,
"scope": scope.get_scope(-1)
}
}
response.set_cookie(key="refreshToken", value=refresh_token, path=COOKIE_PATH,
@ -131,6 +133,13 @@ def edit_account(data: schemas.EditAccountSchema = Body(...),
return users.edit_account(tenant_id=context.tenant_id, user_id=context.user_id, changes=data)
@app.post('/account/scope', tags=["account"])
def change_scope(data: schemas.ScopeSchema = Body(),
context: schemas.CurrentContext = Depends(OR_context)):
data = scope.update_scope(tenant_id=-1, scope=data.scope)
return {'data': data}
@app.post('/integrations/slack', tags=['integrations'])
@app.put('/integrations/slack', tags=['integrations'])
def add_slack_integration(data: schemas.AddCollaborationSchema,

View file

@ -1651,3 +1651,12 @@ class TagCreate(TagUpdate):
selector: str = Field(..., min_length=1, max_length=255)
ignoreClickRage: bool = Field(default=False)
ignoreDeadClick: bool = Field(default=False)
class ScopeType(str, Enum):
FULL_OR = "full"
SPOT_ONLY = "spot"
class ScopeSchema(BaseModel):
scope: ScopeType = Field(default=ScopeType.FULL_OR)

View file

@ -30,7 +30,8 @@ WHERE NOT permissions @> '{SPOT}'
UPDATE public.roles
SET permissions = (SELECT array_agg(distinct e) FROM unnest(permissions || '{SPOT_PUBLIC}') AS e)
WHERE NOT permissions @> '{SPOT_PUBLIC}'
AND name ILIKE 'owner';
AND NOT service_role;
-- AND name ILIKE 'owner';
ALTER TABLE IF EXISTS public.users
ADD COLUMN IF NOT EXISTS spot_jwt_iat timestamp without time zone NULL DEFAULT NULL,
@ -46,9 +47,12 @@ CREATE TABLE IF NOT EXISTS or_cache.autocomplete_top_values
result jsonb NULL,
execution_time integer NULL,
created_at timestamp DEFAULT timezone('utc'::text, now()) NOT NULL,
UNIQUE (project_id, event_type, event_key)
UNIQUE NULLS NOT DISTINCT (project_id, event_type, event_key)
);
ALTER TABLE IF EXISTS public.tenants
ADD COLUMN IF NOT EXISTS scope text NOT NULL DEFAULT 'full';
COMMIT;
\elif :is_next

View file

@ -103,7 +103,8 @@ CREATE TABLE public.tenants
t_sessions bigint NOT NULL DEFAULT 0,
t_users integer NOT NULL DEFAULT 1,
t_integrations integer NOT NULL DEFAULT 0,
last_telemetry bigint NOT NULL DEFAULT CAST(EXTRACT(epoch FROM date_trunc('day', now())) * 1000 AS BIGINT)
last_telemetry bigint NOT NULL DEFAULT CAST(EXTRACT(epoch FROM date_trunc('day', now())) * 1000 AS BIGINT),
scope text NOT NULL DEFAULT 'full'
);
@ -1313,9 +1314,7 @@ CREATE TABLE or_cache.autocomplete_top_values
result jsonb NULL,
execution_time integer NULL,
created_at timestamp DEFAULT timezone('utc'::text, now()) NOT NULL,
UNIQUE (project_id, event_type, event_key)
-- TODO: use `UNIQUE NULLS NOT DISTINCT (project_id, event_type, event_key)`
-- when PG upgrade is validated by devops team
UNIQUE NULLS NOT DISTINCT (project_id, event_type, event_key)
);
COMMIT;

View file

@ -97,7 +97,6 @@ env:
announcement_url: ''
jwt_secret: "SetARandomStringHere"
jwt_algorithm: HS512
jwt_exp_delta_seconds: '2592000'
# Enable logging for python app
# Ref: https://stackoverflow.com/questions/43969743/logs-in-kubernetes-pod-not-showing-up
PYTHONUNBUFFERED: '0'

View file

@ -95,7 +95,6 @@ chalice:
announcement_url: ''
jwt_secret: "SetARandomStringHere"
jwt_algorithm: HS512
jwt_exp_delta_seconds: '2592000'
# Enable logging for python app
# Ref: https://stackoverflow.com/questions/43969743/logs-in-kubernetes-pod-not-showing-up
PYTHONUNBUFFERED: '0'

View file

@ -36,9 +36,12 @@ CREATE TABLE IF NOT EXISTS or_cache.autocomplete_top_values
result jsonb NULL,
execution_time integer NULL,
created_at timestamp DEFAULT timezone('utc'::text, now()) NOT NULL,
UNIQUE (project_id, event_type, event_key)
UNIQUE NULLS NOT DISTINCT (project_id, event_type, event_key)
);
ALTER TABLE IF EXISTS public.tenants
ADD COLUMN IF NOT EXISTS scope text NOT NULL DEFAULT 'full';
COMMIT;
\elif :is_next

View file

@ -103,8 +103,9 @@ CREATE TABLE public.tenants
t_sessions bigint NOT NULL DEFAULT 0,
t_users integer NOT NULL DEFAULT 1,
t_integrations integer NOT NULL DEFAULT 0,
last_telemetry bigint NOT NULL DEFAULT CAST(EXTRACT(epoch FROM date_trunc('day', now())) * 1000 AS BIGINT)
CONSTRAINT onerow_uni CHECK (tenant_id = 1)
last_telemetry bigint NOT NULL DEFAULT CAST(EXTRACT(epoch FROM date_trunc('day', now())) * 1000 AS BIGINT),
scope text NOT NULL DEFAULT 'full',
CONSTRAINT onerow_uni CHECK (tenant_id = 1)
);
CREATE TYPE user_role AS ENUM ('owner', 'admin', 'member');
@ -1199,9 +1200,7 @@ CREATE TABLE or_cache.autocomplete_top_values
result jsonb NULL,
execution_time integer NULL,
created_at timestamp DEFAULT timezone('utc'::text, now()) NOT NULL,
UNIQUE (project_id, event_type, event_key)
-- TODO: use `UNIQUE NULLS NOT DISTINCT (project_id, event_type, event_key)`
-- when PG upgrade is validated by devops team
UNIQUE NULLS NOT DISTINCT (project_id, event_type, event_key)
);