Conversation
kitallis
left a comment
There was a problem hiding this comment.
Mostly some code and convention changes.
|
|
||
| (defn init! [] | ||
| (when (config/lookup :integrate-with-wonko?) | ||
| (wonko/init! "agrajag" |
There was a problem hiding this comment.
Add this to configuration.
| (try | ||
| (heartbeat) | ||
| (standby-cluster) | ||
| (failed-cluster) |
There was a problem hiding this comment.
(standby-cluster) and (failed-cluster) both call (repmgr/nodes-in-cluster): which is not memoized in between. We should call it only once during the duration of this.
| (heartbeat) | ||
| (standby-cluster) | ||
| (failed-cluster) | ||
| (master-db) |
There was a problem hiding this comment.
The same goes for this (master-db) call. This function internally calls (cluster-status), in which case if you add up the two calls before this, we end up calling (cluster-status) (a shell out) 3 times to post metrics. We only need to do this once.
| :name latest-master | ||
| :cluster latest-cluster)))) | ||
|
|
||
| (defn- check-if-new [master-data zk-data] |
There was a problem hiding this comment.
Better name for this function. Maybe (new-master?)
| ;; (1. publish) | ||
| ;; (2. exit) | ||
|
|
||
| (defn- check-if-accurate [] |
There was a problem hiding this comment.
Better name for this function. Since this is not a boolean check anymore and returns the coalesced version from 2 sources of truth. We can call it coalesced-cluster.
| (:event-timestamp zk-data)) | ||
| 0)) | ||
|
|
||
| (defn check-and-update-status [] |
There was a problem hiding this comment.
This can just be (update-status) or simply (update).
|
|
||
| (defn nodes-in-cluster [] | ||
| (let [cluster (cluster-status) | ||
| cluster-map-list (for [role ["master" "FAILED" "standby"] |
There was a problem hiding this comment.
Put them in a var. Convert into a single-cased version – preferably, lowercase – in the input before checking.
| (deserializer bytes)) | ||
| version (-> zk-data :stat :version)] | ||
| (if (predicate? deserialized) | ||
| (zk/set-data client path (serializer new-data) version))) |
There was a problem hiding this comment.
Use the internal (set-data) which has the retry mechanism.
| (catch KeeperException$SessionExpiredException see ::reinit) | ||
| (catch KeeperException$ConnectionLossException cle ::reinit))] | ||
| (condp = result | ||
| ::reinit (do (init!) |
There was a problem hiding this comment.
Try to log the exception. This is written in a way where we only return ::reinit from the catch block and we don't have access to see or cle. We can either rewrite it to do the work right in the catch block or return a map of the result and then log the exception from it in the condp block.
Work in progress.