Compare commits

..

No commits in common. "8626b91b16fcfa97e85d80b79a04ddf9a3e19e60" and "ab2473bdf4c4a7c90fafbaada97eeb31eaf6739e" have entirely different histories.

5 changed files with 43 additions and 13 deletions

View file

@ -4,7 +4,7 @@
:license {:name "Apache License, Version 2.0" :license {:name "Apache License, Version 2.0"
:url "https://www.apache.org/licenses/LICENSE-2.0.html"} :url "https://www.apache.org/licenses/LICENSE-2.0.html"}
:dependencies [[org.clojure/clojure "1.11.1" :scope "provided"] :dependencies [[org.clojure/clojure "1.11.1" :scope "provided"]
[org.clojure/tools.reader "1.4.0"] [org.clojure/tools.reader "1.3.7"]
[aero "1.1.6"] [aero "1.1.6"]
[orchestra "2021.01.01-1"] [orchestra "2021.01.01-1"]
[expound "0.9.0"] [expound "0.9.0"]
@ -25,8 +25,8 @@
:uberjar {:aot :all :uberjar {:aot :all
:main dda.c4k-common.uberjar :main dda.c4k-common.uberjar
:uberjar-name "c4k-common-standalone.jar" :uberjar-name "c4k-common-standalone.jar"
:dependencies [[org.clojure/tools.cli "1.1.230"] :dependencies [[org.clojure/tools.cli "1.0.219"]
[ch.qos.logback/logback-classic "1.5.0" [ch.qos.logback/logback-classic "1.4.14"
:exclusions [com.sun.mail/javax.mail]] :exclusions [com.sun.mail/javax.mail]]
[org.slf4j/jcl-over-slf4j "2.0.12"]]}} [org.slf4j/jcl-over-slf4j "2.0.12"]]}}
:release-tasks [["test"] :release-tasks [["test"]

View file

@ -3,22 +3,46 @@
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
#?(:clj [orchestra.core :refer [defn-spec]] #?(:clj [orchestra.core :refer [defn-spec]]
:cljs [orchestra.core :refer-macros [defn-spec]]) :cljs [orchestra.core :refer-macros [defn-spec]])
[clojure.string :as str]
[dda.c4k-common.yaml :as yaml] [dda.c4k-common.yaml :as yaml]
[dda.c4k-common.predicate :as cp]
[dda.c4k-common.monitoring.monitoring-internal :as int])) [dda.c4k-common.monitoring.monitoring-internal :as int]))
(s/def ::grafana-cloud-user ::int/grafana-cloud-user) (s/def ::grafana-cloud-user cp/bash-env-string?)
(s/def ::grafana-cloud-password ::int/grafana-cloud-password) (s/def ::grafana-cloud-password cp/bash-env-string?)
(s/def ::grafana-cloud-url ::int/grafana-cloud-url) (s/def ::grafana-cloud-url string?)
(s/def ::cluster-name ::int/cluster-name) (s/def ::cluster-name string?)
(s/def ::cluster-stage ::int/cluster-stage) (s/def ::cluster-stage cp/stage?)
(s/def ::node-regex string?)
(s/def ::traefik-regex string?)
(s/def ::kube-state-regex string?)
(s/def ::mon-cfg (s/keys :req-un [::grafana-cloud-url (s/def ::mon-cfg (s/keys :req-un [::grafana-cloud-url
::cluster-name ::cluster-name
::cluster-stage])) ::cluster-stage]))
(s/def ::mon-auth (s/keys :req-un [::grafana-cloud-user (s/def ::mon-auth (s/keys :req-un [::grafana-cloud-user
::grafana-cloud-password])) ::grafana-cloud-password]))
(s/def ::filter-regex (s/keys :req-un [::node-regex
::traefik-regex
::kube-state-regex]))
(def filter-regex-string int/filter-regex-string) (def metric-regex {:node-regex
(str "node_cpu_sec.+|node_load[0-9]+|node_memory_Buf.*|node_memory_Mem.*|"
"node_memory_Cached.*|node_disk_[r,w,i].*|node_filesystem_[s,a].*|"
"node_network_receive_bytes_total|node_network_transmit_bytes_total")
:traefik-regex (str "traefik_entrypoint_.*_total|"
"traefik_entrypoint_.*_seconds_count|"
"traefik_router_.*_total|"
"traefik_router_.*_seconds_count|"
"traefik_service_.*_total|"
"traefik_service_.*_seconds_count|"
"traefik_tls_certs_not_after")
:kube-state-regex (str "kube_pod_container_status_restarts_total|"
"kube_pod_status_reason|kube_node_status_capacity|kube_node_status_allocatable|"
"kube_cronjob_status_active|kube_job_status_failed")})
(def filter-regex-string
(str/join "|" (vals metric-regex)))
(defn-spec generate seq? (defn-spec generate seq?

View file

@ -14,11 +14,17 @@
(s/def ::grafana-cloud-url string?) (s/def ::grafana-cloud-url string?)
(s/def ::cluster-name string?) (s/def ::cluster-name string?)
(s/def ::cluster-stage cp/stage?) (s/def ::cluster-stage cp/stage?)
(s/def ::node-regex string?)
(s/def ::traefik-regex string?)
(s/def ::kube-state-regex string?)
(s/def ::mon-cfg (s/keys :req-un [::grafana-cloud-url (s/def ::mon-cfg (s/keys :req-un [::grafana-cloud-url
::cluster-name ::cluster-name
::cluster-stage])) ::cluster-stage]))
(s/def ::mon-auth (s/keys :req-un [::grafana-cloud-user (s/def ::mon-auth (s/keys :req-un [::grafana-cloud-user
::grafana-cloud-password])) ::grafana-cloud-password]))
(s/def ::filter-regex (s/keys :req-un [::node-regex
::traefik-regex
::kube-state-regex]))
(def metric-regex {:node-regex (def metric-regex {:node-regex
(str "node_cpu_sec.+|node_load[0-9]+|node_memory_Buf.*|node_memory_Mem.*|" (str "node_cpu_sec.+|node_load[0-9]+|node_memory_Buf.*|node_memory_Mem.*|"
@ -38,7 +44,7 @@
(def filter-regex-string (def filter-regex-string
(str/join "|" (vals metric-regex))) (str/join "|" (vals metric-regex)))
(defn-spec generate-prometheus-config map? (defn-spec generate-prometheus-config cp/map-or-seq?
[config ::mon-cfg [config ::mon-cfg
auth ::mon-auth] auth ::mon-auth]
(let [{:keys [grafana-cloud-url cluster-name cluster-stage]} config (let [{:keys [grafana-cloud-url cluster-name cluster-stage]} config
@ -57,7 +63,7 @@
grafana-cloud-password) grafana-cloud-password)
(cm/replace-all-matching-values-by-new-value "FILTER_REGEX" filter-regex-string)))) (cm/replace-all-matching-values-by-new-value "FILTER_REGEX" filter-regex-string))))
(defn-spec generate-config map? (defn-spec generate-config cp/map-or-seq?
[config ::mon-cfg [config ::mon-cfg
auth ::mon-auth] auth ::mon-auth]
(-> (->

View file

@ -1,8 +1,8 @@
(ns dda.c4k-common.monitoring.monitoring-regex-test (ns dda.c4k-common.monitoring-regex-test
(:require (:require
[clojure.test :refer [deftest is are testing run-tests]] [clojure.test :refer [deftest is are testing run-tests]]
[data-test :refer :all] [data-test :refer :all]
[dda.c4k-common.monitoring.monitoring-internal :as cut])) [dda.c4k-common.monitoring :as cut]))
(defn filter-by-regex (defn filter-by-regex
[regex-str collection] [regex-str collection]