Skip to content

Commit

Permalink
Bump java-dogstastd-client to support env-var based configuration (#17)
Browse files Browse the repository at this point in the history
The underlying library supports using the envvars DD_AGENT_HOST, DD_DOGSTATSD_PORT and DD_ENTITY_ID to configure the client.

The change in this PR removes the "custom" configuration in this library so that we defer all contextual setup to the underlying library. This slightly alters the default behaviour by requiring consumers to set the host explicity (through envvars or the host option).

Closes #15
  • Loading branch information
Raymond Huang authored Jun 28, 2019
1 parent 7e5b3a7 commit 4f4abc3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:comments "Copyright (c) 2018 Unbounce Marketing Solutions Inc."}
:profiles {:dev {:dependencies [[org.clojure/test.check "0.9.0"]]}}
:dependencies [[org.clojure/clojure "1.9.0"]
[com.datadoghq/java-dogstatsd-client "2.6.1"]]
[com.datadoghq/java-dogstatsd-client "2.8"]]
:global-vars {*warn-on-reflection* true}
:deploy-repositories {"releases" {:url "https://repo.clojars.org" :creds :gpg}}
)
22 changes: 14 additions & 8 deletions src/com/unbounce/dogstatsd/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,28 @@
(defn setup!
"Sets up the statsd client.
By default, assumes localhost and port 8125. You can change the host and port with:
If :host is not explicitly specified, it will defer to the environment variable DD_AGENT_HOST.
If :port is not explicitly specified, it will first try to read it from the env var DD_DOGSTATSD_PORT, and then fallback to the default port 8125.
Examples:
To setup the client on host \"some-other-post\" and port 1234
(setup! :host \"some-other-host\" :port 1234)
To setup the client once and avoid reloading it, use :once?
(setup! :once? true)
(setup! :host \"some-other-host\" :once? true)
"
[& {:keys [^String host ^long port ^String prefix #^"[Ljava.lang.String;" tags once?]}]
[& {:keys [^String host ^long port ^String prefix tags once?]}]
(when-not (and client once?)
(shutdown!)
(alter-var-root #'client (constantly
(com.timgroup.statsd.NonBlockingStatsDClient.
prefix
(or host "localhost")
(or port 8125)
tags)))))
host
(or port 0)
(str-array tags))))))

(defn increment
([metric]
Expand Down Expand Up @@ -165,9 +169,11 @@
(.recordSetValue client metric value tags))

(comment
(setup!)
(setup! :host "localhost" :port 8125 :tags #{"hello" "world"})

;; In a terminal, setup `nc -u -l 8125` to watch for events
(event {:title "foo" :text "things are bad\nfoo"} nil)
(increment "foo.bar")

(service-check {:name "hi" :status :warning} nil)
(service-check {:name "hi" :status :ok :timestamp 10 :check-run-id 123 :message "foo" :hostname "blah"} nil)
Expand Down

0 comments on commit 4f4abc3

Please sign in to comment.