pesos / grofer

A system and resource monitoring tool written in Golang!
Apache License 2.0
352 stars 52 forks source link

Refactor grofer to make it more extensible ✨ #129

Closed MadhavJivrajani closed 3 years ago

MadhavJivrajani commented 3 years ago

👏 Major 👏 Changes 👏

The main theme of this refactor is to make grofer more extensible and to avoid duplicating and writing redundant boilerplate for every new command created. grofer still has a long way to go in terms of code quality, but this is defintiely a start in the right direction.

Design: The design of grofer now more closely resembles a producer-consumer model of doing things.

MetricScraper - A MetricScraper is any entity that scrapes metrics of any form and Serves them. A MetricScraper also has the ability to set a Sink. Meaning that it can choose what the consumer of the produced metrics will be.

MetricScraperFactory - A MetricScraperFactory produces MetricScrapers based on what the command is. The main purpose of a MetricScraperFactory is to provide a uniform set of functions using which a MetricScraper can be Constructed for any command.

The advantage that the above two abstractions provide is that it allows us to introduce new scrapers independant of the code in the cmd directory and also allows us to introduce new Sinks irrespective of the scrapers present.

As of now, only one sink exists - TUI. Which is the TUI of grofer that consumes the produced metrics. Ideally, export should also be a sink, but this isn't possible with the current state because of non-uniform data formats being used. Once these formats are unified, sinks can be added independent of scrapers and vice-versa.

Directory structure (trimmed, not including non-code files):

├── cmd
├── pkg
│   ├── core
│   ├── export
│   ├── metrics
│   │   ├── container
│   │   ├── factory
│   │   ├── general
│   │   └── process
│   ├── sink
│   │   └── tui
│   │       ├── container
│   │       ├── general
│   │       ├── misc
│   │       └── process
│   └── utils
│       └── visualization
└── scripts

Misc changes:

MadhavJivrajani commented 3 years ago

@Gituser143 made the changes discussed on call, along with refactoring error art ;)