Skip to content

feat(coderd): add coder_app usage stats #9001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Aug 16, 2023

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented Aug 9, 2023

Updates #8658

@mafredri

This comment was marked as outdated.

@mafredri mafredri force-pushed the mafredri/feat-add-app-usage-to-template-insights branch from 9bf63a4 to befb4dc Compare August 9, 2023 15:19
@mtojek mtojek self-requested a review August 10, 2023 08:10
@mafredri
Copy link
Member Author

mafredri commented Aug 10, 2023

I've refactored the stats collection to perform rollups on short-lived requests and added full test coverage for the StatsCollector.

Default rollup window is 1 minute, we can extend it if we want to reduce rows further, but I don't think it'll be necessary.

What's left is:

  • Add tests for coderd and wsproxy to ensure app usage produces stats (?)
  • Fix TODO about wsproxy auth
  • Check correctness of dbauthz implementation

For now, the data looks like this:

SELECT *, session_ended_at - session_started_at AS session_length FROM workspace_app_stats ORDER BY session_started_at;
id user_id workspace_id agent_id access_method slug_or_port session_id session_started_at session_ended_at requests session_length
24 5419d403-d7a1-4000-a9b1-3bab3c9c8993 6c7b8c1c-aeaa-4409-9448-2f46390938b6 1dacd2af-0b50-4fd4-bd99-7443e1fe06e7 path code-server e250b40e-537e-4d89-a45c-852f3f0ce018 2023-08-10 22:03:00+00 2023-08-10 22:04:00+00 9 00:01:00
25 5419d403-d7a1-4000-a9b1-3bab3c9c8993 6c7b8c1c-aeaa-4409-9448-2f46390938b6 1dacd2af-0b50-4fd4-bd99-7443e1fe06e7 path code-server 16c08a01-6827-45ac-959b-fcd72b05c4bd 2023-08-10 22:04:00+00 2023-08-10 22:05:00+00 20 00:01:00
31 5419d403-d7a1-4000-a9b1-3bab3c9c8993 6c7b8c1c-aeaa-4409-9448-2f46390938b6 1dacd2af-0b50-4fd4-bd99-7443e1fe06e7 path code-server fe340b03-46b6-48f8-87e6-64b5baf708b9 2023-08-10 22:04:09.204568+00 2023-08-10 22:16:20.918296+00 1 00:12:11.713728
32 5419d403-d7a1-4000-a9b1-3bab3c9c8993 6c7b8c1c-aeaa-4409-9448-2f46390938b6 1dacd2af-0b50-4fd4-bd99-7443e1fe06e7 path code-server 291de74a-4aee-4ee1-b02a-d8cceddd56ef 2023-08-10 22:04:10.452269+00 2023-08-10 22:16:20.921671+00 1 00:12:10.469402
30 5419d403-d7a1-4000-a9b1-3bab3c9c8993 6c7b8c1c-aeaa-4409-9448-2f46390938b6 1dacd2af-0b50-4fd4-bd99-7443e1fe06e7 terminal 4f9c687b-f732-4c91-92ac-2cc459e6a7b2 2023-08-10 22:05:00+00 2023-08-10 22:06:00+00 2 00:01:00
38 5419d403-d7a1-4000-a9b1-3bab3c9c8993 6c7b8c1c-aeaa-4409-9448-2f46390938b6 1dacd2af-0b50-4fd4-bd99-7443e1fe06e7 terminal bd7d51df-eb75-4642-9033-3102e8ea0665 2023-08-10 22:05:15.74551+00 2023-08-10 22:07:42.616165+00 1 00:02:26.870655
39 5419d403-d7a1-4000-a9b1-3bab3c9c8993 6c7b8c1c-aeaa-4409-9448-2f46390938b6 1dacd2af-0b50-4fd4-bd99-7443e1fe06e7 terminal 23e21c72-28de-4f12-90e7-7a23709599dd 2023-08-10 22:05:23.250785+00 2023-08-10 22:07:46.848367+00 1 00:02:23.597582
40 5419d403-d7a1-4000-a9b1-3bab3c9c8993 6c7b8c1c-aeaa-4409-9448-2f46390938b6 1dacd2af-0b50-4fd4-bd99-7443e1fe06e7 terminal 32d92f3-07d8-4ed0-9373-d741e70cba4a 2023-08-10 22:05:26.718312+00 2023-08-10 22:07:44.201889+00 1 00:02:17.483577
41 5419d403-d7a1-4000-a9b1-3bab3c9c8993 6c7b8c1c-aeaa-4409-9448-2f46390938b6 1dacd2af-0b50-4fd4-bd99-7443e1fe06e7 terminal 07d531c3-1d9b-4eac-b152-2b88e2c7302a 2023-08-10 22:05:26.733824+00 2023-08-10 22:07:46.044149+00 1 00:02:19.310325
73 5419d403-d7a1-4000-a9b1-3bab3c9c8993 6c7b8c1c-aeaa-4409-9448-2f46390938b6 1dacd2af-0b50-4fd4-bd99-7443e1fe06e7 path code-server 3d47059c-50d3-4afd-8976-69e836082bf0 2023-08-10 22:08:00+00 2023-08-10 22:09:00+00 40 00:01:00

@mafredri mafredri marked this pull request as ready for review August 14, 2023 12:53
@mafredri mafredri force-pushed the mafredri/feat-add-app-usage-to-template-insights branch from e903d16 to 1705138 Compare August 14, 2023 14:02
@mafredri mafredri force-pushed the mafredri/feat-add-app-usage-to-template-insights branch from b17b944 to 6ec178b Compare August 14, 2023 14:43
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note before merging: double-check for a duplicate migration!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's any newer migration on main? But yea, I will merge in main and fix if needed before merge. 👍🏻

@mafredri mafredri force-pushed the mafredri/feat-add-app-usage-to-template-insights branch from a23297b to c9272c5 Compare August 16, 2023 11:57
@mafredri mafredri changed the title feat(coderd): track coder_app usage feat(coderd): add coder_app usage stats Aug 16, 2023
@mafredri mafredri merged commit 6fd9975 into main Aug 16, 2023
@mafredri mafredri deleted the mafredri/feat-add-app-usage-to-template-insights branch August 16, 2023 12:22
@github-actions github-actions bot locked and limited conversation to collaborators Aug 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants