Skip to content

Business intelligence made simple

Test trend [skip ci]

Andrew Kanef0b1eaa10619
diff --git a/Gemfile b/Gemfile
index 0abb2b38..57b8adee 100644
--- a/Gemfile
+++ b/Gemfile
@@ -8,7 +8,10 @@ gem "combustion"
gem "rails"
gem "pg"
gem "sprockets-rails"
-gem "prophet-rb" if ENV["TEST_PROPHET"]
# data sources
gem "elasticsearch"
+
+# anomaly detection and forecasting
+gem "prophet-rb" if ENV["TEST_PROPHET"]
+gem "trend" if ENV["TEST_TREND"]
diff --git a/test/charts_test.rb b/test/charts_test.rb
index 37c2645b..ed253f7e 100644
--- a/test/charts_test.rb
+++ b/test/charts_test.rb
@@ -51,12 +51,4 @@ class ChartsTest < ActionDispatch::IntegrationTest
run_query "SELECT 1 AS user_id, NOW() AS conversion_time /* cohort analysis */", query_id: 1
assert_match "1 cohort", response.body
end
-
- def test_forecasting
- skip "Too slow" unless ENV["TEST_PROPHET"]
-
- query = create_query(statement: "SELECT current_date + n AS day, n FROM generate_series(1, 30) n")
- run_query query.statement, query_id: query.id, forecast: "t"
- assert_match %{"name":"forecast"}, response.body
- end
end
diff --git a/test/checks_test.rb b/test/checks_test.rb
index b331c33f..87beef87 100644
--- a/test/checks_test.rb
+++ b/test/checks_test.rb
@@ -41,21 +41,16 @@ class ChecksTest < ActionDispatch::IntegrationTest
assert_equal "failing", check.state
end
- def test_anomaly
- skip "Too slow" unless ENV["TEST_PROPHET"]
+ def test_anomaly_prophet
+ skip unless ENV["TEST_PROPHET"]
- query = create_query(statement: "SELECT current_date + n AS day, 1 FROM generate_series(1, 30) n")
- check = create_check(query: query, check_type: "anomaly")
-
- Blazer.run_checks(schedule: "5 minutes")
- check.reload
- assert_equal "passing", check.state
+ assert_anomaly("prophet")
+ end
- query.update!(statement: "SELECT current_date + n AS day, 1 FROM generate_series(1, 30) n UNION ALL SELECT current_date + 31, 2")
+ def test_anomaly_trend
+ skip unless ENV["TEST_TREND"]
- Blazer.run_checks(schedule: "5 minutes")
- check.reload
- assert_equal "failing", check.state
+ assert_anomaly("trend")
end
def test_emails
@@ -78,4 +73,26 @@ class ChecksTest < ActionDispatch::IntegrationTest
def create_check(**attributes)
Blazer::Check.create!(schedule: "5 minutes", **attributes)
end
+
+ def assert_anomaly(anomaly_checks)
+ previous_value = Blazer.anomaly_checks
+ begin
+ Blazer.anomaly_checks = anomaly_checks
+
+ query = create_query(statement: "SELECT current_date + n AS day, 0.1 * random() FROM generate_series(1, 30) n")
+ check = create_check(query: query, check_type: "anomaly")
+
+ Blazer.run_checks(schedule: "5 minutes")
+ check.reload
+ assert_equal "passing", check.state
+
+ query.update!(statement: "SELECT current_date + n AS day, 0.1 * random() FROM generate_series(1, 30) n UNION ALL SELECT current_date + 31, 2")
+
+ Blazer.run_checks(schedule: "5 minutes")
+ check.reload
+ assert_equal "failing", check.state
+ ensure
+ Blazer.anomaly_checks = previous_value
+ end
+ end
end
diff --git a/test/forecasting_test.rb b/test/forecasting_test.rb
new file mode 100644
index 00000000..e154079e
--- /dev/null
+++ b/test/forecasting_test.rb
@@ -0,0 +1,28 @@
+require_relative "test_helper"
+
+class ForecastingTest < ActionDispatch::IntegrationTest
+ def test_prophet
+ skip unless ENV["TEST_PROPHET"]
+
+ assert_forecast("prophet")
+ end
+
+ def test_trend
+ skip unless ENV["TEST_TREND"]
+
+ assert_forecast("trend")
+ end
+
+ def assert_forecast(forecasting)
+ previous_value = Blazer.forecasting
+ begin
+ Blazer.forecasting = forecasting
+
+ query = create_query(statement: "SELECT current_date + n AS day, n FROM generate_series(1, 30) n")
+ run_query query.statement, query_id: query.id, forecast: "t"
+ assert_match %{"name":"forecast"}, response.body
+ ensure
+ Blazer.forecasting = previous_value
+ end
+ end
+end
diff --git a/test/internal/config/blazer.yml b/test/internal/config/blazer.yml
index a4573fe3..bdd476b4 100644
--- a/test/internal/config/blazer.yml
+++ b/test/internal/config/blazer.yml
@@ -67,11 +67,11 @@ check_schedules:
# enable anomaly detection
# note: with trend, time series are sent to https://trendapi.org
-anomaly_checks: prophet
+# anomaly_checks: prophet / trend / r
# enable forecasting
# note: with trend, time series are sent to https://trendapi.org
-forecasting: prophet
+# forecasting: prophet / trend
# enable map
mapbox_access_token: token