feat: Add anonymized telemetry to report product usage (#2273)

* feat: Add anonymized telemetry to report product usage

This adds a background service to report telemetry to a Coder
server for usage data. There will be realtime event data sent
in the future, but for now usage will report on a CRON.

* Fix flake and requested changes

* Add reporting options for setup

* Add reporting for workspaces

* Add resources as they are reported

* Track API key usage

* Ensure telemetry is tracked prior to exit
This commit is contained in:
Kyle Carberry
2022-06-17 00:26:40 -05:00
committed by GitHub
parent af8a1e3fea
commit 4cce969018
33 changed files with 1674 additions and 95 deletions
+3
View File
@@ -8,6 +8,9 @@ WHERE
LIMIT
1;
-- name: GetAPIKeysLastUsedAfter :many
SELECT * FROM api_keys WHERE last_used > $1;
-- name: InsertAPIKey :one
INSERT INTO
api_keys (
@@ -6,6 +6,9 @@ FROM
WHERE
job_id = $1;
-- name: GetParameterSchemasCreatedAfter :many
SELECT * FROM parameter_schemas WHERE created_at > $1;
-- name: InsertParameterSchema :one
INSERT INTO
parameter_schemas (
@@ -46,6 +46,9 @@ FROM
WHERE
id = ANY(@ids :: uuid [ ]);
-- name: GetProvisionerJobsCreatedAfter :many
SELECT * FROM provisioner_jobs WHERE created_at > $1;
-- name: InsertProvisionerJob :one
INSERT INTO
provisioner_jobs (
+5
View File
@@ -0,0 +1,5 @@
-- name: InsertDeploymentID :exec
INSERT INTO site_configs (key, value) VALUES ('deployment_id', $1);
-- name: GetDeploymentID :one
SELECT value FROM site_configs WHERE key = 'deployment_id';
+3
View File
@@ -48,6 +48,9 @@ WHERE
LIMIT
1;
-- name: GetTemplates :many
SELECT * FROM templates;
-- name: InsertTemplate :one
INSERT INTO
templates (
@@ -40,6 +40,9 @@ FROM
WHERE
job_id = $1;
-- name: GetTemplateVersionsCreatedAfter :many
SELECT * FROM template_versions WHERE created_at > $1;
-- name: GetTemplateVersionByTemplateIDAndName :one
SELECT
*
@@ -34,6 +34,9 @@ FROM
WHERE
resource_id = ANY(@ids :: uuid [ ]);
-- name: GetWorkspaceAgentsCreatedAfter :many
SELECT * FROM workspace_agents WHERE created_at > $1;
-- name: InsertWorkspaceAgent :one
INSERT INTO
workspace_agents (
@@ -7,6 +7,9 @@ SELECT * FROM workspace_apps WHERE agent_id = ANY(@ids :: uuid [ ]);
-- name: GetWorkspaceAppByAgentIDAndName :one
SELECT * FROM workspace_apps WHERE agent_id = $1 AND name = $2;
-- name: GetWorkspaceAppsCreatedAfter :many
SELECT * FROM workspace_apps WHERE created_at > $1;
-- name: InsertWorkspaceApp :one
INSERT INTO
workspace_apps (
@@ -18,6 +18,9 @@ WHERE
LIMIT
1;
-- name: GetWorkspaceBuildsCreatedAfter :many
SELECT * FROM workspace_builds WHERE created_at > $1;
-- name: GetWorkspaceBuildByWorkspaceIDAndName :one
SELECT
*
@@ -14,6 +14,9 @@ FROM
WHERE
job_id = $1;
-- name: GetWorkspaceResourcesCreatedAfter :many
SELECT * FROM workspace_resources WHERE created_at > $1;
-- name: InsertWorkspaceResource :one
INSERT INTO
workspace_resources (id, created_at, job_id, transition, type, name)
+1 -1
View File
@@ -8,7 +8,7 @@ WHERE
LIMIT
1;
-- name: GetWorkspacesWithFilter :many
-- name: GetWorkspaces :many
SELECT
*
FROM