Hey all-
We're moving forward on MetricFu modularity, and separating concerns. One major feature on that path is making each metric self-contained. Each metric needs to know how to configure itself. In order to make plugins possible, MetricFu should know about configured plugins.
I have a work-in-progress PR right now that is a first step in that direction.
https://github.com/metricfu/metric_fu/pull/91 Each metric has a class that subclasses MetricFu::Metric. MetricFu::Metric has an inherited hook that collects all its subclasses, which means it knows about all configured metrics.
Right now, it knows its name, its run options, whether it has a graph, and some limited information about when it can be enabled. I'm following in how Pry has for each plugin an 'activated' and 'enabled' attribute. Enabled plugins are used by Pry. Activated means that their libraries have been required. So, a library can be activated, but not enabled.
# Encapsulates the configuration options for each metric
module MetricFu
class Metric
attr_accessor :enabled
def initialize
self.enabled = false
end
def enable
self.enabled = true
end
# @return metric name [Symbol]
def metric_name
not_implemented
end
# @return metric run options [Hash]
def run_options
not_implemented
end
# @return metric_options [Hash]
def has_graph?
not_implemented
end
@metrics = []
# @return all subclassed metrics [Array<MetricFu::Metric>]
def self.metrics
@metrics
end
def self.get_metric(metric_name)
metrics.find{|metric|metric.metric_name.to_s == metric_name.to_s}
end
def self.inherited(subclass)
@metrics << subclass.new
end
private
def not_implemented
raise "Required method #{caller[0]} not implemented in #{__FILE__}"
end
end
end
I think the following are all the things the metric should know about itself
* metric_name
* run_options
* graph_options for bluff and gchart
* its templates for html, yaml, etc output
* whether it is activated
* whether it is enabled. There is an 'enable' method that encapsulates logic that prevents enabled such as something like
def enable
if MetricFu.configuration.mri?
super
else
MetricFu.configuration.mf_debug("Cane is only available in MRI. It requires ripper")
end
end
* -> it should know about its environment so it can make decisions based on it. We'll have an environment class that knows the ruby engine(cruby,jruby etc), the ruby version, if there's ripper support, if there's a rails project, cruise control?, etc
* Its hotspots configuration, how it identifies and weights problems
* Error handling?
Thoughts?
-Benjamin