Skip to content
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

Save tracking info for rooms #1699

Merged
merged 3 commits into from
Apr 26, 2023
Merged

Save tracking info for rooms #1699

merged 3 commits into from
Apr 26, 2023

Conversation

mjh1
Copy link
Contributor

@mjh1 mjh1 commented Apr 24, 2023

What does this pull request do? Explain your changes. (required)

I've created a database table to be able to keep track of rooms. I've implemented a webhook receiver so that we can store information like which participants have joined and what tracks they have published.

Specific updates (required)

How did you test each of these updates (required)

  • Modified existing unit test to cover new functionality.
  • Tested webhooks locally to observe the expected updated info in the room table.

Does this pull request close any open issues?

Screenshots (optional)

Checklist

  • I have read the CONTRIBUTING document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@mjh1 mjh1 requested a review from a team as a code owner April 24, 2023 18:29
@vercel
Copy link

vercel bot commented Apr 24, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
livepeer-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 26, 2023 2:26pm

@mjh1 mjh1 requested a review from victorges April 24, 2023 18:29
@codecov
Copy link

codecov bot commented Apr 24, 2023

Codecov Report

Merging #1699 (5ba89c8) into master (7341a28) will decrease coverage by 0.25826%.
The diff coverage is 31.66667%.

Impacted file tree graph

@@                 Coverage Diff                 @@
##              master       #1699         +/-   ##
===================================================
- Coverage   53.02876%   52.77050%   -0.25826%     
===================================================
  Files             74          75          +1     
  Lines           4903        4963         +60     
  Branches         976         987         +11     
===================================================
+ Hits            2600        2619         +19     
- Misses          1970        2007         +37     
- Partials         333         337          +4     
Impacted Files Coverage Δ
packages/api/src/parse-cli.ts 34.04255% <ø> (ø)
packages/api/src/store/table.ts 71.68675% <ø> (ø)
packages/api/src/controllers/room.ts 29.31034% <29.31034%> (ø)
packages/api/src/store/db.ts 82.60870% <100.00000%> (+0.19112%) ⬆️
packages/api/src/test-server.ts 93.18182% <100.00000%> (+0.15856%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cbdbc0d...5ba89c8. Read the comment docs.

Impacted Files Coverage Δ
packages/api/src/parse-cli.ts 34.04255% <ø> (ø)
packages/api/src/store/table.ts 71.68675% <ø> (ø)
packages/api/src/controllers/room.ts 29.31034% <29.31034%> (ø)
packages/api/src/store/db.ts 82.60870% <100.00000%> (+0.19112%) ⬆️
packages/api/src/test-server.ts 93.18182% <100.00000%> (+0.15856%) ⬆️

@mjh1 mjh1 requested a review from gioelecerati April 25, 2023 09:09
Copy link
Member

@victorges victorges left a comment

Choose a reason for hiding this comment

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

LGTM

const room = await svc.createRoom(opts);
emptyTimeout: 15 * 60,
maxParticipants: 10,
metadata: `{"userId": "${req.user.id}"}`,
Copy link
Member

Choose a reason for hiding this comment

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

Nice to have the metadata! As a nit, you could write a syntax-safe JSON here as well:

Suggested change
metadata: `{"userId": "${req.user.id}"}`,
metadata: JSON.stringify({userId: req.user.id}),

Comment on lines 69 to 70
app.use("/webhook", express.raw({ type: "*/*" }));
app.post("/webhook", async (req, res) => {
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think this would have the same effect (unless you want the middleware on other methods not only POST)

Suggested change
app.use("/webhook", express.raw({ type: "*/*" }));
app.post("/webhook", async (req, res) => {
app.post("/webhook", express.raw({ type: "*/*" }), async (req, res) => {

req.config.livekitApiKey,
req.config.livekitSecret
);
console.log("livekit webhook auth", req.get("Authorization"));
Copy link
Member

Choose a reason for hiding this comment

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

Should probably remove/comment this log before deploy

);
const participants = await svc.listParticipants(roomId);

room = await db.room.get(roomId);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe double check this room exists and return a 4xx error if it doesn't (or anything that LiveKit won't retry)

description: Success
content:
application/json:
$ref: "#/components/schemas/create-room-response"
Copy link
Member

Choose a reason for hiding this comment

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

If it's only for $refing it here, I'd say we can just inline it (and remove the top-level component)

Suggested change
$ref: "#/components/schemas/create-room-response"
additionalProperties: false
properties:
id:
type: string

Comment on lines 2591 to 2592
unique: true
index: true
Copy link
Member

Choose a reason for hiding this comment

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

Actually the id field is the only exception! We don't need any index here.

Suggested change
unique: true
index: true

In the database, we have a separate column for the ID which is also the table primary key, and when querying by it we always check that table instead of the id in the JSON column. The index here would be redundant/unused.

type: string
readOnly: true
example: 66E2161C-7670-4D05-B71D-DA2D6979556F
index: true
Copy link
Member

Choose a reason for hiding this comment

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

You need to add room to this list here: https://github.com/livepeer/livepeer-com/blob/a326c2f31bfd7638390ba703bcf7f1ca6a7cad1e/packages/api/src/store/table.ts#L352

Otherwise the indexes won't really be created. This is a tech debt we've been carrying since the time we had some issues with indexes on the stream table which is huge and gets a lot of updates.

id:
type: string

room:
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind adding documentation (description) to the user-facing fields in this object?

Comment on lines +61 to +63
for (const key in room.participants) {
room.participants[key].tracksPublished = undefined;
}
Copy link
Member

Choose a reason for hiding this comment

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

Maybe consider hiding the entire participants field. Do users really need access to all that information? Might be easier to start by using it only internally for tracking/billing and consider exposing only parts of it that users may need.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it will be helpful to give them at least the IDs and names of the participants so that they would easily be able to see who has joined and remove people if needed (api coming in next PR). I will tidy up the remaining fields too in the next PR.

break;
case "room_started":
case "room_finished":
room = await db.room.get(event.room.name);
Copy link
Member

Choose a reason for hiding this comment

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

Same for checking if the room exists. Maybe we want this step outside the switch?

packages/api/src/controllers/room.ts Dismissed Show dismissed Hide dismissed
@mjh1 mjh1 merged commit cc7102b into master Apr 26, 2023
18 checks passed
@mjh1 mjh1 deleted the mh/livekit-track branch April 26, 2023 16:03
suhailkakar pushed a commit that referenced this pull request May 4, 2023
* Save tracking info for rooms

* add response schemas

* review comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants