Skip to content

feat: add snyk doctor extension#631

Open
CatalinSnyk wants to merge 2 commits into
mainfrom
feat/snyk-doctor
Open

feat: add snyk doctor extension#631
CatalinSnyk wants to merge 2 commits into
mainfrom
feat/snyk-doctor

Conversation

@CatalinSnyk

@CatalinSnyk CatalinSnyk commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Description

  • Adding the initial Snyk Doctor extension/
  • Registered under the local workflows and behind the experimental flag.

Checklist

  • Tests added and all succeed (make test)
  • Regenerated mocks, etc. (make generate)
  • Linted (make lint)
  • Test your changes work for the CLI - CLI PR
  • Tracking CLI-1589 / CLI-1530

For the reviewer

I think we can keep this PR open and use this as a feature branch (meaning the other PRs from tickets from the same epic would merge into this instead of main), just to keep the feature scoped until we get more things going around it.

@CatalinSnyk CatalinSnyk requested review from a team as code owners June 17, 2026 13:23
@snyk-io

snyk-io Bot commented Jun 17, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@snyk-io

snyk-io Bot commented Jun 17, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@snyk-pr-review-bot

This comment has been minimized.

Comment thread pkg/local_workflows/doctor_workflow/doctor_workflow.go
Comment thread pkg/local_workflows/doctor_workflow/doctor_workflow.go Outdated
Comment thread pkg/local_workflows/doctor_workflow/doctor_workflow.go Outdated

@robertolopezlopez robertolopezlopez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

some minor questions, one missing error check (maybe intended)

@robertolopezlopez

Copy link
Copy Markdown
Contributor

approving waiting for those changes :)

@CatalinSnyk

CatalinSnyk commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, I'm adding the tests now, just doing moving a few things around to get some dependency injections for the tests.

Also I'll keep the PR open for now, as I mentioned in the ticket and PR description - just to use it as a feature branch.

@snyk-pr-review-bot

This comment has been minimized.

@CatalinSnyk

Copy link
Copy Markdown
Contributor Author

Memory Inefficiency 🟠 [major]
The readDebugLog function returns a string, which forces a full copy of the log data from the initial []byte buffer. Subsequently, doctorEntryPoint converts this string back into a []byte when calling workflow.NewData, creating yet another copy. Snyk debug logs can be very large; this triple-buffering approach (byte slice -> string -> byte slice) significantly increases memory pressure and the risk of Out-Of-Memory (OOM) failures for no functional benefit. The code should pass []byte throughout.

Will be done later

@snyk-pr-review-bot

Copy link
Copy Markdown

PR Reviewer Guide 🔍

🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Redundant Allocations 🟡 [minor]

The readDebugLog function returns a string, which necessitates converting the []byte returned by os.ReadFile or io.ReadAll into a new string allocation (lines 76, 86). Subsequently, doctorEntryPoint converts this string back into a []byte at line 60 to pass it to workflow.NewData. Since Snyk debug logs can be extremely large, these redundant conversions significantly increase memory pressure by holding multiple copies of the data simultaneously. Returning []byte directly from readDebugLog would be more efficient.

		[]byte(debugLog),
		workflow.WithLogger(logger),
		workflow.WithConfiguration(config),
	)
	return []workflow.Data{outputData}, nil
}

func readDebugLog(stdin io.Reader, inputPath string) (string, error) {
	if inputPath != "" {
		content, err := os.ReadFile(inputPath)
		if err != nil {
			return "", cli.NewGeneralCLIFailureError(
				fmt.Sprintf("Could not read the debug log file at '%s'. Check that the path is correct and the file is readable.", inputPath),
				snyk_errors.WithCause(err),
			)
		}
		return string(content), nil
	}

	content, err := io.ReadAll(stdin)
	if err != nil {
		return "", cli.NewGeneralCLIFailureError(
			"Could not read the debug log from standard input.",
			snyk_errors.WithCause(err),
		)
	}
	return string(content), nil
📚 Repository Context Analyzed

This review considered 12 relevant code sections from 11 files (average relevance: 0.85)

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