Skip to content

Commit

Permalink
use appropriate types in cloudwatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hewitt committed Apr 1, 2019
1 parent c1bdb1a commit 544cb9a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
35 changes: 25 additions & 10 deletions src/crucible/aws/cloudwatch.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
[crucible.encoding.keys :refer [->key]]
[clojure.spec.alpha :as s]))

(defmethod ->key ::ok-actions [_] "OKActions")
(defmethod ->key :ok-actions [_] "OKActions")

(s/def ::actions-enabled (spec-or-ref string? #_boolean?))
(s/def ::actions-enabled (spec-or-ref boolean?))

(s/def ::actions (s/coll-of (spec-or-ref string?) :kind vector?))

(s/def ::alarm-actions ::actions)

(s/def ::alarm-description (spec-or-ref string?))

Expand All @@ -26,26 +30,37 @@

(s/def ::dimensions (s/coll-of ::dimension :kind vector?))

(s/def ::evaluation-periods (spec-or-ref string? #_pos-int?))
(s/def ::evaluation-periods (spec-or-ref pos-int?))

;; The percentile statistic for the metric. Specify a value between p0.0 and p100.
(s/def ::extended-statistic (spec-or-ref (s/and string?
#(clojure.string/starts-with? % "p"))))

(s/def ::insufficient-data-actions ::actions)

(s/def ::metric-name (spec-or-ref string?))

(s/def ::namespace (spec-or-ref string?))

(s/def ::ok-actions (s/coll-of (spec-or-ref string?) :kind vector?))
(s/def ::insufficient-data-actions ::ok-actions)
(s/def ::alarm-actions (s/coll-of (spec-or-ref string?) :kind vector?))
(s/def ::ok-actions ::actions)

(s/def ::period (spec-or-ref string? #_(s/and pos-int?
#(= 0 (mod % 60)))))
;; The time over which the specified statistic is applied.
;; Specify time in seconds, in multiples of 60.
(s/def ::period (spec-or-ref (s/and pos-int?
#(zero? (mod % 60)))))

(s/def ::statistic (spec-or-ref #{"SampleCount"
"Average"
"Sum"
"Minimum"
"Maximum"}))

(s/def ::threshold (spec-or-ref string? #_number?))
(s/def ::threshold (spec-or-ref double?))

(s/def ::treat-missing-data (spec-or-ref #{"breaching"
"notBreaching"
"ignore"
"missing"}))

(s/def ::unit (spec-or-ref #{"Seconds"
"Microseconds"
Expand Down Expand Up @@ -79,7 +94,6 @@
::metric-name
::namespace
::period
::statistic
::threshold]
:opt [::actions-enabled
::alarm-actions
Expand All @@ -88,6 +102,7 @@
::dimensions
::insufficient-data-actions
::ok-actions
::statistic
::unit]))

(defresource alarm "AWS::CloudWatch::Alarm" ::alarm)
6 changes: 3 additions & 3 deletions test/crucible/aws/cloudwatch_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
::cw/metric-name "CPUUtilization"
::cw/namespace "AWS/EC2"
::cw/statistic "Average"
::cw/period "300"
::cw/evaluation-periods "2"
::cw/threshold "90"
::cw/period 300
::cw/evaluation-periods 2
::cw/threshold 90.0
::cw/alarm-actions [(xref :web-server-scale-up-policy)]
::cw/dimensions [{::cw/name "AutoScalingGroupName"
::cw/value (xref :web-server-group)}]
Expand Down

0 comments on commit 544cb9a

Please sign in to comment.