Skip to content

Commit

Permalink
Release 0.2.61
Browse files Browse the repository at this point in the history
Add function retry-stats
  • Loading branch information
ivarref committed Sep 7, 2022
1 parent 812a07b commit c7b74e2
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,34 @@ Note: I have not tried these libraries myself.

## Change log

#### 2022-09-07 v0.2.61 [diff](https://github.com/ivarref/yoltq/compare/v0.2.60...v0.2.61)
Added function option `retry-stats`:

```clojure
(ns com.github.ivarref.yoltq)

(defn retry-stats
"Gather retry statistics.
Optional keyword arguments:
* :age-days — last number of days to look at data from. Defaults to 30.
* :queue-name — only gather statistics for this queue name. Defaults to nil, meaning all queues.
Example return value:
{:queue-a {:ok 100, :retries 2, :retry-percentage 2.0}
:queue-b {:ok 100, :retries 75, :retry-percentage 75.0}}
From the example value above, we can see that :queue-b fails at a much higher rate than :queue-a.
Assuming that the queue consumers are correctly implemented, this means that the service representing :queue-b
is much more unstable than the one representing :queue-a. This again implies
that you will probably want to fix the downstream service of :queue-b, if that is possible.
"
[{:keys [age-days queue-name now]
:or {age-days 30
now (ZonedDateTime/now ZoneOffset/UTC)}}]
...)
```

#### 2022-08-18 v0.2.60 [diff](https://github.com/ivarref/yoltq/compare/v0.2.59...v0.2.60)
Improved: Added config option `:healthy-allowed-error-time`:
```
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<packaging>jar</packaging>
<groupId>com.github.ivarref</groupId>
<artifactId>yoltq</artifactId>
<version>0.2.60</version>
<version>0.2.61</version>
<name>yoltq</name>
<dependencies>
<dependency>
Expand All @@ -30,7 +30,7 @@
<scm>
<connection>scm:git:git://github.com/ivarref/yoltq.git</connection>
<developerConnection>scm:git:ssh://[email protected]/ivarref/yoltq.git</developerConnection>
<tag>v0.2.60</tag>
<tag>v0.2.61</tag>
<url>https://github.com/ivarref/yoltq</url>
</scm>
</project>
49 changes: 48 additions & 1 deletion src/com/github/ivarref/yoltq.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[datomic.api :as d])
(:import (datomic Connection)
(java.lang.management ManagementFactory)
(java.time Duration)
(java.time Duration Instant ZoneOffset ZonedDateTime)
(java.util.concurrent ExecutorService Executors TimeUnit)))


Expand Down Expand Up @@ -247,6 +247,53 @@
cfg (assoc-in cfg [:handlers qname :max-retries] Integer/MAX_VALUE)]
(poller/poll-once! cfg qname :error)))

(defn retry-stats
"Gather retry statistics.
Optional keyword arguments:
* :age-days — last number of days to look at data from. Defaults to 30.
* :queue-name — only gather statistics for this queue name. Defaults to nil, meaning all queues.
Example return value:
{:queue-a {:ok 100, :retries 2, :retry-percentage 2.0}
:queue-b {:ok 100, :retries 75, :retry-percentage 75.0}}
From the example value above, we can see that :queue-b fails at a much higher rate than :queue-a.
Assuming that the queue consumers are correctly implemented, this means that the service representing :queue-b
is much more unstable than the one representing :queue-a. This again implies
that you will probably want to fix the downstream service of :queue-b, if that is possible.
"
[{:keys [age-days queue-name now]
:or {age-days 30
now (ZonedDateTime/now ZoneOffset/UTC)}}]
(let [{:keys [conn]} @*config*
db (d/db conn)]
(->> (d/query {:query {:find '[?qname ?status ?tries ?init-time]
:in (into '[$] (when queue-name '[?qname]))
:where '[[?e :com.github.ivarref.yoltq/queue-name ?qname]
[?e :com.github.ivarref.yoltq/status ?status]
[?e :com.github.ivarref.yoltq/tries ?tries]
[?e :com.github.ivarref.yoltq/init-time ?init-time]]}
:args (remove nil? [db queue-name])})
(mapv (partial zipmap [:qname :status :tries :init-time]))
(mapv #(update % :init-time (fn [init-time] (.atZone (Instant/ofEpochMilli init-time) ZoneOffset/UTC))))
(mapv #(assoc % :age-days (.toDays (Duration/between (:init-time %) now))))
(filter #(<= (:age-days %) age-days))
(group-by :qname)
(mapv (fn [[q values]]
{q (let [{:keys [ok retries] :as m} (->> values
(mapv (fn [{:keys [tries status]}]
(condp = status
u/status-init {}
u/status-processing {:processing 1 :retries (dec tries)}
u/status-done {:ok 1 :retries (dec tries)}
u/status-error {:error 1 :retries (dec tries)})))
(reduce (partial merge-with +) {}))]
(into (sorted-map) (merge m
(when (pos-int? ok)
{:retry-percentage (double (* 100 (/ retries ok)))}))))}))
(into (sorted-map)))))

(comment
(do
(require 'com.github.ivarref.yoltq.log-init)
Expand Down

0 comments on commit c7b74e2

Please sign in to comment.