Open
Description
I like the ideas behind with-timestamps
and with-counters
macros. However, their usage is harmed by having to manually assemble the composite collector maps of e.g.
(with-timestamps
{:last-run (registry :app/last-run),
:last-success (registry :app/last-success),
:last-failure (registry :app/last-failure)}
...)
Right now I'm using the following hack:
(require '[medley.core :as m])
(require '[iapetos.core :as ia])
(defn- composite-collector [collector-fn state-name opts ks]
(let [nm #(keyword (namespace state-name)
(str (name state-name) "." (name %)))
g #(collector-fn (nm %) opts)]
(zipmap ks (map g ks))))
(defn timestamps-gauge [state-name opts]
(composite-collector ia/gauge state-name opts
[:last-run :last-success :last-failure]))
(defn- composite? [collector-or-composite-map]
(not (satisfies? iapetos.collector/Collector collector-or-composite-map)))
(defn register [registry collector]
(if (composite? collector)
(apply ia/register registry (vals collector))
(ia/register registry collector)))
(defn at
([registry collector]
(at registry collector {}))
([registry collector labels]
(if (composite? collector)
(m/map-vals #(registry % labels) collector)
(registry collector labels))))
(defmacro with-timestamps
;; rewritten to not expect the literal map as input
)
;; Usage
(def collector (timestamps-gauge :app/function {:labels [:part]}))
(def registry (-> (ia/collector-registry) (register collector))
(with-timestamps (at registry collector {:part "x"}) ...)
I can imagine people coming up with various Collectors assembled from the basic counters/gauges. It would be nice if we could treat them as atomic units.
What do you think about making the composite collectors a first-class citizen of Iapetos?
Activity