Skip to content

Commit 762fb91

Browse files
committed
refactor: remove unused methods from Failbot and Stats instrument classes
1 parent 4a2b81e commit 762fb91

File tree

8 files changed

+4
-280
lines changed

8 files changed

+4
-280
lines changed

lib/hooks/plugins/instruments/failbot.rb

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,7 @@ module Instruments
1111
# Users can replace this with their own implementation for services
1212
# like Sentry, Rollbar, etc.
1313
class Failbot < FailbotBase
14-
# Report an error or exception
15-
#
16-
# @param error_or_message [Exception, String] Exception object or error message
17-
# @param context [Hash] Optional context information
18-
# @return [void]
19-
def report(error_or_message, context = {})
20-
# Override in subclass for actual error reporting
21-
end
22-
23-
# Report a critical error
24-
#
25-
# @param error_or_message [Exception, String] Exception object or error message
26-
# @param context [Hash] Optional context information
27-
# @return [void]
28-
def critical(error_or_message, context = {})
29-
# Override in subclass for actual error reporting
30-
end
31-
32-
# Report a warning
33-
#
34-
# @param message [String] Warning message
35-
# @param context [Hash] Optional context information
36-
# @return [void]
37-
def warning(message, context = {})
38-
# Override in subclass for actual warning reporting
39-
end
14+
# Inherit from FailbotBase to provide a default implementation of the failbot instrument.
4015
end
4116
end
4217
end

lib/hooks/plugins/instruments/failbot_base.rb

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,6 @@ class FailbotBase
1919
def log
2020
Hooks::Log.instance
2121
end
22-
23-
# Report an error or exception
24-
#
25-
# @param error_or_message [Exception, String] Exception object or error message
26-
# @param context [Hash] Optional context information
27-
# @return [void]
28-
# @raise [NotImplementedError] if not implemented by subclass
29-
def report(error_or_message, context = {})
30-
raise NotImplementedError, "Failbot instrument must implement #report method"
31-
end
32-
33-
# Report a critical error
34-
#
35-
# @param error_or_message [Exception, String] Exception object or error message
36-
# @param context [Hash] Optional context information
37-
# @return [void]
38-
# @raise [NotImplementedError] if not implemented by subclass
39-
def critical(error_or_message, context = {})
40-
raise NotImplementedError, "Failbot instrument must implement #critical method"
41-
end
42-
43-
# Report a warning
44-
#
45-
# @param message [String] Warning message
46-
# @param context [Hash] Optional context information
47-
# @return [void]
48-
# @raise [NotImplementedError] if not implemented by subclass
49-
def warning(message, context = {})
50-
raise NotImplementedError, "Failbot instrument must implement #warning method"
51-
end
52-
53-
# Capture an exception during block execution
54-
#
55-
# @param context [Hash] Optional context information
56-
# @return [Object] Return value of the block
57-
def capture(context = {})
58-
yield
59-
rescue => e
60-
report(e, context)
61-
raise
62-
end
6322
end
6423
end
6524
end

lib/hooks/plugins/instruments/stats.rb

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,7 @@ module Instruments
1111
# Users can replace this with their own implementation for services
1212
# like DataDog, New Relic, etc.
1313
class Stats < StatsBase
14-
# Record a metric
15-
#
16-
# @param metric_name [String] Name of the metric
17-
# @param value [Numeric] Value to record
18-
# @param tags [Hash] Optional tags/labels for the metric
19-
# @return [void]
20-
def record(metric_name, value, tags = {})
21-
# Override in subclass for actual metrics reporting
22-
end
23-
24-
# Increment a counter
25-
#
26-
# @param metric_name [String] Name of the counter
27-
# @param tags [Hash] Optional tags/labels for the metric
28-
# @return [void]
29-
def increment(metric_name, tags = {})
30-
# Override in subclass for actual metrics reporting
31-
end
32-
33-
# Record a timing metric
34-
#
35-
# @param metric_name [String] Name of the timing metric
36-
# @param duration [Numeric] Duration in seconds
37-
# @param tags [Hash] Optional tags/labels for the metric
38-
# @return [void]
39-
def timing(metric_name, duration, tags = {})
40-
# Override in subclass for actual metrics reporting
41-
end
14+
# Inherit from StatsBase to provide a default implementation of the stats instrument.
4215
end
4316
end
4417
end

lib/hooks/plugins/instruments/stats_base.rb

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,51 +19,6 @@ class StatsBase
1919
def log
2020
Hooks::Log.instance
2121
end
22-
23-
# Record a metric
24-
#
25-
# @param metric_name [String] Name of the metric
26-
# @param value [Numeric] Value to record
27-
# @param tags [Hash] Optional tags/labels for the metric
28-
# @return [void]
29-
# @raise [NotImplementedError] if not implemented by subclass
30-
def record(metric_name, value, tags = {})
31-
raise NotImplementedError, "Stats instrument must implement #record method"
32-
end
33-
34-
# Increment a counter
35-
#
36-
# @param metric_name [String] Name of the counter
37-
# @param tags [Hash] Optional tags/labels for the metric
38-
# @return [void]
39-
# @raise [NotImplementedError] if not implemented by subclass
40-
def increment(metric_name, tags = {})
41-
raise NotImplementedError, "Stats instrument must implement #increment method"
42-
end
43-
44-
# Record a timing metric
45-
#
46-
# @param metric_name [String] Name of the timing metric
47-
# @param duration [Numeric] Duration in seconds
48-
# @param tags [Hash] Optional tags/labels for the metric
49-
# @return [void]
50-
# @raise [NotImplementedError] if not implemented by subclass
51-
def timing(metric_name, duration, tags = {})
52-
raise NotImplementedError, "Stats instrument must implement #timing method"
53-
end
54-
55-
# Measure execution time of a block
56-
#
57-
# @param metric_name [String] Name of the timing metric
58-
# @param tags [Hash] Optional tags/labels for the metric
59-
# @return [Object] Return value of the block
60-
def measure(metric_name, tags = {})
61-
start_time = Time.now
62-
result = yield
63-
duration = Time.now - start_time
64-
timing(metric_name, duration, tags)
65-
result
66-
end
6722
end
6823
end
6924
end

spec/unit/lib/hooks/plugins/instruments/failbot_base_spec.rb

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,4 @@
99
expect(failbot.log).to eq(Hooks::Log.instance)
1010
end
1111
end
12-
13-
describe "#report" do
14-
it "raises NotImplementedError" do
15-
expect { failbot.report("error", {}) }.to raise_error(NotImplementedError, "Failbot instrument must implement #report method")
16-
end
17-
end
18-
19-
describe "#critical" do
20-
it "raises NotImplementedError" do
21-
expect { failbot.critical("critical error", {}) }.to raise_error(NotImplementedError, "Failbot instrument must implement #critical method")
22-
end
23-
end
24-
25-
describe "#warning" do
26-
it "raises NotImplementedError" do
27-
expect { failbot.warning("warning message", {}) }.to raise_error(NotImplementedError, "Failbot instrument must implement #warning method")
28-
end
29-
end
30-
31-
describe "#capture" do
32-
it "yields block and captures exceptions" do
33-
allow(failbot).to receive(:report)
34-
35-
result = failbot.capture({ context: "test" }) do
36-
"block_result"
37-
end
38-
39-
expect(result).to eq("block_result")
40-
expect(failbot).not_to have_received(:report)
41-
end
42-
43-
it "captures and re-raises exceptions" do
44-
error = StandardError.new("test error")
45-
allow(failbot).to receive(:report)
46-
47-
expect do
48-
failbot.capture({ context: "test" }) do
49-
raise error
50-
end
51-
end.to raise_error(error)
52-
53-
expect(failbot).to have_received(:report).with(error, { context: "test" })
54-
end
55-
end
5612
end

spec/unit/lib/hooks/plugins/instruments/failbot_spec.rb

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,6 @@
55

66
it "inherits from FailbotBase" do
77
expect(described_class).to be < Hooks::Plugins::Instruments::FailbotBase
8-
end
9-
10-
describe "#report" do
11-
it "does nothing by default" do
12-
expect { failbot.report("error", {}) }.not_to raise_error
13-
end
14-
end
15-
16-
describe "#critical" do
17-
it "does nothing by default" do
18-
expect { failbot.critical("critical error", {}) }.not_to raise_error
19-
end
20-
end
21-
22-
describe "#warning" do
23-
it "does nothing by default" do
24-
expect { failbot.warning("warning message", {}) }.not_to raise_error
25-
end
26-
end
27-
28-
describe "#capture" do
29-
it "yields block and does nothing on success" do
30-
result = failbot.capture({ context: "test" }) do
31-
"block_result"
32-
end
33-
34-
expect(result).to eq("block_result")
35-
end
36-
37-
it "captures but does nothing with exceptions" do
38-
error = StandardError.new("test error")
39-
40-
expect do
41-
failbot.capture({ context: "test" }) do
42-
raise error
43-
end
44-
end.to raise_error(error)
45-
end
8+
expect(failbot).to be_a(Hooks::Plugins::Instruments::FailbotBase)
469
end
4710
end

spec/unit/lib/hooks/plugins/instruments/stats_base_spec.rb

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,4 @@
99
expect(stats.log).to eq(Hooks::Log.instance)
1010
end
1111
end
12-
13-
describe "#record" do
14-
it "raises NotImplementedError" do
15-
expect { stats.record("metric", 1.0, {}) }.to raise_error(NotImplementedError, "Stats instrument must implement #record method")
16-
end
17-
end
18-
19-
describe "#increment" do
20-
it "raises NotImplementedError" do
21-
expect { stats.increment("counter", {}) }.to raise_error(NotImplementedError, "Stats instrument must implement #increment method")
22-
end
23-
end
24-
25-
describe "#timing" do
26-
it "raises NotImplementedError" do
27-
expect { stats.timing("timer", 0.5, {}) }.to raise_error(NotImplementedError, "Stats instrument must implement #timing method")
28-
end
29-
end
30-
31-
describe "#measure" do
32-
it "measures execution time and calls timing" do
33-
allow(stats).to receive(:timing)
34-
result = stats.measure("test_metric", { tag: "value" }) do
35-
"block_result"
36-
end
37-
38-
expect(result).to eq("block_result")
39-
expect(stats).to have_received(:timing).with("test_metric", kind_of(Numeric), { tag: "value" })
40-
end
41-
end
4212
end

spec/unit/lib/hooks/plugins/instruments/stats_spec.rb

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,6 @@
55

66
it "inherits from StatsBase" do
77
expect(described_class).to be < Hooks::Plugins::Instruments::StatsBase
8-
end
9-
10-
describe "#record" do
11-
it "does nothing by default" do
12-
expect { stats.record("metric", 1.0, {}) }.not_to raise_error
13-
end
14-
end
15-
16-
describe "#increment" do
17-
it "does nothing by default" do
18-
expect { stats.increment("counter", {}) }.not_to raise_error
19-
end
20-
end
21-
22-
describe "#timing" do
23-
it "does nothing by default" do
24-
expect { stats.timing("timer", 0.5, {}) }.not_to raise_error
25-
end
26-
end
27-
28-
describe "#measure" do
29-
it "still works for measuring execution time" do
30-
result = stats.measure("test_metric", { tag: "value" }) do
31-
"block_result"
32-
end
33-
34-
expect(result).to eq("block_result")
35-
end
8+
expect(stats).to be_a(Hooks::Plugins::Instruments::StatsBase)
369
end
3710
end

0 commit comments

Comments
 (0)