Skip to content

Commit

Permalink
config moved to ziggurat.config
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakshya Gupta committed Jul 6, 2022
1 parent b19f019 commit 862fccf
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
43 changes: 23 additions & 20 deletions src/ziggurat/config.clj
Expand Up @@ -8,9 +8,9 @@
(:import (java.util Properties)
[org.apache.kafka.common.config SaslConfigs])
(:gen-class
:methods [^{:static true} [get [String] Object]
^{:static true} [getIn [java.lang.Iterable] Object]]
:name tech.gojek.ziggurat.internal.Config))
:methods [^{:static true} [get [String] Object]
^{:static true} [getIn [java.lang.Iterable] Object]]
:name tech.gojek.ziggurat.internal.Config))

(def config-file "config.edn")

Expand All @@ -25,10 +25,10 @@
:username "guest"
:password "guest"
:channel-timeout 2000
:publish-retry {:back-off-ms 5000
:non-recoverable-exception {:enabled true
:back-off-ms 5000
:count 5}}}
:publish-retry {:back-off-ms 5000
:non-recoverable-exception {:enabled true
:back-off-ms 5000
:count 5}}}
:jobs {:instant {:worker-count 4
:prefetch-count 4}}
:rabbit-mq {:delay {:queue-name "%s_delay_queue"
Expand Down Expand Up @@ -77,9 +77,9 @@
(declare config)

(defstate config
:start (let [config-values-from-env (config-from-env config-file)
app-name (-> config-values-from-env :ziggurat :app-name)]
(deep-merge (interpolate-config default-config app-name) config-values-from-env)))
:start (let [config-values-from-env (config-from-env config-file)
app-name (-> config-values-from-env :ziggurat :app-name)]
(deep-merge (interpolate-config default-config app-name) config-values-from-env)))

(defn ziggurat-config []
(get config :ziggurat))
Expand Down Expand Up @@ -169,9 +169,9 @@
(defn- normalize-value
[v]
(str/trim
(cond
(keyword? v) (name v)
:else (str v))))
(cond
(keyword? v) (name v)
:else (str v))))

(defn set-property
[mapping-table p k v]
Expand All @@ -195,8 +195,8 @@
(defn- add-jaas-properties
[properties jaas-config]
(if (some? jaas-config)
(let [username (get jaas-config :username)
password (get jaas-config :password)
(let [username (get jaas-config :username)
password (get jaas-config :password)
mechanism (get jaas-config :mechanism)]
(doto properties
(.put SaslConfigs/SASL_JAAS_CONFIG (create-jaas-properties username password mechanism))))
Expand All @@ -222,11 +222,11 @@
:mechanism <>}}}
"
(let [ssl-configs-enabled (:enabled ssl-config-map)
jaas-config (get ssl-config-map :jaas)]
jaas-config (get ssl-config-map :jaas)]
(if (true? ssl-configs-enabled)
(as-> properties pr
(add-jaas-properties pr jaas-config)
(reduce-kv set-property-fn pr ssl-config-map))
(add-jaas-properties pr jaas-config)
(reduce-kv set-property-fn pr ssl-config-map))
properties)))

(defn build-properties
Expand All @@ -249,11 +249,14 @@
"
[set-property-fn config-map]
(as-> (Properties.) pr
(build-ssl-properties pr set-property-fn (ssl-config))
(reduce-kv set-property-fn pr config-map)))
(build-ssl-properties pr set-property-fn (ssl-config))
(reduce-kv set-property-fn pr config-map)))

(def build-consumer-config-properties (partial build-properties (partial set-property consumer-config-mapping-table)))

(def build-producer-config-properties (partial build-properties (partial set-property producer-config-mapping-table)))

(def build-streams-config-properties (partial build-properties (partial set-property streams-config-mapping-table)))

(defn get-configured-retry-count []
(-> (ziggurat-config) :retry :count))
4 changes: 2 additions & 2 deletions src/ziggurat/mapper.clj
@@ -1,7 +1,7 @@
(ns ziggurat.mapper
(:require [clojure.string :as str]
[sentry-clj.async :as sentry]
[ziggurat.config :refer [ziggurat-config]]
[ziggurat.config :refer [ziggurat-config get-configured-retry-count]]
[ziggurat.messaging.producer :as producer]
[ziggurat.metrics :as metrics]
[ziggurat.new-relic :as nr]
Expand Down Expand Up @@ -39,7 +39,7 @@
failure-metric "failure"
dead-letter-metric "dead-letter"
multi-message-processing-namespaces [message-processing-namespaces [message-processing-namespace]]
user-payload (create-user-payload message-payload (producer/get-configured-retry-count))]
user-payload (create-user-payload message-payload (get-configured-retry-count))]
(clog/with-logging-context {:consumer-group topic-entity-name}
(nr/with-tracing "job" new-relic-transaction-name
(try
Expand Down
3 changes: 0 additions & 3 deletions src/ziggurat/messaging/producer.clj
Expand Up @@ -154,9 +154,6 @@
(defn get-channel-retry-count [topic-entity channel]
(:count (channel-retry-config topic-entity channel)))

(defn get-configured-retry-count []
(-> (ziggurat-config) :retry :count))

(defn- get-channel-queue-timeout-or-default-timeout [topic-entity channel]
(let [channel-queue-timeout-ms (:queue-timeout-ms (channel-retry-config topic-entity channel))
queue-timeout-ms (get-in (rabbitmq-config) [:delay :queue-timeout-ms])]
Expand Down
2 changes: 1 addition & 1 deletion test/ziggurat/mapper_test.clj
@@ -1,7 +1,7 @@
(ns ziggurat.mapper-test
(:require [clojure.test :refer :all]
[schema.core :as s]
[ziggurat.config :refer [ziggurat-config]]
[ziggurat.config :refer [ziggurat-config get-configured-retry-count]]
[ziggurat.fixtures :as fix]
[ziggurat.mapper :refer :all]
[ziggurat.messaging.connection :refer [producer-connection]]
Expand Down

0 comments on commit 862fccf

Please sign in to comment.