|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
| 3 | +require_relative "../../core/component_access" |
| 4 | + |
3 | 5 | module Hooks |
4 | 6 | module Plugins |
5 | 7 | module Instruments |
6 | 8 | # Base class for all stats instrument plugins |
7 | 9 | # |
8 | | - # All custom stats implementations must inherit from this class and implement |
9 | | - # the required methods for metrics reporting. |
| 10 | + # This class provides the foundation for implementing custom metrics reporting |
| 11 | + # instruments. Subclasses should implement specific methods for their target |
| 12 | + # metrics service (DataDog, New Relic, StatsD, etc.). |
| 13 | + # |
| 14 | + # @abstract Subclass and implement service-specific metrics methods |
| 15 | + # @example Implementing a custom stats instrument |
| 16 | + # class MyStatsImplementation < Hooks::Plugins::Instruments::StatsBase |
| 17 | + # def increment(metric_name, tags = {}) |
| 18 | + # # Send increment metric to your service |
| 19 | + # MyMetricsService.increment(metric_name, tags) |
| 20 | + # log.debug("Sent increment metric: #{metric_name}") |
| 21 | + # end |
| 22 | + # |
| 23 | + # def timing(metric_name, duration, tags = {}) |
| 24 | + # # Send timing metric to your service |
| 25 | + # MyMetricsService.timing(metric_name, duration, tags) |
| 26 | + # end |
| 27 | + # end |
| 28 | + # |
| 29 | + # @see Hooks::Plugins::Instruments::Stats |
10 | 30 | class StatsBase |
11 | | - # Short logger accessor for all subclasses |
12 | | - # @return [Hooks::Log] Logger instance |
| 31 | + include Hooks::Core::ComponentAccess |
| 32 | + |
| 33 | + # Record an increment metric |
| 34 | + # |
| 35 | + # This is a no-op implementation that subclasses should override |
| 36 | + # to provide actual metrics reporting functionality. |
| 37 | + # |
| 38 | + # @param metric_name [String] Name of the metric to increment |
| 39 | + # @param tags [Hash] Optional tags/labels for the metric |
| 40 | + # @return [void] |
| 41 | + # @note Subclasses should implement this method for their specific service |
| 42 | + # @example Override in subclass |
| 43 | + # def increment(metric_name, tags = {}) |
| 44 | + # statsd.increment(metric_name, tags: tags) |
| 45 | + # end |
| 46 | + def increment(metric_name, tags = {}) |
| 47 | + # No-op implementation for base class |
| 48 | + end |
| 49 | + |
| 50 | + # Record a timing/duration metric |
| 51 | + # |
| 52 | + # This is a no-op implementation that subclasses should override |
| 53 | + # to provide actual metrics reporting functionality. |
| 54 | + # |
| 55 | + # @param metric_name [String] Name of the timing metric |
| 56 | + # @param duration [Numeric] Duration value (typically in milliseconds) |
| 57 | + # @param tags [Hash] Optional tags/labels for the metric |
| 58 | + # @return [void] |
| 59 | + # @note Subclasses should implement this method for their specific service |
| 60 | + # @example Override in subclass |
| 61 | + # def timing(metric_name, duration, tags = {}) |
| 62 | + # statsd.timing(metric_name, duration, tags: tags) |
| 63 | + # end |
| 64 | + def timing(metric_name, duration, tags = {}) |
| 65 | + # No-op implementation for base class |
| 66 | + end |
| 67 | + |
| 68 | + # Record a gauge metric |
13 | 69 | # |
14 | | - # Provides a convenient way for instruments to log messages without needing |
15 | | - # to reference the full Hooks::Log namespace. |
| 70 | + # This is a no-op implementation that subclasses should override |
| 71 | + # to provide actual metrics reporting functionality. |
16 | 72 | # |
17 | | - # @example Logging an error in an inherited class |
18 | | - # log.error("Failed to send metric to external service") |
19 | | - def log |
20 | | - Hooks::Log.instance |
| 73 | + # @param metric_name [String] Name of the gauge metric |
| 74 | + # @param value [Numeric] Current value for the gauge |
| 75 | + # @param tags [Hash] Optional tags/labels for the metric |
| 76 | + # @return [void] |
| 77 | + # @note Subclasses should implement this method for their specific service |
| 78 | + # @example Override in subclass |
| 79 | + # def gauge(metric_name, value, tags = {}) |
| 80 | + # statsd.gauge(metric_name, value, tags: tags) |
| 81 | + # end |
| 82 | + def gauge(metric_name, value, tags = {}) |
| 83 | + # No-op implementation for base class |
21 | 84 | end |
22 | 85 | end |
23 | 86 | end |
|
0 commit comments