1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-28 19:06:12 +01:00

feat: create the project-metrics-summary-trends table (#6313)

Adds a migration to create and fill the `project_metrics_summary_trends`

This table is to be used in enterprise to update the metrics data daily
per project (after the aggregation of the hourly data)

Driving force for this was doing performance testing on the executive
dashboard.
This will allow to remove the expensive query to aggregate the data on
demand and will drop the total response time from 2.5sec to 125ms
(measurements done with 100 Projects, 10000 features and over 1M rows in
`client_metrics_env_daily`

Closes #
[1-2080](https://linear.app/unleash/issue/1-2080/create-the-project-metrics-summary-trends-table)

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
andreas-unleash 2024-02-22 17:21:08 +02:00 committed by GitHub
parent 7cc968fdc4
commit 7a08a121f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,42 @@
exports.up = function (db, cb) {
db.runSql(
`
CREATE TABLE IF NOT EXISTS project_client_metrics_trends
(
project varchar NOT NULL references projects(id) ON DELETE CASCADE,
date date NOT NULL,
total_yes integer NOT NULL,
total_no integer NOT NULL,
total_apps integer NOT NULL,
total_flags integer NOT NULL,
total_environments integer NOT NULL,
PRIMARY KEY (project, date)
);
INSERT INTO project_client_metrics_trends (project, date, total_yes, total_no, total_apps, total_flags, total_environments)
SELECT
f.project,
cmed.date,
SUM(cmed.yes) AS total_yes,
SUM(cmed.no) AS total_no,
COUNT(DISTINCT cmed.app_name) AS total_apps,
COUNT(DISTINCT cmed.feature_name) AS total_flags,
COUNT(DISTINCT cmed.environment) AS total_environments
FROM
client_metrics_env_daily cmed
JOIN features f on f.name = cmed.feature_name
GROUP BY
f.project, cmed.date
`,
cb,
);
};
exports.down = function (db, cb) {
db.runSql(
`
DROP TABLE IF EXISTS project_client_metrics_trends
`,
cb,
);
};