Skip to content

Commit

Permalink
Fix cron check-in endpoint and event
Browse files Browse the repository at this point in the history
Change the endpoint to `/check_ins/json` and amend the event format
to use `identifier` instead of `name`, `digest` instead of `id`, and
a new `check_in_type` field.
  • Loading branch information
unflxw committed Aug 1, 2024
1 parent 2e46614 commit e94a311
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
21 changes: 14 additions & 7 deletions lib/appsignal/check_in.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ defmodule Appsignal.CheckIn.Cron do
defp transmit(event) do
if Appsignal.Config.active?() do
config = Appsignal.Config.config()
endpoint = "#{config[:logging_endpoint]}/checkins/cron/json"
endpoint = "#{config[:logging_endpoint]}/check_ins/json"

case @transmitter.transmit(endpoint, event, config) do
{:ok, status_code, _, _} when status_code in 200..299 ->
Appsignal.IntegrationLogger.trace(
"Transmitted cron check-in `#{event.name}` (#{event.id}) #{event.kind} event"
"Transmitted cron check-in `#{event.identifier}` (#{event.digest}) #{event.kind} event"
)

{:ok, status_code, _, _} ->
Expand Down Expand Up @@ -92,17 +92,24 @@ defmodule Appsignal.CheckIn.Cron.Event do
@derive Jason.Encoder

@type kind :: :start | :finish
@type t :: %Event{name: String.t(), id: String.t(), kind: kind, timestamp: integer}
@type t :: %Event{
identifier: String.t(),
digest: String.t(),
kind: kind,
timestamp: integer,
check_in_type: String.t()
}

defstruct [:name, :id, :kind, :timestamp]
defstruct [:identifier, :digest, :kind, :timestamp, :check_in_type]

@spec new(Cron.t(), kind) :: t
def new(%Cron{name: name, id: id}, kind) do
%Event{
name: name,
id: id,
identifier: name,
digest: id,
kind: kind,
timestamp: System.system_time(:second)
timestamp: System.system_time(:second),
check_in_type: "cron"
}
end
end
22 changes: 11 additions & 11 deletions test/appsignal/check_in_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule Appsignal.CheckInTest do
Cron.start(cron)

assert [
%Event{name: "cron-checkin-name", kind: :start}
%Event{identifier: "cron-checkin-name", kind: :start}
] = FakeTransmitter.transmitted_payloads()
end
end
Expand All @@ -41,7 +41,7 @@ defmodule Appsignal.CheckInTest do
Cron.finish(cron)

assert [
%Event{name: "cron-checkin-name", kind: :finish}
%Event{identifier: "cron-checkin-name", kind: :finish}
] = FakeTransmitter.transmitted_payloads()
end
end
Expand All @@ -51,8 +51,8 @@ defmodule Appsignal.CheckInTest do
output = CheckIn.cron("cron-checkin-name", fn -> "output" end)

assert [
%Event{name: "cron-checkin-name", kind: :start},
%Event{name: "cron-checkin-name", kind: :finish}
%Event{identifier: "cron-checkin-name", kind: :start},
%Event{identifier: "cron-checkin-name", kind: :finish}
] = FakeTransmitter.transmitted_payloads()

assert "output" == output
Expand All @@ -64,7 +64,7 @@ defmodule Appsignal.CheckInTest do
end

assert [
%Event{name: "cron-checkin-name", kind: :start}
%Event{identifier: "cron-checkin-name", kind: :start}
] = FakeTransmitter.transmitted_payloads()
end
end
Expand All @@ -74,7 +74,7 @@ defmodule Appsignal.CheckInTest do
CheckIn.cron("cron-checkin-name")

assert [
%Event{name: "cron-checkin-name", kind: :finish}
%Event{identifier: "cron-checkin-name", kind: :finish}
] = FakeTransmitter.transmitted_payloads()
end
end
Expand All @@ -84,16 +84,16 @@ defmodule Appsignal.CheckInTest do
Appsignal.heartbeat("heartbeat-name")

assert [
%Event{name: "heartbeat-name", kind: :finish}
%Event{identifier: "heartbeat-name", kind: :finish}
] = FakeTransmitter.transmitted_payloads()
end

test "forwards heartbeat/2 to CheckIn.cron/2" do
output = Appsignal.heartbeat("heartbeat-name", fn -> "output" end)

assert [
%Event{name: "heartbeat-name", kind: :start},
%Event{name: "heartbeat-name", kind: :finish}
%Event{identifier: "heartbeat-name", kind: :start},
%Event{identifier: "heartbeat-name", kind: :finish}
] = FakeTransmitter.transmitted_payloads()

assert "output" == output
Expand All @@ -105,8 +105,8 @@ defmodule Appsignal.CheckInTest do
Appsignal.Heartbeat.finish(heartbeat)

assert [
%Event{name: "heartbeat-name", kind: :start},
%Event{name: "heartbeat-name", kind: :finish}
%Event{identifier: "heartbeat-name", kind: :start},
%Event{identifier: "heartbeat-name", kind: :finish}
] = FakeTransmitter.transmitted_payloads()
end
end
Expand Down

0 comments on commit e94a311

Please sign in to comment.