forked from brabster/crucible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for cloudwatch anomaly detector * Add test for cloudwatch anomaly detector * Remove need for ->key on name space spec * Remove vector requirement on dimensions spec
- Loading branch information
Cameron Sumpter
authored and
Sam Hewitt
committed
Oct 7, 2019
1 parent
0dfb4b0
commit 37b7de8
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
(ns crucible.aws.cloudwatch.anomaly-detector | ||
(:require [clojure.spec.alpha :as s] | ||
[crucible.aws.cloudwatch :as cloudwatch] | ||
[crucible.encoding.keys :refer [->key]] | ||
[crucible.resources :refer [defresource spec-or-ref]])) | ||
|
||
(s/def ::value (spec-or-ref string?)) | ||
|
||
(s/def ::name (spec-or-ref string?)) | ||
|
||
(s/def ::dimension (s/keys :req [::name ::value])) | ||
|
||
(s/def ::dimensions (s/coll-of ::dimension)) | ||
|
||
(s/def ::stat ::cloudwatch/statistic) | ||
|
||
(def date-time-regex | ||
#"(19|20)[0-9][0-9]-(0[0-9]|1[0-2])-(0[1-9]|([12][0-9]|3[01]))T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]") | ||
|
||
(s/def ::date-time (spec-or-ref (s/and string? #(re-matches date-time-regex %)))) | ||
|
||
(s/def ::end-time ::date-time) | ||
|
||
(s/def ::start-time ::date-time) | ||
|
||
(s/def ::range (s/keys :req [::start-time ::end-time])) | ||
|
||
(s/def ::ranges (s/coll-of ::range)) | ||
|
||
(s/def ::namespace (spec-or-ref string?)) | ||
|
||
(s/def ::metric-name (spec-or-ref string?)) | ||
|
||
(s/def ::excluded-time-ranges (spec-or-ref ::ranges)) | ||
|
||
(s/def ::metric-time-zone (spec-or-ref string?)) | ||
|
||
(s/def ::configuration (s/keys :opt [::excluded-time-ranges ::metric-time-zone])) | ||
|
||
(s/def ::anomaly-detector (s/keys :req [::metric-name | ||
::namespace | ||
::stat])) | ||
|
||
(defresource anomaly-detector "AWS::CloudWatch::AnomalyDetector" ::anomaly-detector) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"Type" : "AWS::CloudWatch::AnomalyDetector", | ||
"Properties" : { | ||
"Configuration" : { | ||
"ExcludedTimeRanges": [{ | ||
"EndTime": "2019-07-01T23:59:59", | ||
"StartTime": "2019-07-01T23:59:59" | ||
}], | ||
"MetricTimeZone": "America/New_York" | ||
}, | ||
"Dimensions" : [{ | ||
"Name": "Memory", | ||
"Value": "UsedMemory" | ||
}], | ||
"MetricName" : "JvmMetric", | ||
"Namespace" : "AWSSDK/Java", | ||
"Stat" : "Average" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(ns crucible.aws.cloudwatch.anomaly-detector-test | ||
(:require [cheshire.core :as json] | ||
[clojure.java.io :as io] | ||
[clojure.test :as t :refer :all] | ||
[crucible.assertion :refer [resource=]] | ||
[crucible.aws.cloudwatch.anomaly-detector :as ad])) | ||
|
||
(deftest anomaly-detection-test | ||
(testing "encode" | ||
(is (resource= | ||
(json/decode (slurp (io/resource "aws/cloudwatch/anomaly_detector.json"))) | ||
(ad/anomaly-detector | ||
{::ad/namespace "AWSSDK/Java" | ||
::ad/stat "Average" | ||
::ad/metric-name "JvmMetric" | ||
::ad/configuration | ||
{::ad/excluded-time-ranges | ||
[{::ad/end-time "2019-07-01T23:59:59" | ||
::ad/start-time "2019-07-01T23:59:59"}] | ||
::ad/metric-time-zone "America/New_York"} | ||
::ad/dimensions [{::ad/name "Memory" | ||
::ad/value "UsedMemory"}]}))))) |