Skip to content

Commit

Permalink
Remove heartbeat aliases and warnings
Browse files Browse the repository at this point in the history
Remove all name and argument aliases for the deprecated heartbeat
invocations, and the corresponding deprecation warnings.
  • Loading branch information
unflxw committed Aug 14, 2024
1 parent e074679 commit 98fc66c
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 262 deletions.
21 changes: 0 additions & 21 deletions lib/appsignal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

require "appsignal/logger"
require "appsignal/utils/stdout_and_logger_message"
require "appsignal/helpers/heartbeat"
require "appsignal/helpers/instrumentation"
require "appsignal/helpers/metrics"

Expand All @@ -18,7 +17,6 @@
# {Appsignal::Helpers::Metrics}) for ease of use.
module Appsignal
class << self
include Helpers::Heartbeat
include Helpers::Instrumentation
include Helpers::Metrics

Expand Down Expand Up @@ -424,25 +422,6 @@ def collect_environment_metadata
end
Appsignal::Environment.report_supported_gems
end

# Alias constants that have moved with a warning message that points to the
# place to update the reference.
def const_missing(name)
case name
when :Heartbeat
unless @heartbeat_constant_deprecation_warning_emitted
callers = caller
Appsignal::Utils::StdoutAndLoggerMessage.warning \
"The constant Appsignal::Heartbeat has been deprecated. " \
"Please update the constant name to Appsignal::CheckIn::Cron " \
"in the following file and elsewhere to remove this message.\n#{callers.first}"
@heartbeat_constant_deprecation_warning_emitted = true
end
Appsignal::CheckIn::Cron
else
super
end
end
end
end

Expand Down
17 changes: 2 additions & 15 deletions lib/appsignal/check_in/cron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,13 @@ def transmitter
"#{Appsignal.config[:logging_endpoint]}/check_ins/json"
)
end

def emit_initializer_deprecation_warning
return if @initializer_deprecation_warning_emitted

callers = caller
Appsignal::Utils::StdoutAndLoggerMessage.warning(
"Passing a `name` keyword argument to `Appsignal::CheckIn::Cron.new` is deprecated. " \
"Please use the `identifier` keyword argument instead, " \
"in the following file and elsewhere, to remove this message.\n#{callers[2]}"
)
@initializer_deprecation_warning_emitted = true
end
end

# @api private
attr_reader :identifier, :digest

def initialize(identifier: nil, name: nil)
@identifier = identifier || name || raise(ArgumentError, "missing keyword: :identifier")
Cron.emit_initializer_deprecation_warning unless name.nil?
def initialize(identifier:)
@identifier = identifier
@digest = SecureRandom.hex(8)
end

Expand Down
20 changes: 0 additions & 20 deletions lib/appsignal/helpers/heartbeat.rb

This file was deleted.

206 changes: 0 additions & 206 deletions spec/lib/appsignal/check_in_spec.rb
Original file line number Diff line number Diff line change
@@ -1,170 +1,3 @@
describe Appsignal::Heartbeat do
let(:err_stream) { std_stream }

after do
Appsignal.instance_variable_set(:@heartbeat_constant_deprecation_warning_emitted, false)
end

it "returns the Cron constant calling the Heartbeat constant" do
silence { expect(Appsignal::Heartbeat).to be(Appsignal::CheckIn::Cron) }
end

it "prints a deprecation warning to STDERR" do
capture_std_streams(std_stream, err_stream) do
expect(Appsignal::Heartbeat).to be(Appsignal::CheckIn::Cron)
end

expect(err_stream.read)
.to include("appsignal WARNING: The constant Appsignal::Heartbeat has been deprecated.")
end

it "does not print a deprecation warning to STDERR more than once" do
capture_std_streams(std_stream, err_stream) do
expect(Appsignal::Heartbeat).to be(Appsignal::CheckIn::Cron)
end

expect(err_stream.read)
.to include("appsignal WARNING: The constant Appsignal::Heartbeat has been deprecated.")

err_stream.truncate(0)

capture_std_streams(std_stream, err_stream) do
expect(Appsignal::Heartbeat).to be(Appsignal::CheckIn::Cron)
end

expect(err_stream.read)
.not_to include("appsignal WARNING: The constant Appsignal::Heartbeat has been deprecated.")
end

it "logs a warning" do
logs =
capture_logs do
silence do
expect(Appsignal::Heartbeat).to be(Appsignal::CheckIn::Cron)
end
end

expect(logs).to contains_log(
:warn,
"The constant Appsignal::Heartbeat has been deprecated."
)
end

it "does not log a warning more than once" do
logs =
capture_logs do
silence do
expect(Appsignal::Heartbeat).to be(Appsignal::CheckIn::Cron)
end
end

expect(logs).to contains_log(
:warn,
"The constant Appsignal::Heartbeat has been deprecated."
)

logs =
capture_logs do
silence do
expect(Appsignal::Heartbeat).to be(Appsignal::CheckIn::Cron)
end
end

expect(logs).not_to contains_log(
:warn,
"The constant Appsignal::Heartbeat has been deprecated."
)
end
end

describe "Appsignal.heartbeat" do
let(:err_stream) { std_stream }

before do
Appsignal.instance_variable_set(:@heartbeat_helper_deprecation_warning_emitted, false)
end

it "should forward the call to Appsignal::CheckIn.cron" do
expect(Appsignal::CheckIn).to receive(:cron).with("heartbeat-name")
expect do
Appsignal.heartbeat("heartbeat-name")
end.not_to raise_error

block = proc { 42 }
expect(Appsignal::CheckIn).to receive(:cron).with("heartbeat-name") do |&given_block|
expect(given_block).to be(block)
end.and_return("output")
expect(Appsignal.heartbeat("heartbeat-name", &block)).to eq("output")
end

it "prints a deprecation warning to STDERR" do
capture_std_streams(std_stream, err_stream) do
Appsignal.heartbeat("heartbeat-name")
end

expect(err_stream.read)
.to include("appsignal WARNING: The helper Appsignal.heartbeat has been deprecated.")
end

it "does not print a deprecation warning to STDERR more than once" do
capture_std_streams(std_stream, err_stream) do
Appsignal.heartbeat("heartbeat-name")
end

expect(err_stream.read)
.to include("appsignal WARNING: The helper Appsignal.heartbeat has been deprecated.")

err_stream.truncate(0)

capture_std_streams(std_stream, err_stream) do
Appsignal.heartbeat("heartbeat-name")
end

expect(err_stream.read)
.not_to include("appsignal WARNING: The helper Appsignal.heartbeat has been deprecated.")
end

it "logs a warning" do
logs =
capture_logs do
silence do
Appsignal.heartbeat("heartbeat-name")
end
end

expect(logs).to contains_log(
:warn,
"The helper Appsignal.heartbeat has been deprecated."
)
end

it "does not log a warning more than once" do
logs =
capture_logs do
silence do
Appsignal.heartbeat("heartbeat-name")
end
end

expect(logs).to contains_log(
:warn,
"The helper Appsignal.heartbeat has been deprecated."
)

logs =
capture_logs do
silence do
Appsignal.heartbeat("heartbeat-name")
end
end

expect(logs).not_to contains_log(
:warn,
"The helper Appsignal.heartbeat has been deprecated."
)
end
end

describe Appsignal::CheckIn::Cron do
let(:config) { project_fixture_config }
let(:cron_checkin) { described_class.new(:name => "cron-checkin-name") }
Expand Down Expand Up @@ -300,43 +133,4 @@
end
end
end

describe "#initialize" do
describe "when initialised with deprecated heartbeat keyword names" do
let(:err_stream) { std_stream }

after do
described_class.instance_variable_set(:@initializer_deprecation_warning_emitted, false)
end

it "can be initialised" do
cron_checkin = described_class.new(:name => "cron-checkin-name")
expect(cron_checkin.identifier).to eq("cron-checkin-name")
end

it "logs a deprecation warning" do
capture_std_streams(std_stream, err_stream) do
expect(described_class.new(:name => "cron-checkin-name"))
.to be_a(Appsignal::CheckIn::Cron)
end

expect(err_stream.read)
.to include(
"appsignal WARNING: Passing a `name` keyword argument to " \
"`Appsignal::CheckIn::Cron.new` is deprecated."
)
end
end

it "can be initialised with cron check-in keyword names" do
cron_checkin = described_class.new(:identifier => "cron-checkin-name")
expect(cron_checkin.identifier).to eq("cron-checkin-name")
end

it "raises an error when no identifier is given" do
expect do
described_class.new
end.to raise_error(ArgumentError, "missing keyword: :identifier")
end
end
end

0 comments on commit 98fc66c

Please sign in to comment.