-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor: Migrate to Bun, implement stacks and real-time stats #33
Conversation
… in logs and Error Page
Reviewer's Guide by SourceryThis pull request represents a significant refactoring and enhancement of the DockStatAPI project. It includes a migration to Bun, adoption of Elysia.js, implementation of SQLite, refactoring of logging, implementation of a plugin system, implementation of Docker Compose stack management, implementation of a WebSocket endpoint for streaming container statistics, implementation of scheduled tasks, addition of a check for 'CHANGE_ME' in plugin files, implementation of a relay controller, and addition of a 404 page. Sequence diagram for WebSocket container statistics streamsequenceDiagram
participant Client
participant WebSocket
participant Dockerode
participant SplitStream
Client->>WebSocket: Connects to /docker/stats
activate WebSocket
WebSocket->>Client: Connection established
WebSocket->>Dockerode: docker.listContainers()
activate Dockerode
Dockerode-->>WebSocket: ContainerInfo[]
loop for each container
WebSocket->>Dockerode: container.stats({stream: true})
activate Dockerode
Dockerode-->>WebSocket: statsStream (Readable)
WebSocket->>SplitStream: statsStream.pipe(splitStream)
activate SplitStream
SplitStream-->>WebSocket: line (string)
WebSocket->>Client: JSON.stringify(data)
Client-->>WebSocket: pong (heartbeat)
end
deactivate Dockerode
deactivate SplitStream
Client->>WebSocket: Close connection
WebSocket->>SplitStream: statsStream.destroy()
deactivate WebSocket
Updated class diagram for database repositoryclassDiagram
class dbFunctions {
+ init()
+ addDockerHost(hostId: string, url: string, secure: boolean)
+ getDockerHosts(): DockerHost[]
+ addLogEntry(level: string, message: string, file_name: string, line: number)
+ getAllLogs()
+ getLogsByLevel(level: string)
+ updateDockerHost(name: string, url: string, secure: boolean)
+ deleteDockerHost(name: string)
+ clearAllLogs()
+ clearLogsByLevel(level: string)
+ updateConfig(polling_rate: number, fetching_interval: number, keep_data_for: number)
+ getConfig()
+ deleteOldData(days: number)
+ addContainerStats(id: string, hostId: string, name: string, image: string, status: string, state: string, cpu_usage: number, memory_usage: number)
+ updateHostStats(stats: HostStats)
+ addStack(stack_config: stacks_config)
+ getStacks()
+ deleteStack(name: string)
+ updateStack(stack_config: stacks_config)
}
class DockerHost {
+ name: string
+ url: string
+ secure: boolean
}
class HostStats {
+ hostId: string
+ dockerVersion: string
+ apiVersion: string
+ os: string
+ architecture: string
+ totalMemory: number
+ totalCPU: number
+ labels: string[]
+ containers: number
+ containersRunning: number
+ containersStopped: number
+ containersPaused: number
+ images: number
}
class stacks_config {
+ name: string
+ version: number
+ custom: Boolean
+ source: string
+ container_count: number
+ stack_prefix: string
+ automatic_reboot_on_error: Boolean
+ image_updates: Boolean
}
dbFunctions -- DockerHost : returns
dbFunctions -- HostStats : uses
dbFunctions -- stacks_config : uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Its4Nik - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding a
docker-compose.override.yamlto define configurations that override the basedocker-compose.yaml.
Here's what I looked at during the review
- 🟡 General issues: 6 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 2 issues found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
…rned-variable) Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
…rned-variable) Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR #33 - v3
This PR includes a pretty big amount of changes, including:
- switch to Bun with Elysia as Express alternative
- Web sockets for container stats streaming
- A SQLite Database, where everything is kept
- Plugins!
- Advanced Logging
This results in a whole new codebase but rather that and better structured then DockStatAPI v1 / v2
@sourcery-ai
Summary by Sourcery
Refactor the project to use Bun instead of Node.js, improving performance and simplifying the development process. The API is now built with Elysia.js.
New Features: