Skip to content

Feat: Add /graph and /graph/image endpoints #27

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 18 commits into from
Jan 10, 2025

Conversation

Its4Nik
Copy link
Owner

@Its4Nik Its4Nik commented Jan 10, 2025

Added these endpoints:

  • /graph: has a cached html file with will get responded
  • /graph/image: Responds with a png image created using puppeteer, this endpoint can be embed on GitHub for example.

Summary by Sourcery

Add /graph and /graph/image endpoints. The /graph endpoint serves a cached HTML file containing a dependency graph, while /graph/image serves a PNG image of the same graph, suitable for embedding in platforms like GitHub.

New Features:

  • Added two new endpoints, /graph and /graph/image, for visualizing container dependencies as an HTML file and a PNG image, respectively.

ToDo:

  • Add tests for the new endpoints and associated functionality. Since we cant test if the image looks identical (not easy atleast) there will be no tests!

@Its4Nik Its4Nik added enhancement New feature or request new feature A new feature will be added by this PR labels Jan 10, 2025
@Its4Nik Its4Nik self-assigned this Jan 10, 2025
Copy link
Contributor

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

sourcery-ai bot commented Jan 10, 2025

Reviewer's Guide by Sourcery

This pull request introduces two new endpoints related to dependency graphs: /graph and /graph/image. The /graph endpoint serves a cached HTML file containing the dependency graph, while /graph/image responds with a PNG image of the graph generated using Puppeteer. This image can be embedded in platforms like GitHub.

Sequence diagram for the new graph endpoints

sequenceDiagram
    participant Client
    participant GraphEndpoint as /graph
    participant GraphImageEndpoint as /graph/image
    participant GraphHandler
    participant Puppeteer
    participant FileSystem

    alt Request HTML Graph
        Client->>GraphEndpoint: GET /graph
        GraphEndpoint->>FileSystem: Read cached HTML
        FileSystem-->>GraphEndpoint: Return HTML file
        GraphEndpoint-->>Client: Serve HTML graph
    else Request PNG Graph
        Client->>GraphImageEndpoint: GET /graph/image
        GraphImageEndpoint->>GraphHandler: Generate graph image
        GraphHandler->>Puppeteer: Create browser instance
        Puppeteer->>Puppeteer: Render HTML content
        Puppeteer->>Puppeteer: Take screenshot
        Puppeteer-->>GraphHandler: Return PNG image
        GraphHandler-->>GraphImageEndpoint: Return image
        GraphImageEndpoint-->>Client: Serve PNG image
    end
Loading

Class diagram for graph-related components

classDiagram
    class GraphHandler {
        -generateGraphFiles(allContainerData)
        -getGraphFilePaths()
        -renderGraphToImage(htmlContent, outputPath)
    }

    class Puppeteer {
        +launch()
        +createPage()
        +setContent()
        +screenshot()
    }

    class FileSystem {
        +writeFile()
        +readFile()
    }

    GraphHandler --> Puppeteer: uses
    GraphHandler --> FileSystem: uses
Loading

Flow diagram for graph generation process

graph TD
    A[Start Graph Generation] --> B[Load Container Data]
    B --> C[Generate Graph Elements]
    C --> D[Create HTML Content]
    D --> E{Cache Files}
    E --> F[Cache JSON Data]
    E --> G[Cache HTML File]
    E --> H[Generate PNG Image]
    H --> I[Use Puppeteer]
    I --> J[Render HTML]
    J --> K[Take Screenshot]
    K --> L[Save PNG File]
    L --> M[End Graph Generation]
Loading

File-Level Changes

Change Details Files
Added new endpoints for serving dependency graph
  • Implemented /graph endpoint to serve cached HTML of dependency graph
  • Implemented /graph/image endpoint to serve PNG image of the graph
  • Updated documentation to include new endpoints
  • Added Puppeteer for graph image generation
  • Implemented graph generation logic using Cytoscape
README.md
package.json
src/config/swagger.yaml
src/handlers/graph.ts
src/routes/graphs/routes.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai bot changed the title @sourcery-ai Feat: Add /graph and /graph/image endpoints Jan 10, 2025
@Its4Nik Its4Nik changed the base branch from main to Swagger-update January 10, 2025 19:48
Copy link
Owner Author

Choose a reason for hiding this comment

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

Could use refactoring, won't do it in this branch tho

@Its4Nik Its4Nik merged commit 9f64c0f into Swagger-update Jan 10, 2025
7 checks passed
@Its4Nik Its4Nik deleted the Feat-embedded-graphs branch January 10, 2025 20:18
Its4Nik added a commit that referenced this pull request Jan 12, 2025
* Chore: Updated swagger

* Fix: Typo

* Fix: Fixing dockerfiles for prod/dev environment

* Feat: Add `/graph` and `/graph/image` endpoints (#27)

* Feat: Server side HTML generation => Client side rendering

* Fix: This _might_ fix the workflow

* Fix: Remove unused function

* Fix: Please make it stop

* Fix: Setting up python before hand

* Fix: Remove unused dep

* Fix: Using node20 instead of latest

* Fix: Works on my end...

* Feat: Master Nodes

* Feat: Icon for master node (needs testing)

* Fix: Adjusting function (needs testing)

* Fix: Adjusting function (needs testing)

* Fix: Removed some graph rendering features (will be back but better)

* Feat: render html file as png using puppeteer

ToFix: svgs dont render

* Fix: Hell yeah we got image creation!

* Fix: Adjusted routes since they need an absolute path

* Fix: Remove unused dependencies

* Fix: Exclude CWE-200 from CodeQl

* Feat: Respomse examples in swagger

Fix: Fixing some catch blocks

* Fix: Adjusting catches

* Fix: Adjusted catch to typing
Its4Nik added a commit that referenced this pull request Feb 9, 2025
* Chore: new testing workflows (dropping playwright)

* Chore: updating github workflow

* Fix: Fixing some minor things

* Chore: Updated to ES2020 syntax and AMD module

* Feat: startServer function to start the server with a different port

* Fix: Adjusting testing files based on workflow restrictions

* Fix: Adjusting testing files based on workflow restrictions

* Chore: Updating swagger (wrong branch bruh)

* Docs: Update swagger documentation (#26)

* Chore: Updated swagger

* Fix: Typo

* Fix: Fixing dockerfiles for prod/dev environment

* Feat: Add `/graph` and `/graph/image` endpoints (#27)

* Feat: Server side HTML generation => Client side rendering

* Fix: This _might_ fix the workflow

* Fix: Remove unused function

* Fix: Please make it stop

* Fix: Setting up python before hand

* Fix: Remove unused dep

* Fix: Using node20 instead of latest

* Fix: Works on my end...

* Feat: Master Nodes

* Feat: Icon for master node (needs testing)

* Fix: Adjusting function (needs testing)

* Fix: Adjusting function (needs testing)

* Fix: Removed some graph rendering features (will be back but better)

* Feat: render html file as png using puppeteer

ToFix: svgs dont render

* Fix: Hell yeah we got image creation!

* Fix: Adjusted routes since they need an absolute path

* Fix: Remove unused dependencies

* Fix: Exclude CWE-200 from CodeQl

* Feat: Respomse examples in swagger

Fix: Fixing some catch blocks

* Fix: Adjusting catches

* Fix: Adjusted catch to typing

* Feat: Stack creation

* Feat: Stack creation + starting and stopping

* Fix: Project root instead of path

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Fix: Logging adustment

* Fix: Allow undescores and dashes in stack name

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Fix: Propagate error

* Fix: Inline variable that is immediately returned

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Fix: move some things around

* Fix: Minor adjustments

* Feat: Get a stack's docker-compose

* Feat: automatic Stack environmental file management

* Fix: sample-varaible.json adjustment

* Fix: Potential fix for code scanning alert no. 102: Log injection

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* Fix: fix for code scanning alert no. 94: Uncontrolled data used in path expression

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* Fix: fix for code scanning alert no. 92: Uncontrolled data used in path expression

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* FiX: fix for code scanning alert no. 106: Log injection

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* Fix: Logger vulnerability and CI graph generation

* Feat: change logger verbosity and spelling fix

* Feat: ToDo comments to GH issue

* Fix: Add checkout

* Fix: May fix the ToDo workflow

* Fix: Remove todo

* Fix: Re-Add commit

* Fix: Remove TODO

* Fix: Re-add TODO

* Fix: Where tf did my package lock go 😭

* CI/CD: Remove ToDo

* CI/CD: Add ToDo

* CI/CD: Fix command

* CI/CD: Add checkout

* Fix: CPU value was a percentage the whole time?

* Feat: Websocket endpoints for logs and container metrics

* Fix: Make linter happy

* Fix: Fix import

* Fix: Fix tsc build

* Jest: Fix tests

* Jest: Fix Tests

* Fix: Typo in src/config/swagger.yaml

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Fix: Typo in src/config/swagger.yaml

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Fix: Tyypo in src/config/swagger.yaml

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* (code-quality): Inline variable that is immediately returned

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* (code-quality): Prefer object destructuring when accessing and using properties.

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* (code-quality): Prefer object destructuring when accessing and using properties.

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* (code-quality): Prefer object destructuring when accessing and using properties.

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Fix: Update extractHostData.ts

* Update TODO.md

---------

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: ItsNik <info@itsnik.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new feature A new feature will be added by this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant