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