Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(maint) change maint-mode state of status implementation to :starting #1753

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions documentation/api/status/v1/status.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ following:
* `detail_level`: info is currently the only level
* `service_status_version`: version of the status API
* `service_version`: version of PuppetDB
* `state`: "running" if read and write databases are up, "error" if down
* `state`: short description of PuppetDB's current state:
* "starting" if PuppetDB is in maintenance mode
* "running" if not in maintenance mode and read and write databases are up
* "error" if the read or write databases are down.
* `status`:
* `maintenance_mode?`: indicates whether PuppetDB is in maintenance mode.
PuppetDB enters maintenance mode at startup and exits it after completing any
pending migrations and initial data synchronization (when using HA).
While in maintenance mode PuppetDB will not respond to queries.
* `read_db_up?`: indicates whether the read database is responding to queries
* `write_db_up?`: indicates whether the write database is responding to queries
* `queue_depth`: depth of the command queue
* `queue_depth`: depth of the command queue. If the queue is not yet
initialized, this field will be null.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
(def tk-version "1.1.1")
(def tk-jetty9-version "1.3.1")
(def ks-version "1.1.0")
(def tk-status-version "0.2.0")
(def tk-status-version "0.2.1")

(def pdb-jvm-opts
(case (System/getProperty "java.specification.version")
Expand Down
18 changes: 11 additions & 7 deletions src/puppetlabs/puppetdb/pdb_routing.clj
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,20 @@
1
(fn [level]
(let [globals (shared-globals)
queue-depth (->> [:command-processing :mq :endpoint]
(get-in config)
(mq/queue-size "localhost"))
queue-depth (try (->> [:command-processing :mq :endpoint]
(get-in config)
(mq/queue-size "localhost"))
(catch Exception _
nil))
read-db-up? (sutils/db-up? (:scf-read-db globals))
write-db-up? (sutils/db-up? (:scf-write-db globals))
state (if (and read-db-up? write-db-up?)
:running
:error)]
maintenance-mode? (maint-mode?)
state (cond
maintenance-mode? :starting
(and read-db-up? write-db-up?) :running
:else :error)]
{:state state
:status {:maintenance_mode? (maint-mode?)
:status {:maintenance_mode? maintenance-mode?
:queue_depth queue-depth
:read_db_up? read-db-up?
:write_db_up? write-db-up?}}))))
Expand Down
13 changes: 7 additions & 6 deletions src/puppetlabs/puppetdb/scf/storage_utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,10 @@
(defn db-up?
[db-spec]
(utils/with-timeout 1000 false
(jdbc/with-transacted-connection db-spec
(try (let [select-42 "SELECT (a - b) AS answer FROM (VALUES ((7 * 7), 7)) AS x(a, b)"
[{:keys [answer]}] (jdbc/query [select-42])]
(= answer 42))
(catch Exception _
false)))))
(try
(jdbc/with-transacted-connection db-spec
(let [select-42 "SELECT (a - b) AS answer FROM (VALUES ((7 * 7), 7)) AS x(a, b)"
[{:keys [answer]}] (jdbc/query [select-42])]
(= answer 42)))
(catch Exception _
false))))
12 changes: 6 additions & 6 deletions test/puppetlabs/puppetdb/status_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
(testing "status returns as expected when in maintenance mode"
(with-redefs [puppetlabs.puppetdb.pdb-routing/maint-mode? (constantly true)]
(svc-utils/with-puppetdb-instance
(let [{:keys [body] :as pdb-resp} (-> svc-utils/*base-url*
(assoc :prefix "/status/v1/services")
base-url->str-with-prefix
client/get)
(let [{:keys [body status]} (-> svc-utils/*base-url*
(assoc :prefix "/status/v1/services")
base-url->str-with-prefix
(client/get {:throw-exceptions false}))
pdb-status (:puppetdb-status (json/parse-string body true))]
(tu/assert-success! pdb-resp)
(is (= "running" (:state pdb-status)))
(is (= 503 status))
(is (= "starting" (:state pdb-status)))
(is (= {:maintenance_mode? true
:read_db_up? true
:write_db_up? true
Expand Down