Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composite collectors #8

Open
dm3 opened this issue Apr 27, 2017 · 0 comments
Open

Composite collectors #8

dm3 opened this issue Apr 27, 2017 · 0 comments

Comments

@dm3
Copy link

dm3 commented Apr 27, 2017

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants