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

feat: Dump resources command for debuggability #6635

Merged
merged 7 commits into from
Feb 13, 2025
Merged

Conversation

k-anshul
Copy link
Member

@k-anshul k-anshul commented Feb 10, 2025

subtask for https://github.com/rilldata/rill-private-issues/issues/854

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

@k-anshul k-anshul self-assigned this Feb 10, 2025
cli/cmd/sudo/project/dump_resources.go Outdated Show resolved Hide resolved
cli/cmd/sudo/project/dump_resources.go Outdated Show resolved Hide resolved
@begelundmuller begelundmuller changed the title feat : Dump resources command for debuggability feat: Dump resources command for debuggability Feb 12, 2025
cli/pkg/printer/resources.go Outdated Show resolved Hide resolved
Comment on lines 574 to 578
switch r.Meta.Name.Kind {
case runtime.ResourceKindSource:
spec, specErr = protojson.MarshalOptions{Indent: " "}.Marshal(r.GetSource().Spec)
state, stateErr = protojson.MarshalOptions{Indent: " "}.Marshal(r.GetSource().State)
case runtime.ResourceKindModel:
Copy link
Contributor

Choose a reason for hiding this comment

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

All these cases seem excessive for an internal dump tool. Did you consider just doing a JSON roundtrip to avoid handling each type specifically? E.g. (pseudocode):

rowJSON := protojson.Marshal(r)
row := json.Unmarshal(rowJSON)
for k, v := range row {
  if k != "meta" {
    row["spec"] = row[k]["spec"]
    row["state"] = row[k]["state"]
    delete(row, k)
    break
  }
}

row["org"] = org
row["project"] = project
row["resource_type"] = runtime.PrettifyResourceKind(r.Meta.Name.Kind)
row["resource_name"] = r.Meta.Name.Name

return row

Copy link
Member Author

Choose a reason for hiding this comment

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

No I did not consider handling via JSON but sounds like a better idea. Modified the code.

cli/pkg/printer/resources.go Outdated Show resolved Hide resolved
cli/cmd/sudo/project/dump_resources.go Outdated Show resolved Hide resolved
@k-anshul k-anshul merged commit 13886b0 into main Feb 13, 2025
10 checks passed
@k-anshul k-anshul deleted the dump_resources branch February 13, 2025 15:27
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.

2 participants