Skip to content

Instantly share code, notes, and snippets.

@ichramm
Last active December 27, 2019 17:28
Show Gist options
  • Save ichramm/149a50efd1d2a9c35265f22120a29afb to your computer and use it in GitHub Desktop.
Save ichramm/149a50efd1d2a9c35265f22120a29afb to your computer and use it in GitHub Desktop.
error classifier
(ns error-classifier
(:require [clojure.test :refer :all]))
(def known-errors ["Anonymous access not allowed"
"Invalid trace, not on the current datasource"
"sync placeholders were requested with a limit of"
"constraint \"company_campaign_dismisses_pkey\""
"constraint \"company_placeholder_customers_reached_pkey"
"constraint \"company_campaign_banner_customers_reached_pkey\""
"constraint \"company_channel_customers_reached_pkey\""
"constraint \"company_channel_conversions_pkey\""
"value too long for type character varying"
"Trail already finished on sync page"
"Invalid tracking data for trail"
"Trail is gone"
"Invalid trail identifier"
"Trail action without triggering action found"
"Trail has already completed for another campaign"
"campaign-priorities.invoke" ; import errors (should be warnings)
])
(defn classify [file]
(let [counters (->> (reduce #(assoc % %2 {:count 0}) {} known-errors)
(merge {"other" {:count 0}}))]
(with-open [rdr (clojure.java.io/reader file)]
(loop [lines (line-seq rdr)
counters counters]
(if (seq lines)
(let [line (first lines)
s (some #(re-find (re-pattern %) line) known-errors)]
(if s
(recur (rest lines) (update-in counters [s :count] inc))
(do
(println "Other error" line)
(recur (rest lines) (update-in counters ["other" :count] inc)))))
(->> counters
(map (fn [[key val]] (merge val {:key key})))
(sort-by :count)
reverse
(every? #(do (println (format "%1$6d: %2$s" (:count %) (:key %)))
true))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment