feat: add analytics subcommand#784
Conversation
| func resolveAnalyticsProjectID() (string, error) { | ||
| if project != nil && project.ProjectId != "" { | ||
| return project.ProjectId, nil | ||
| } | ||
|
|
||
| if project == nil { | ||
| return "", fmt.Errorf("%s; %s", analyticsProjectIDRequirement, analyticsProjectSelectHint) | ||
| } | ||
|
|
||
| projectName := project.Name | ||
| if strings.TrimSpace(projectName) == "" { | ||
| projectName = "<selected>" | ||
| } | ||
|
|
||
| return "", fmt.Errorf( | ||
| "selected project [%s] is missing project_id; %s. %s", | ||
| projectName, | ||
| analyticsProjectIDRequirement, | ||
| analyticsProjectSelectHint, | ||
| ) | ||
| } |
There was a problem hiding this comment.
Urf, I would love a better solution than this...it basically mandates the user either remove and re-auth the legacy project, or go and edit ~/.livekit/cli-config.yaml to manually add it. We've only started storing the project ID in the last ~5 months.
Let me see if there's an easy way to maybe install a startup hook that will backfill old projects with their ID.
There was a problem hiding this comment.
Yeah this is a bummer. I only noticed this since I fell into that older case, but it wasn't a big deal for me to re-auth (or just manually add it back in).
I couldn't find any endpoint/way of fetching the ID, otherwise I'd be happy to take a stab at a backfill. Let me know what you find.
|
This looks great so far! I will take a closer look and play around with it this evening. To answer your question, no -- analytics service is not implemented in LiveKit OSS. But neither are the |
|
Hey @rektdeckard is there anything I can help with for this PR? |
rektdeckard
left a comment
There was a problem hiding this comment.
Apologies for the holdup here. We are internally working on a total reimplementation of authentication on the CLI to move toward user-based authentication and I had hoped we would land that (including access to new analytics endpoints) sooner than it has. In the interim, I am happy to include the work you've done here to expose our existing REST endpoints, and we can go ahead with it as-is, modulo some small nits below.
Thanks for the contribution, and sorry again it took me so long to get to this!
| &cli.IntFlag{ | ||
| Name: "limit", | ||
| Usage: "Maximum number of sessions to return", | ||
| }, |
There was a problem hiding this comment.
Omission of this query parameter will always return no results, which is unexpected. Can you update this to set a reasonable default (maybe 10?) and wire it through the query builder code?
| rawJSONToString(session.BandwidthIn), | ||
| rawJSONToString(session.BandwidthOut), |
There was a problem hiding this comment.
Some size formatting would be nice here (B/K/M)
| ) | ||
| } | ||
|
|
||
| fmt.Println(table) |
There was a problem hiding this comment.
We have since added some new conventions for command output and logging that uses a Printer for all this stuff. It is globally available as the variable out. Can you update this and all calls to fmt.Print* to out.Result*/out.Status* calls?
| fmt.Println(table) | |
| out.Result(table) |
Adds a new
lk analyticscommand group to query LiveKit Cloud Analytics sessions.lk analytics listandlk analytics get SESSION_ID.--json/-joutput for both commands.--limit,--page,--start,--endwith validation.--project/ default project) and requires storedproject_id(no--project-idoverride).--curlsupport for analytics REST requests (prints equivalent curl command).go test ./cmd/lk.Mostly generated with Codex with manual code review.
Biggest thing I assumed was this is tightly coupled to LiveKit Cloud. Does this endpoint work for self hosted instances? I think the way this is built works for custom server URLs, but maybe some of the messages need to be tweaked