feat(db): added edited_at to metrics

feat(db): defined all template metrics
feat(db): support delta multi-execution
feat(api): get edited_at with metric data
feat(api): get owner_email with metric data
feat(api): support of metrics areaChart
This commit is contained in:
Taha Yassine Kraiem 2022-04-05 11:28:47 +02:00
parent 5f006a312b
commit ef4c9a5bf5
4 changed files with 53 additions and 51 deletions

View file

@ -194,7 +194,8 @@ def update(metric_id, user_id, project_id, data: schemas.UpdateCustomMetricsSche
SET name = %(name)s, is_public= %(is_public)s,
view_type= %(view_type)s, metric_type= %(metric_type)s,
metric_of= %(metric_of)s, metric_value= %(metric_value)s,
metric_format= %(metric_format)s
metric_format= %(metric_format)s,
edited_at = timezone('utc'::text, now())
WHERE metric_id = %(metric_id)s
AND project_id = %(project_id)s
AND (user_id = %(user_id)s OR is_public)
@ -224,6 +225,11 @@ def get_all(project_id, user_id, include_series=False):
AND project_id = %(project_id)s
AND ((user_id = %(user_id)s OR is_public))) AS connected_dashboards
) AS connected_dashboards ON (TRUE)
LEFT JOIN LATERAL (SELECT email AS owner_email
FROM users
WHERE deleted_at ISNULL
AND users.user_id = metrics.user_id
) AS owner ON (TRUE)
WHERE metrics.project_id = %(project_id)s
AND metrics.deleted_at ISNULL
AND (user_id = %(user_id)s OR metrics.is_public)
@ -246,7 +252,7 @@ def delete(project_id, metric_id, user_id):
cur.execute(
cur.mogrify("""\
UPDATE public.metrics
SET deleted_at = timezone('utc'::text, now())
SET deleted_at = timezone('utc'::text, now()), edited_at = timezone('utc'::text, now())
WHERE project_id = %(project_id)s
AND metric_id = %(metric_id)s
AND (user_id = %(user_id)s OR is_public);""",
@ -274,6 +280,11 @@ def get(metric_id, project_id, user_id, flatten=True):
AND project_id = %(project_id)s
AND ((user_id = %(user_id)s OR is_public))) AS connected_dashboards
) AS connected_dashboards ON (TRUE)
LEFT JOIN LATERAL (SELECT email AS owner_email
FROM users
WHERE deleted_at ISNULL
AND users.user_id = metrics.user_id
) AS owner ON (TRUE)
WHERE metrics.project_id = %(project_id)s
AND metrics.deleted_at ISNULL
AND (metrics.user_id = %(user_id)s OR metrics.is_public)

View file

@ -776,6 +776,7 @@ class CustomMetricCreateSeriesSchema(BaseModel):
class MetricTimeseriesViewType(str, Enum):
line_chart = "lineChart"
progress = "progress"
area_chart = "areaChart"
class MetricTableViewType(str, Enum):

View file

@ -18,50 +18,23 @@ CREATE TABLE IF NOT EXISTS dashboards
deleted_at timestamp NULL DEFAULT NULL
);
-- CREATE TABLE templates
-- (
-- template_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY,
-- template_key text,
-- name text NOT NULL,
-- category text NOT NULL,
-- series jsonb NOT NULL,
-- config jsonb NOT NULL,
-- predefined boolean DEFAULT TRUE
-- );
-- CREATE TABLE dashboard_widgets
-- (
-- widget_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY,
-- dashboard_id integer NOT NULL REFERENCES dashboards (dashboard_id) ON DELETE CASCADE,
-- metric_id integer NOT NULL REFERENCES metrics (metric_id) ON DELETE CASCADE,
-- -- template_id integer NOT NULL REFERENCES templates (template_id) ON DELETE CASCADE,
-- user_id integer NOT NULL REFERENCES users (user_id) ON DELETE SET NULL,
-- created_at timestamp NOT NULL DEFAULT timezone('utc'::text, now()),
-- configuration jsonb NOT NULL DEFAULT '{}'::jsonb,
-- name text
-- );
-- INSERT INTO public.templates (name, category, series, config, predefined, template_key)
-- VALUES ('captured sessions', 'overview', '[]', '{}', true, 'count_sessions'),
-- ('request load time', 'overview', '[]', '{}', true, 'avg_request_load_time'),
-- ('page load time', 'overview', '[]', '{}', true, 'avg_page_load_time'),
-- ('image load time', 'overview', '[]', '{}', true, 'avg_image_load_time');
ALTER TYPE metric_view_type ADD VALUE IF NOT EXISTS 'areaChart';
ALTER TABLE IF EXISTS metrics
DROP CONSTRAINT IF EXISTS null_project_id_for_template_only;
DROP CONSTRAINT IF EXISTS null_project_id_for_template_only,
DROP CONSTRAINT IF EXISTS unique_key;
ALTER TABLE IF EXISTS metrics
ADD COLUMN IF NOT EXISTS is_pinned boolean NOT NULL DEFAULT FALSE,
ADD COLUMN IF NOT EXISTS category text NULL DEFAULT 'custom',
ADD COLUMN IF NOT EXISTS is_predefined boolean NOT NULL DEFAULT FALSE,
ADD COLUMN IF NOT EXISTS is_template boolean NOT NULL DEFAULT FALSE,
ADD COLUMN IF NOT EXISTS key text NULL DEFAULT NULL,
ADD COLUMN IF NOT EXISTS config jsonb NOT NULL DEFAULT '{}'::jsonb,
ADD COLUMN IF NOT EXISTS edited_at timestamp NULL DEFAULT NULL,
ADD COLUMN IF NOT EXISTS is_pinned boolean NOT NULL DEFAULT FALSE,
ADD COLUMN IF NOT EXISTS category text NULL DEFAULT 'custom',
ADD COLUMN IF NOT EXISTS is_predefined boolean NOT NULL DEFAULT FALSE,
ADD COLUMN IF NOT EXISTS is_template boolean NOT NULL DEFAULT FALSE,
ADD COLUMN IF NOT EXISTS key text NULL DEFAULT NULL,
ADD COLUMN IF NOT EXISTS config jsonb NOT NULL DEFAULT '{}'::jsonb,
ALTER COLUMN project_id DROP NOT NULL,
ADD CONSTRAINT null_project_id_for_template_only
CHECK ( (metrics.category != 'custom') != (metrics.project_id IS NOT NULL) );
CHECK ( (metrics.category != 'custom') != (metrics.project_id IS NOT NULL) ),
ADD CONSTRAINT unique_key UNIQUE (key);
@ -76,17 +49,33 @@ CREATE TABLE IF NOT EXISTS dashboard_widgets
name text
);
-- INSERT INTO public.templates (name, category, series, config, predefined, template_key)
-- VALUES ('captured sessions', 'overview', '[]', '{}', true, 'count_sessions'),
-- ('request load time', 'overview', '[]', '{}', true, 'avg_request_load_time'),
-- ('page load time', 'overview', '[]', '{}', true, 'avg_page_load_time'),
-- ('image load time', 'overview', '[]', '{}', true, 'avg_image_load_time');
INSERT INTO metrics (name, category, config, is_predefined, is_template, is_public, key)
VALUES ('captured sessions', 'overview', '{}', true, true, true, 'count_sessions'),
('request load time', 'overview', '{}', true, true, true, 'avg_request_load_time'),
('page load time', 'overview', '{}', true, true, true, 'avg_page_load_time'),
('image load time', 'overview', '{}', true, true, true, 'avg_image_load_time');
VALUES ('sessions count', 'overview', '{}', true, true, true, 'count_sessions'),
('avg request load time', 'overview', '{}', true, true, true, 'avg_request_load_time'),
('avg page load time', 'overview', '{}', true, true, true, 'avg_page_load_time'),
('avg image load time', 'overview', '{}', true, true, true, 'avg_image_load_time'),
('avg dom content load start', 'overview', '{}', true, true, true, 'avg_dom_content_load_start'),
('avg first contentful pixel', 'overview', '{}', true, true, true, 'avg_first_contentful_pixel'),
('avg visited pages count', 'overview', '{}', true, true, true, 'avg_visited_pages'),
('avg session duration', 'overview', '{}', true, true, true, 'avg_session_duration'),
('avg pages dom buildtime', 'overview', '{}', true, true, true, 'avg_pages_dom_buildtime'),
('avg pages response time', 'overview', '{}', true, true, true, 'avg_pages_response_time'),
('avg response time', 'overview', '{}', true, true, true, 'avg_response_time'),
('avg first paint', 'overview', '{}', true, true, true, 'avg_first_paint'),
('avg dom content loaded', 'overview', '{}', true, true, true, 'avg_dom_content_loaded'),
('avg time till first bit', 'overview', '{}', true, true, true, 'avg_till_first_bit'),
('avg time to interactive', 'overview', '{}', true, true, true, 'avg_time_to_interactive'),
('requests count', 'overview', '{}', true, true, true, 'count_requests'),
('avg time to render', 'overview', '{}', true, true, true, 'avg_time_to_render'),
('avg used js heap size', 'overview', '{}', true, true, true, 'avg_used_js_heap_size'),
('avg cpu', 'overview', '{}', true, true, true, 'avg_cpu')
ON CONFLICT (key) DO UPDATE SET name=excluded.name,
category=excluded.category,
config=excluded.config,
is_predefined=excluded.is_predefined,
is_template=excluded.is_template,
is_public=excluded.is_public;
COMMIT
COMMIT;
ALTER TYPE metric_view_type ADD VALUE IF NOT EXISTS 'areaChart';

View file

@ -947,6 +947,7 @@ $$
active boolean NOT NULL DEFAULT TRUE,
created_at timestamp default timezone('utc'::text, now()) not null,
deleted_at timestamp,
edited_at timestamp,
metric_type metric_type NOT NULL DEFAULT 'timeseries',
view_type metric_view_type NOT NULL DEFAULT 'lineChart',
metric_of text NOT NULL DEFAULT 'sessionCount',