Skip to content

Commit

Permalink
percentiles: put the quantile as attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
mcorbin committed Sep 28, 2024
1 parent 52d9412 commit cf3476e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
12 changes: 5 additions & 7 deletions src/clojure/mirabelle/action.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,7 @@
"Build a new event from an Exception and from the event which caused it."
[^Exception e base-event]
{:time (:time base-event)
:service "mirabelle-exception"
:name "mirabelle-exception"
:state "error"
:metric 1
:tags ["exception" (.getName (class e))]
Expand Down Expand Up @@ -2884,14 +2884,13 @@
(let [^Histogram histogram (.getIntervalHistogram recorder)]
(.recordValue recorder (:metric event))
(doseq [percentile percentiles]
(call-rescue (assoc event
:metric (.getValueAtPercentile histogram
(double (* 100 percentile)))
:quantile (str percentile))
(call-rescue (-> (assoc event
:metric (.getValueAtPercentile histogram
(double (* 100 percentile))))
(assoc-in [:attributes :quantile] (str percentile)))
children)))
(.recordValue recorder (:metric event))))))))


(s/def ::highest-trackable-value pos-int?)
(s/def ::nb-significant-digits pos-int?)
(s/def ::lowest-discernible-value number?)
Expand Down Expand Up @@ -3020,7 +3019,6 @@
(dissoc source))
children))))))


(defn iterate-on
[config & children]
;(mspec/valid-action? ::extract [k])
Expand Down
2 changes: 1 addition & 1 deletion src/clojure/mirabelle/math.clj
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
When s is empty, returns an empty list."
[s points]
(map (fn [pname event]
(assoc event :quantile (str pname)))
(assoc-in event [:attributes :quantile] (str pname)))
points
(sorted-sample-extract s points)))

Expand Down
16 changes: 8 additions & 8 deletions test/mirabelle/action_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -861,9 +861,9 @@
rec)
state
[[{:metric 3} {:metric 1} {:metric 2}]]
[{:metric 1 :quantile "0"}
{:metric 2 :quantile "0.5"}
{:metric 3 :quantile "1"}])))
[{:metric 1 :attributes {:quantile "0"}}
{:metric 2 :attributes {:quantile "0.5"}}
{:metric 3 :attributes {:quantile "1"}}])))

(deftest tagged-all*-test
(let [[rec state] (recorder)]
Expand Down Expand Up @@ -915,7 +915,7 @@
(stream {:foo 1})
(is (= 1 (count @state)))
(is (= "error" (:state (first @state))))
(is (= "mirabelle-exception" (:service (first @state))))
(is (= "mirabelle-exception" (:name (first @state))))
(is (instance? Exception (:exception (first @state))))))

(deftest streams-test
Expand Down Expand Up @@ -1518,10 +1518,10 @@
{:time 2 :metric 200}
{:time 4 :metric 800}
{:time 12 :metric 800}]
[{:time 12, :metric 100, :quantile "0"}
{:time 12, :metric 200, :quantile "0.5"}
{:time 12, :metric 800, :quantile "0.99"}
{:time 12, :metric 800, :quantile "1"}])))
[{:time 12, :metric 100, :attributes {:quantile "0"}}
{:time 12, :metric 200, :attributes {:quantile "0.5"}}
{:time 12, :metric 800, :attributes {:quantile "0.99"}}
{:time 12, :metric 800, :attributes {:quantile "1"}}])))

(deftest to-string-test
(let [[rec state] (recorder)]
Expand Down
16 changes: 12 additions & 4 deletions test/mirabelle/math_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,24 @@
[]

[{:metric 1 :service "foo"}]
[{:metric 1 :service "foo" :quantile "0"} {:metric 1 :service "foo" :quantile "0.5"} {:metric 1 :service "foo" :quantile "1"}]
[{:metric 1 :service "foo" :attributes {:quantile "0"}}
{:metric 1 :service "foo" :attributes {:quantile "0.5"}}
{:metric 1 :service "foo" :attributes {:quantile "1"}}]

[{:metric 2} {:metric 1}]
[{:metric 1 :quantile "0"} {:metric 2 :quantile "0.5"} {:metric 2 :quantile "1"}]
[{:metric 1 :attributes {:quantile "0"}}
{:metric 2 :attributes {:quantile "0.5"}}
{:metric 2 :attributes {:quantile "1"}}]

[{:metric 3} {:metric 1} {:metric 2}]
[{:metric 1 :quantile "0"} {:metric 2 :quantile "0.5"} {:metric 3 :quantile "1"}]
[{:metric 1 :attributes {:quantile "0"}}
{:metric 2 :attributes {:quantile "0.5"}}
{:metric 3 :attributes {:quantile "1"}}]

[{:metric 6} {:metric 1} {:metric 2} {:metric 1} {:metric 1}]
[{:metric 1 :quantile "0"} {:metric 1 :quantile "0.5"} {:metric 6 :quantile "1"}]))
[{:metric 1 :attributes {:quantile "0"}}
{:metric 1 :attributes {:quantile "0.5"}}
{:metric 6 :attributes {:quantile "1"}}]))

(deftest extremum-n-test
(are [events expected] (= (math/extremum-n 3 > events) expected)
Expand Down

0 comments on commit cf3476e

Please sign in to comment.