How tony-spark/metrico works
Main components
• Agent: In the cmd/agent and internal/agent directories, you find the core logic for collecting metrics, configuration handling, and the abstraction over various transports (HTTP, gRPC, etc.).
• Server: Located in cmd/server and internal/server, this handles incoming metrics, provides APIs (both HTTP and gRPC, as evidenced in directories like internal/server/http and internal/server/grpc), and further processes and persists the data.
• Data Storage and Persistence: Within internal/server/storage you have multiple storage implementations (file-based, PostgreSQL, perhaps even single-value in-memory storage) along with a “db” directory that includes migration scripts for setting up database tables.
• Transport Layers: Both the agent and server modules have dedicated packages for handling different transport mechanisms (e.g., internal/agent/transports for the agent and internal/server/{http,grpc} for the server). This outlines a clear separation and abstraction between the communication protocols.
• Configuration & Security: Directories like internal/config, cmd/agent/README.md, and the various config files (agent-config.json, server-config.json) indicate a modular setup for configuration management. The crypto and keys directories are used for signing or encrypting data, adding a security layer.
• Static Lint Tool: The cmd/staticlint and internal/staticlint directories represent an auxiliary tool to improve code quality by analyzing for common pitfalls (like potential misuse of os.Exit, for example).
Relationships and interactions
• The Server receives the metrics and uses its “services” and “models” packages to process and perhaps persist them. Include the storage backends (file system, PostgreSQL, or in-memory) that the server writes to.
• External assets (like the web UI templates under assets/templates or static asset generation via assets/assets.go) are used to display metrics. You may show these as a separate component connected to the Server.
• The API interface is highlighted by the proto and generated pb directories. These represent interoperable definitions for both HTTP and gRPC services, so show them as part of the Server’s API layer.
• The static analyzer tool (staticlint) runs separately, likely during CI/CD (as seen in the GitHub workflows), so represent it as an auxiliary tool used during development rather than at runtime.
Architectural patterns and design principles
• Modular Separation: Clear separation between the Agent and Server, each with dedicated modules (configuration, transports, metrics, etc.).
• Abstraction and extensibility: The use of transport packages and the configuration modules indicate an architecture that encourages adding more protocols or storage solutions without altering core logic.
• Layered Architecture: Presentation (web/UI templates and API endpoints), Business/Services (processing and persistence) and Data Access (storage implementations) are distinct.