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):
👏 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
- AMetricScraper
is any entity that scrapes metrics of any form andServe
s them. A MetricScraper also has the ability to set aSink
. Meaning that it can choose what the consumer of the produced metrics will be.MetricScraperFactory
- AMetricScraperFactory
producesMetricScraper
s based on what the command is. The main purpose of aMetricScraperFactory
is to provide a uniform set of functions using which aMetricScraper
can beConstruct
ed 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 newSink
s irrespective of the scrapers present.As of now, only one sink exists -
TUI
. Which is the TUI ofgrofer
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):
src
directory is now renamed topkg
directory due to convention.metrics
contains the logic and implementation of differentMetricScrapers
and theMetricScraperFactory
.metrics/container
contain scraper specific logic to actually get metrics.metrics/factory/container_metrics.go
contain the implementaion ofMetricScraper
for a container metrics specificMetricScraper
.MetricScraper
, theServe()
method is reponsible for choosing between sinks.FactoryOption
s are used to inject command specific configuration into theMetricScraper
implementation.sink
contains the different sinks that can consume metrics.core
package contains different command and sink types, and also some custom errors.cmd
directory uses a seperate command struct to and associated functions to abstract details from top level functions in cobra.Misc changes:
fileName.go
are changed tofile_name.go
because camel case in file names is weird.