Skip to content

Commit

Permalink
librato/safe-name: fix a bug which broke metric name escaping
Browse files Browse the repository at this point in the history
Invalid characters which were replaced and changed the length of the
string caused safe-name to (sometimes) call subs with a length larger
than the string itself, throwing an exception.
  • Loading branch information
aphyr committed Jan 3, 2013
1 parent 95c7caf commit 72e2373
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/riemann/librato.clj
Expand Up @@ -5,13 +5,14 @@
clojure.math.numeric-tower))

(defn safe-name
"Converts a string into a safe name for Librato's metrics and streams. Converts spaces to periods, preserves only A-Za-z0-9.:-_, and cuts to 255 characters."
"Converts a string into a safe name for Librato's metrics and streams.
Converts spaces to periods, preserves only A-Za-z0-9.:-_, and cuts to 255
characters."
[s]
(when s
(-> s
(string/replace " " ".")
(string/replace #"[^-.:_\w]" "")
(subs 0 (min 255 (count s))))))
(let [s (string/replace s " " ".")
s (string/replace s #"[^-.:_\w]" "")]
(subs s 0 (min 255 (count s))))))

(defn event->gauge
"Converts an event to a gauge."
Expand Down

0 comments on commit 72e2373

Please sign in to comment.