Skip to content

Commit

Permalink
fixup! deps
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenet committed Jan 28, 2025
1 parent 6ee7fcd commit 6902bf5
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/spootnik/reporter/alert.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
(:import (java.time Instant)))

(defprotocol Alert
(send! [client alert]
"Sends `alert`, conforming to `:spootnik.reporter/alert`, via `client` to
alertmanager instance")
(msend! [client alerts]
"Sends `alerts` in bulk, conforming to `:spootnik.reporter/alerts`, via
`client` to alertmanager instance"))
(-send! [client alert])
(-msend! [client alerts]))

(s/def ::named (s/or :k ident? :s string?))

Expand Down Expand Up @@ -46,9 +42,6 @@
(defn ->alert
[{:as alert :keys [name labels annotations generator-url delay-after-ms]
:or {delay-after-ms (* 60 1000 15)}}]
(when-not (s/valid? :spootnik.reporter/alert alert)
(ex/ex-incorrect! "Invalid alert format"
(s/explain-data :spootnik.reporter/alert alert)))
(let [t (Instant/now)]
(cond-> {:startsAt (str t)
:endsAt (str (.plusMillis t (* delay-after-ms)))
Expand All @@ -67,12 +60,32 @@

(defrecord AlephClient [])

(s/def :spootnik.reporter.alert.client/server string?)
(s/def :spootnik.reporter.alert/client
(s/keys :req-un [:spootnik.reporter.alert.client/server]))

(extend-protocol Alert
AlephClient
(msend! [client alerts]
@(http/post "/api/v2/alerts"
(-msend! [client alerts]
@(http/post (format "%s/api/v2/alerts" (:server client))
(into {:body (alerts-body alerts)
:headers {"Content-Type" "application/json; charset=utf-8"}}
client)))
(send! [client alert]
(msend! client [alert])))
(-send! [client alert]
(-msend! client [alert])))

(defn send!
"Sends `alert`, conforming to `:spootnik.reporter/alert`, via `client` to
alertmanager instance"
[client alert]
(ex/assert-spec-valid :spootnik.reporter.alert/client client)
(ex/assert-spec-valid :spootnik.reporter/alert alert)
(-send! client alert))

(defn msend!
"Sends `alerts` in bulk, conforming to `:spootnik.reporter/alerts`, via `client`
to alertmanager instance"
[client alerts]
(ex/assert-spec-valid :spootnik.reporter.alert/client client)
(ex/assert-spec-valid :spootnik.reporter/alerts alerts)
(-msend! client alerts))

0 comments on commit 6902bf5

Please sign in to comment.