0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 16:30:37 -05:00

Fix issues from previous refactor peer review

This commit is contained in:
Andrey Antukh 2022-03-09 17:29:33 +01:00
parent 9841a39d04
commit f7bb08382c
6 changed files with 23 additions and 33 deletions

View file

@ -141,8 +141,7 @@
(s/def ::host ::us/string) (s/def ::host ::us/string)
(s/def ::http-server-port ::us/integer) (s/def ::http-server-port ::us/integer)
(s/def ::http-server-host ::us/string) (s/def ::http-server-host ::us/string)
(s/def ::http-server-min-threads ::us/integer) (s/def ::http-server-io-threads ::us/integer)
(s/def ::http-server-max-threads ::us/integer)
(s/def ::http-session-idle-max-age ::dt/duration) (s/def ::http-session-idle-max-age ::dt/duration)
(s/def ::http-session-updater-batch-max-age ::dt/duration) (s/def ::http-session-updater-batch-max-age ::dt/duration)
(s/def ::http-session-updater-batch-max-size ::us/integer) (s/def ::http-session-updater-batch-max-size ::us/integer)
@ -243,8 +242,7 @@
::host ::host
::http-server-host ::http-server-host
::http-server-port ::http-server-port
::http-server-max-threads ::http-server-io-threads
::http-server-min-threads
::http-session-idle-max-age ::http-session-idle-max-age
::http-session-updater-batch-max-age ::http-session-updater-batch-max-age
::http-session-updater-batch-max-size ::http-session-updater-batch-max-size

View file

@ -10,6 +10,7 @@
[app.common.exceptions :as ex] [app.common.exceptions :as ex]
[app.common.logging :as l] [app.common.logging :as l]
[app.common.spec :as us] [app.common.spec :as us]
[app.config :as cf]
[app.http.doc :as doc] [app.http.doc :as doc]
[app.http.errors :as errors] [app.http.errors :as errors]
[app.http.middleware :as middleware] [app.http.middleware :as middleware]
@ -35,9 +36,7 @@
(s/def ::host ::us/string) (s/def ::host ::us/string)
(s/def ::name ::us/string) (s/def ::name ::us/string)
(s/def ::executors (s/map-of keyword? ::wrk/executor)) (s/def ::executors (s/map-of keyword? ::wrk/executor))
(s/def ::io-threads ::cf/http-server-io-threads)
;; (s/def ::max-threads ::cf/http-server-max-threads)
;; (s/def ::min-threads ::cf/http-server-min-threads)
(defmethod ig/prep-key ::server (defmethod ig/prep-key ::server
[_ cfg] [_ cfg]
@ -48,7 +47,7 @@
(defmethod ig/pre-init-spec ::server [_] (defmethod ig/pre-init-spec ::server [_]
(s/keys :req-un [::port ::host ::name ::executors] (s/keys :req-un [::port ::host ::name ::executors]
:opt-un [::router ::handler])) :opt-un [::router ::handler ::io-threads]))
(defmethod ig/init-key ::server (defmethod ig/init-key ::server
[_ {:keys [handler router port name host executors] :as cfg}] [_ {:keys [handler router port name host executors] :as cfg}]
@ -97,7 +96,7 @@
(handler request respond (handler request respond
(fn [cause] (fn [cause]
(l/error :hint "unexpected error processing request" (l/error :hint "unexpected error processing request"
::l/context (errors/get-error-context request cause) ::l/context (errors/get-context request)
:query-string (yrq/query request) :query-string (yrq/query request)
:cause cause) :cause cause)
(respond (yrs/response 500 "internal server error"))))))) (respond (yrs/response 500 "internal server error")))))))

View file

@ -21,18 +21,17 @@
(yrq/get-header request "x-real-ip") (yrq/get-header request "x-real-ip")
(yrq/remote-addr request))) (yrq/remote-addr request)))
(defn get-error-context (defn get-context
[request error] [request]
(let [data (ex-data error)] (merge
(merge {:path (:uri request)
{:path (:uri request) :method (:request-method request)
:method (:request-method request) :params (:params request)
:params (:params request) :ip-addr (parse-client-ip request)
:ip-addr (parse-client-ip request) :profile-id (:profile-id request)}
:profile-id (:profile-id request)} (let [headers (:headers request)]
(let [headers (:headers request)] {:user-agent (get headers "user-agent")
{:user-agent (get headers "user-agent") :frontend-version (get headers "x-frontend-version" "unknown")})))
:frontend-version (get headers "x-frontend-version" "unknown")}))))
(defmulti handle-exception (defmulti handle-exception
(fn [err & _rest] (fn [err & _rest]
@ -61,7 +60,7 @@
(let [edata (ex-data error) (let [edata (ex-data error)
explain (us/pretty-explain edata)] explain (us/pretty-explain edata)]
(l/error ::l/raw (ex-message error) (l/error ::l/raw (ex-message error)
::l/context (get-error-context request error) ::l/context (get-context request)
:cause error) :cause error)
(yrs/response :status 500 (yrs/response :status 500
:body {:type :server-error :body {:type :server-error
@ -87,7 +86,7 @@
(handle-exception (:handling edata) request) (handle-exception (:handling edata) request)
(do (do
(l/error ::l/raw (ex-message error) (l/error ::l/raw (ex-message error)
::l/context (get-error-context request error) ::l/context (get-context request)
:cause error) :cause error)
(yrs/response 500 {:type :server-error (yrs/response 500 {:type :server-error
:code :unexpected :code :unexpected
@ -98,7 +97,7 @@
[error request] [error request]
(let [state (.getSQLState ^java.sql.SQLException error)] (let [state (.getSQLState ^java.sql.SQLException error)]
(l/error ::l/raw (ex-message error) (l/error ::l/raw (ex-message error)
::l/context (get-error-context request error) ::l/context (get-context request)
:cause error) :cause error)
(cond (cond
(= state "57014") (= state "57014")

View file

@ -113,7 +113,8 @@
:host (cf/get :http-server-host) :host (cf/get :http-server-host)
:router (ig/ref :app.http/router) :router (ig/ref :app.http/router)
:metrics (ig/ref :app.metrics/metrics) :metrics (ig/ref :app.metrics/metrics)
:executors (ig/ref :app.worker/executors)} :executors (ig/ref :app.worker/executors)
:io-threads (cf/get :http-server-io-threads)}
:app.http/router :app.http/router
{:assets (ig/ref :app.http.assets/handlers) {:assets (ig/ref :app.http.assets/handlers)

View file

@ -262,10 +262,3 @@
:gauge (make-gauge props) :gauge (make-gauge props)
:summary (make-summary props) :summary (make-summary props)
:histogram (make-histogram props))) :histogram (make-histogram props)))
;; (defn instrument-jetty!
;; [^CollectorRegistry registry ^StatisticsHandler handler]
;; (doto (JettyStatisticsCollector. handler)
;; (.register registry))
;; nil)

View file

@ -259,7 +259,7 @@
;; A task responsible to permanently delete already marked as deleted ;; A task responsible to permanently delete already marked as deleted
;; storage files. The storage objects are practically never marked to ;; storage files. The storage objects are practically never marked to
;; be deleted directly by the api call. The touched-gc is responsible ;; be deleted directly by the api call. The touched-gc is responsible
;; collect the usage of the object and mark it as deleted. ;; of collecting the usage of the object and mark it as deleted.
(declare sql:retrieve-deleted-objects-chunk) (declare sql:retrieve-deleted-objects-chunk)