Skip to content
Draft
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
12 changes: 6 additions & 6 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
[commons-codec "1.22.1"]
[commons-io "2.22.0"]
[grimradical/clj-semver "0.3.0" :exclusions [org.clojure/clojure]]
[io.dropwizard.metrics/metrics-core "3.2.6"]
[io.dropwizard.metrics5/metrics-core "5.0.7"]
[lambdaisland/uri "1.19.155"]
[liberator "0.15.3"]
;; NOTE: Versions after 8.1 bring in Jackson 3.x.
Expand All @@ -76,15 +76,15 @@
[org.openvoxproject/kitchensink "3.5.8" :classifier "test"]
[org.openvoxproject/rbac-client "1.3.0"]
[org.openvoxproject/rbac-client "1.3.0" :classifier "test"]
[org.openvoxproject/ring-middleware "2.2.1"]
[org.openvoxproject/ring-middleware "2.2.1-SNAPSHOT"]
[org.openvoxproject/ssl-utils "3.7.1"]
[org.openvoxproject/trapperkeeper "5.0.5"]
[org.openvoxproject/trapperkeeper "5.0.5" :classifier "test"]
[org.openvoxproject/trapperkeeper-comidi-metrics "1.1.1"]
[org.openvoxproject/trapperkeeper-comidi-metrics "1.1.1-SNAPSHOT"]
[org.openvoxproject/trapperkeeper-authorization "2.4.1"]
[org.openvoxproject/trapperkeeper-filesystem-watcher "1.6.1"]
[org.openvoxproject/trapperkeeper-metrics "2.3.2"]
[org.openvoxproject/trapperkeeper-metrics "2.3.2" :classifier "test"]
[org.openvoxproject/trapperkeeper-metrics "2.3.1-SNAPSHOT"]
[org.openvoxproject/trapperkeeper-metrics "2.3.1-SNAPSHOT" :classifier "test"]
[org.openvoxproject/trapperkeeper-scheduler "1.4.1"]
[org.openvoxproject/trapperkeeper-status "1.5.1"]
[org.openvoxproject/trapperkeeper-webserver "12.1.1"]
Expand All @@ -106,7 +106,7 @@
[clj-commons/fs]
[commons-io]
[grimradical/clj-semver :exclusions [org.clojure/clojure]]
[io.dropwizard.metrics/metrics-core]
[io.dropwizard.metrics5/metrics-core]
[liberator]
;; We do not currently use this dependency directly, but
;; we have documentation that shows how users can use it to
Expand Down
18 changes: 6 additions & 12 deletions src/clj/puppetlabs/services/jruby/jruby_metrics_core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[puppetlabs.comidi :as comidi]
[puppetlabs.i18n.core :refer [trs]]
[puppetlabs.services.protocols.jruby-puppet :as jruby-protocol])
(:import (com.codahale.metrics MetricRegistry Gauge Counter Histogram Meter Timer)
(:import (io.dropwizard.metrics5 MetricFilter MetricRegistry Gauge Counter Histogram Meter Timer)
(clojure.lang Atom IFn)
(java.time ZoneOffset ZonedDateTime)
(java.time.format DateTimeFormatter)
Expand Down Expand Up @@ -201,15 +201,8 @@
(schema/defn borrow-timers :- java.util.Map
"Returns a map of borrow timers from JRuby Metrics"
[{:keys [metric-registry hostname]} :- JRubyMetrics]
(let [metric-namespace (metrics/host-metric-name hostname "jruby.borrow-timer")
;; TODO: v4.0 of Dropwizard Metrics has a MetricFilter/startsWith
;; static method that returns a filter which can be passed
;; directly to .getTimers.
metric-filter (partial filter (fn [[k _]]
(str/starts-with? k metric-namespace)))]
(->> (.getTimers metric-registry)
metric-filter
(into {}))))
(let [metric-namespace (metrics/host-metric-name hostname "jruby.borrow-timer")]
(.getTimers metric-registry (MetricFilter/startsWith metric-namespace))))

(schema/defn summarize-borrow-timers
"Generates a summary for each JRuby borrow timer
Expand All @@ -219,10 +212,11 @@
[{:keys [hostname] :as metrics} :- JRubyMetrics]
(let [timer-namespace (metrics/host-metric-name hostname "jruby.borrow-timer")
get-name (fn [timer-name]
(if (= timer-namespace timer-name)
(let [timer-name (str timer-name)]
(if (= timer-namespace timer-name)
"total"
(str/replace-first timer-name
(str timer-namespace ".") "")))
(str timer-namespace ".") ""))))
timer-summary (fn [timer]
(let [snapshot (.getSnapshot timer)]
{:count (.getCount timer)
Expand Down
2 changes: 1 addition & 1 deletion src/clj/puppetlabs/services/jruby/jruby_puppet_core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
(:import (com.puppetlabs.puppetserver PuppetProfiler JRubyPuppet)
(clojure.lang IFn)
(java.util HashMap)
(com.codahale.metrics MetricRegistry)))
(io.dropwizard.metrics5 MetricRegistry)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Constants
Expand Down
10 changes: 5 additions & 5 deletions src/clj/puppetlabs/services/master/master_core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
[schema.core :as schema]
[slingshot.slingshot :refer [throw+ try+]])
(:import (clojure.lang IFn)
(com.codahale.metrics Gauge MetricRegistry)
(io.dropwizard.metrics5 Gauge MetricRegistry)
(com.fasterxml.jackson.core JsonParseException)
(java.io FileInputStream)
(java.lang.management ManagementFactory)
Expand Down Expand Up @@ -1205,10 +1205,10 @@

(defn register-gauge!
[registry hostname metric-name metric-fn]
(.register registry (metrics/host-metric-name hostname metric-name)
(proxy [Gauge] []
(getValue []
(metric-fn)))))
(.registerGauge registry (metrics/host-metric-name hostname metric-name)
(proxy [Gauge] []
(getValue []
(metric-fn)))))

(schema/defn register-jvm-metrics!
[registry :- MetricRegistry
Expand Down
74 changes: 52 additions & 22 deletions src/clj/puppetlabs/services/master/master_service.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns puppetlabs.services.master.master-service
(:require [clojure.tools.logging :as log]
[clojure.walk :as walk]
[puppetlabs.trapperkeeper.core :refer [defservice]]
[puppetlabs.puppetserver.certificate-authority :as ca]
[puppetlabs.puppetserver.jruby-request :as jruby-request]
Expand All @@ -14,36 +15,55 @@

(def master-service-status-version 1)

;; Dropwizard 5 JMX rejects wildcard pattern characters in ObjectName values.
;; We replace route wildcards with a stable token before metrics registration.
(def metrics-route-wildcard-token "ANY")

(defn sanitize-metrics-route-id
[route-id]
(if (string? route-id)
(str/replace route-id "*" metrics-route-wildcard-token)
route-id))

(defn sanitize-route-metadata-for-metrics
[route-metadata]
(walk/postwalk
(fn [node]
(if (and (map? node) (string? (:route-id node)))
(update node :route-id sanitize-metrics-route-id)
node))
route-metadata))

;; Default list of allowed histograms/timers
(def default-metrics-allowed-hists
["http.active-histo"
"http.puppet-v3-catalog-/*/-requests"
"http.puppet-v3-environment-/*/-requests"
"http.puppet-v3-environment_classes-/*/-requests"
"http.puppet-v3-catalog-/ANY/-requests"
"http.puppet-v3-environment-/ANY/-requests"
"http.puppet-v3-environment_classes-/ANY/-requests"
"http.puppet-v3-environments-requests"
"http.puppet-v3-file_bucket_file-/*/-requests"
"http.puppet-v3-file_content-/*/-requests"
"http.puppet-v3-file_metadata-/*/-requests"
"http.puppet-v3-file_metadatas-/*/-requests"
"http.puppet-v3-node-/*/-requests"
"http.puppet-v3-report-/*/-requests"
"http.puppet-v3-static_file_content-/*/-requests"])
"http.puppet-v3-file_bucket_file-/ANY/-requests"
"http.puppet-v3-file_content-/ANY/-requests"
"http.puppet-v3-file_metadata-/ANY/-requests"
"http.puppet-v3-file_metadatas-/ANY/-requests"
"http.puppet-v3-node-/ANY/-requests"
"http.puppet-v3-report-/ANY/-requests"
"http.puppet-v3-static_file_content-/ANY/-requests"])

;; Default list of allowed values/counts
(def default-metrics-allowed-vals
["http.active-requests"
"http.puppet-v3-catalog-/*/-percentage"
"http.puppet-v3-environment-/*/-percentage"
"http.puppet-v3-environment_classes-/*/-percentage"
"http.puppet-v3-catalog-/ANY/-percentage"
"http.puppet-v3-environment-/ANY/-percentage"
"http.puppet-v3-environment_classes-/ANY/-percentage"
"http.puppet-v3-environments-percentage"
"http.puppet-v3-file_bucket_file-/*/-percentage"
"http.puppet-v3-file_content-/*/-percentage"
"http.puppet-v3-file_metadata-/*/-percentage"
"http.puppet-v3-file_metadatas-/*/-percentage"
"http.puppet-v3-node-/*/-percentage"
"http.puppet-v3-report-/*/-percentage"
"http.puppet-v3-static_file_content-/*/-percentage"
"http.puppet-v3-status-/*/-percentage"
"http.puppet-v3-file_bucket_file-/ANY/-percentage"
"http.puppet-v3-file_content-/ANY/-percentage"
"http.puppet-v3-file_metadata-/ANY/-percentage"
"http.puppet-v3-file_metadatas-/ANY/-percentage"
"http.puppet-v3-node-/ANY/-percentage"
"http.puppet-v3-report-/ANY/-percentage"
"http.puppet-v3-static_file_content-/ANY/-percentage"
"http.puppet-v3-status-/ANY/-percentage"
"http.total-requests"
; num-cpus is registered in trapperkeeper-comidi-metrics, see
; https://github.com/puppetlabs/trapperkeeper-comidi-metrics/blob/0.1.1/src/puppetlabs/metrics/http.clj#L117-L120
Expand Down Expand Up @@ -151,16 +171,26 @@
boltlib-path
certname))
routes (comidi/context path ring-app)
route-metadata (comidi/route-metadata routes)
route-metadata (-> routes
comidi/route-metadata
sanitize-route-metadata-for-metrics)
comidi-handler (comidi/routes->handler routes)
registry (get-metrics-registry :puppetserver)
http-metrics (http-metrics/initialize-http-metrics!
registry
metrics-server-id
route-metadata)
http-client-metric-ids-for-status (atom master-core/puppet-server-http-client-metrics-for-status)
;; Middleware to sanitize live request route-ids so they match
;; the sanitized metric names registered during initialization.
wrap-with-route-id-sanitization (fn [handler]
(fn [req]
(if (get-in req [:route-info :route-id])
(handler (update-in req [:route-info :route-id] sanitize-metrics-route-id))
(handler req))))
ring-handler (-> comidi-handler
(http-metrics/wrap-with-request-metrics http-metrics)
wrap-with-route-id-sanitization
(comidi/wrap-with-route-metadata routes))
hostcrl (get-in config [:puppetserver :hostcrl])]
(log-java-deprecation-message (System/getProperty "java.version"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns puppetlabs.services.puppet-profiler.puppet-profiler-core
(:import (com.codahale.metrics MetricRegistry)
(:import (io.dropwizard.metrics5 MetricRegistry)
(com.puppetlabs.puppetserver MetricsPuppetProfiler PuppetProfiler))
(:require [clojure.string :as str]
[schema.core :as schema]
Expand Down
14 changes: 10 additions & 4 deletions src/java/com/puppetlabs/puppetserver/MetricsPuppetProfiler.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.puppetlabs.puppetserver;

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import io.dropwizard.metrics5.MetricRegistry;
import io.dropwizard.metrics5.Timer;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -190,8 +190,14 @@ private Map<String, Timer> getOrCreateTimersByIDs(String[] metric_id) {
}

private String getMetricName(List<String> metric_id) {
metric_id.add(0, hostname);
return MetricRegistry.name("puppetlabs", metric_id.toArray(new String[metric_id.size()]));
StringBuilder sb = new StringBuilder();
sb.append("puppetlabs.").append(hostname);
for (String segment : metric_id) {
if (segment != null && !segment.isEmpty()) {
sb.append('.').append(segment);
}
}
return sb.toString();
}

private void registerMetricName(String metric_name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
[puppetlabs.trapperkeeper.services.protocols.metrics :as metrics-protocol]
[puppetlabs.trapperkeeper.testutils.bootstrap :as tk-testutils]
[puppetlabs.trapperkeeper.testutils.logging :as logutils])
(:import (com.codahale.metrics MetricRegistry)
(:import (io.dropwizard.metrics5 MetricRegistry)
(java.io ByteArrayOutputStream)
(org.jruby RubyInstanceConfig$CompileMode RubyInstanceConfig$ProfilingMode)
(org.jruby.embed EvalFailedException)))
Expand Down
Loading
Loading