Fixes logging to not cause out of control costs
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
[clj-http.client :as http]
|
||||
[auto-ap.logging :as alog]
|
||||
[config.core :refer [env]]
|
||||
[com.brunobonacci.mulog :as mu]))
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[com.brunobonacci.mulog.common.json :as j]))
|
||||
|
||||
(defn get-container-data []
|
||||
(try
|
||||
@@ -16,7 +17,7 @@
|
||||
result)
|
||||
(catch Exception e
|
||||
(alog/error ::no-container-tags
|
||||
:error e)
|
||||
:error e)
|
||||
{})))
|
||||
|
||||
(mount/defstate container-data
|
||||
@@ -32,29 +33,41 @@
|
||||
:start (get-container-tags)
|
||||
:stop nil)
|
||||
|
||||
(defn capture-invalid-json
|
||||
[events]
|
||||
(filter
|
||||
(fn [event]
|
||||
(try
|
||||
(j/to-json event)
|
||||
true
|
||||
(catch Exception _
|
||||
(mu/log ::invalid-json-value :value (pr-str event))
|
||||
false)))
|
||||
events))
|
||||
|
||||
(defn set-logging-context []
|
||||
(when (seq container-data)
|
||||
|
||||
(mu/start-publisher! {:type :console-json
|
||||
:transform (fn [events]
|
||||
(map (fn [{:keys [mulog/duration mulog/event-name mulog/namespace] :as e}]
|
||||
(cond-> e
|
||||
duration (assoc :duration duration
|
||||
:duration-ms (quot duration 1000000))
|
||||
true (assoc :event-name event-name
|
||||
:namespace namespace)))
|
||||
events))})
|
||||
(->> events
|
||||
capture-invalid-json
|
||||
(map (fn [{:keys [mulog/duration mulog/event-name mulog/namespace] :as e}]
|
||||
(cond-> e
|
||||
duration (assoc :duration duration
|
||||
:duration-ms (quot duration 1000000))
|
||||
true (assoc :event-name event-name
|
||||
:namespace namespace))))))})
|
||||
(mu/set-global-context!
|
||||
{:container (:DockerId container-data)
|
||||
:ip (-> container-data :Networks first :IPv4Addresses first)
|
||||
:env (:dd-env env)
|
||||
:service (or
|
||||
(System/getenv "INTEGREAT_JOB")
|
||||
(:dd-service env))})))
|
||||
(System/getenv "INTEGREAT_JOB")
|
||||
(:dd-service env))})))
|
||||
|
||||
(defn stop-logging-context []
|
||||
(when (seq container-data)
|
||||
))
|
||||
(when (seq container-data)))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(mount/defstate logging-context
|
||||
@@ -67,5 +80,3 @@
|
||||
(str "service:" (:dd-service env))}
|
||||
container-tags))
|
||||
:stop (statsd/shutdown!))
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
(defn raw-graphql-ids
|
||||
([args] (raw-graphql-ids (dc/db conn) args))
|
||||
([db args]
|
||||
(auto-ap.logging/peek args)
|
||||
(let [valid-clients (extract-client-ids (:clients args)
|
||||
(:client-id args)
|
||||
(when (:client-code args)
|
||||
|
||||
@@ -184,7 +184,7 @@
|
||||
|
||||
|
||||
(auto-ap.datomic/pull-id (dc/db conn) [:client/code "NGRV"])
|
||||
|
||||
|
||||
(->> (dc/q '[:find (pull ?ba [:bank-account/name :bank-account/code {:client/_bank-accounts [:client/code]}])
|
||||
:in $ $$
|
||||
:where
|
||||
@@ -198,8 +198,4 @@
|
||||
(map (fn [[ba]]
|
||||
(println ba)
|
||||
[(-> ba :client/_bank-accounts :client/code) (:bank-account/code ba) (:bank-account/name ba)]))
|
||||
( #(clojure.data.csv/write-csv *out* % :separator \tab)))
|
||||
|
||||
|
||||
)
|
||||
|
||||
(#(clojure.data.csv/write-csv *out* % :separator \tab))))
|
||||
|
||||
Reference in New Issue
Block a user