File: metrics_testutils.clj

package info (click to toggle)
trapperkeeper-metrics-clojure 1.5.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 464 kB
  • sloc: java: 221; sh: 52; xml: 33; makefile: 27
file content (42 lines) | stat: -rw-r--r-- 1,402 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(ns puppetlabs.trapperkeeper.services.metrics.metrics-testutils
  (:import (com.codahale.metrics.graphite GraphiteSender))
  (:require [schema.core :as schema]
            [clojure.set]))

(def graphite-config
  {:graphite
   {:host "my.graphite.server"
    :port 2003
    :update-interval-seconds 10}})

(def test-config
  {:server-id "localhost"
   :reporters graphite-config})

(defn build-config-with-registries
  [registries]
  (assoc test-config :registries registries))

(schema/defn make-graphite-sender :- GraphiteSender
  "Creates a GraphiteSender object which doesn't make any network requests,
  but instead collects the data from each call to send into the provided atom"
  [reported-metrics :- (schema/atom {schema/Keyword #{schema/Str}})
   domain :- schema/Keyword]
  (reify GraphiteSender
    (connect [this])
    (send [this name value timestamp]
      (swap! reported-metrics #(update-in % [domain] clojure.set/union #{name})))
    (flush [this])
    (isConnected [this] true)
    (getFailures [this] 0)
    (close [this])))

(schema/defn reported?
  "Returns true if the given metric-name is found in reported-metrics"
  ([reported-metrics metric-name]
   (reported? reported-metrics :default metric-name))
  ([reported-metrics :- {schema/Keyword #{schema/Str}}
    domain :- schema/Keyword
    metric-name :- schema/Str]
   (contains? (get reported-metrics domain) metric-name)))