From e94a311c8fa153985a51e5ceac06d3061ad8c667 Mon Sep 17 00:00:00 2001 From: Noemi <45180344+unflxw@users.noreply.github.com> Date: Thu, 1 Aug 2024 09:34:02 +0200 Subject: [PATCH] Fix cron check-in endpoint and event 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. --- lib/appsignal/check_in.ex | 21 ++++++++++++++------- test/appsignal/check_in_test.exs | 22 +++++++++++----------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/lib/appsignal/check_in.ex b/lib/appsignal/check_in.ex index fff8324c..047a64e5 100644 --- a/lib/appsignal/check_in.ex +++ b/lib/appsignal/check_in.ex @@ -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, _, _} -> @@ -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 diff --git a/test/appsignal/check_in_test.exs b/test/appsignal/check_in_test.exs index 98d75d41..fd264817 100644 --- a/test/appsignal/check_in_test.exs +++ b/test/appsignal/check_in_test.exs @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -84,7 +84,7 @@ 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 @@ -92,8 +92,8 @@ defmodule Appsignal.CheckInTest 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 @@ -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