|
@@ -1,64 +1,174 @@
|
|
|
from sentry.snuba.dataset import Dataset
|
|
|
-from sentry.snuba.metrics.extraction import OndemandMetricSpec, is_on_demand_query
|
|
|
+from sentry.snuba.metrics.extraction import (
|
|
|
+ OndemandMetricSpec,
|
|
|
+ is_on_demand_metric_query,
|
|
|
+ is_standard_metrics_compatible,
|
|
|
+)
|
|
|
|
|
|
|
|
|
-def test_is_on_demand_query_wrong_dataset():
|
|
|
- assert is_on_demand_query(Dataset.Transactions, "count()", "geo.city:Vienna") is False
|
|
|
- assert (
|
|
|
- is_on_demand_query(Dataset.Metrics, "count()", "browser.version:1 os.name:android") is False
|
|
|
- )
|
|
|
+class TestIsOnDemandMetricQuery:
|
|
|
+ perf_metrics = Dataset.PerformanceMetrics
|
|
|
|
|
|
+ def test_wrong_dataset(self):
|
|
|
+ assert (
|
|
|
+ is_on_demand_metric_query(Dataset.Transactions, "count()", "geo.city:Vienna") is False
|
|
|
+ )
|
|
|
+ assert (
|
|
|
+ is_on_demand_metric_query(
|
|
|
+ Dataset.Metrics, "count()", "browser.version:1 os.name:android"
|
|
|
+ )
|
|
|
+ is False
|
|
|
+ )
|
|
|
|
|
|
-def test_is_on_demand_query_no_query():
|
|
|
- assert is_on_demand_query(Dataset.PerformanceMetrics, "count()", "") is False
|
|
|
+ def test_no_query(self):
|
|
|
+ assert is_on_demand_metric_query(Dataset.PerformanceMetrics, "count()", "") is False
|
|
|
|
|
|
+ def test_invalid_query(self):
|
|
|
+ assert is_on_demand_metric_query(self.perf_metrics, "count()", "AND") is False
|
|
|
+ assert (
|
|
|
+ is_on_demand_metric_query(self.perf_metrics, "count()", ")AND transaction.duration:>=1")
|
|
|
+ is False
|
|
|
+ )
|
|
|
+ assert (
|
|
|
+ is_on_demand_metric_query(self.perf_metrics, "count()", "transaction.duration:>=abc")
|
|
|
+ is False
|
|
|
+ )
|
|
|
+ assert is_on_demand_metric_query(self.perf_metrics, "count_if(}", "") is False
|
|
|
|
|
|
-def test_is_on_demand_query_invalid_query():
|
|
|
- dataset = Dataset.PerformanceMetrics
|
|
|
+ def test_on_demand_queries(self):
|
|
|
+ # # transaction.duration is a non-standard field
|
|
|
+ assert (
|
|
|
+ is_on_demand_metric_query(self.perf_metrics, "count()", "transaction.duration:>=1")
|
|
|
+ is True
|
|
|
+ )
|
|
|
+ # # geo.city is a non-standard field
|
|
|
+ assert is_on_demand_metric_query(self.perf_metrics, "count()", "geo.city:Vienna") is True
|
|
|
+ # os.name is a standard field, browser.version is not
|
|
|
+ assert (
|
|
|
+ is_on_demand_metric_query(
|
|
|
+ self.perf_metrics, "count()", "geo.city:Vienna os.name:android"
|
|
|
+ )
|
|
|
+ is True
|
|
|
+ )
|
|
|
+ # os.version is not a standard field
|
|
|
+ assert (
|
|
|
+ is_on_demand_metric_query(
|
|
|
+ self.perf_metrics,
|
|
|
+ "count()",
|
|
|
+ "(release:a OR transaction.op:b) transaction.duration:>1s",
|
|
|
+ )
|
|
|
+ is True
|
|
|
+ )
|
|
|
|
|
|
- assert is_on_demand_query(dataset, "count()", "AND") is False
|
|
|
- assert is_on_demand_query(dataset, "count()", ")AND transaction.duration:>=1") is False
|
|
|
- assert is_on_demand_query(dataset, "count()", "transaction.duration:>=abc") is False
|
|
|
- assert is_on_demand_query(dataset, "count_if(}", "") is False
|
|
|
+ def test_standard_comaptible_queries(self):
|
|
|
+ assert is_on_demand_metric_query(self.perf_metrics, "count()", "") is False
|
|
|
+ assert is_on_demand_metric_query(self.perf_metrics, "count()", "environment:dev") is False
|
|
|
+ assert (
|
|
|
+ is_on_demand_metric_query(
|
|
|
+ self.perf_metrics, "count()", "release:initial OR os.name:android"
|
|
|
+ )
|
|
|
+ is False
|
|
|
+ )
|
|
|
+ assert (
|
|
|
+ is_on_demand_metric_query(
|
|
|
+ self.perf_metrics,
|
|
|
+ "count()",
|
|
|
+ "(http.method:POST OR http.status_code:404) browser.name:chrome",
|
|
|
+ )
|
|
|
+ is False
|
|
|
+ )
|
|
|
+ assert is_on_demand_metric_query(self.perf_metrics, "foo.bar", "") is False
|
|
|
+ assert is_on_demand_metric_query(self.perf_metrics, "count()", "foo.bar") is False
|
|
|
+
|
|
|
+ def test_countif(self):
|
|
|
+ assert (
|
|
|
+ is_on_demand_metric_query(
|
|
|
+ self.perf_metrics, "count_if(transaction.duration,equals,300)", ""
|
|
|
+ )
|
|
|
+ is True
|
|
|
+ )
|
|
|
+ assert (
|
|
|
+ is_on_demand_metric_query(self.perf_metrics, 'count_if(release,equals,"foo")', "")
|
|
|
+ is False
|
|
|
+ )
|
|
|
|
|
|
|
|
|
-def test_is_on_demand_query_true():
|
|
|
- dataset = Dataset.PerformanceMetrics
|
|
|
+class TestIsStandardMetricsCompatible:
|
|
|
+ perf_metrics = Dataset.PerformanceMetrics
|
|
|
|
|
|
- # transaction.duration is a non-standard field
|
|
|
- assert is_on_demand_query(dataset, "count()", "transaction.duration:>=1") is True
|
|
|
- # transaction.duration is a non-standard field
|
|
|
- assert is_on_demand_query(dataset, "count()", "geo.city:Vienna") is True
|
|
|
- # os.name is a standard field, browser.version is not
|
|
|
- assert is_on_demand_query(dataset, "count()", "browser.version:1 os.name:android") is True
|
|
|
- # os.version is not a standard field
|
|
|
- assert (
|
|
|
- is_on_demand_query(
|
|
|
- dataset, "count()", "(release:a OR transaction.op:b) transaction.duration:>1s"
|
|
|
+ def test_wrong_dataset(self):
|
|
|
+ assert is_standard_metrics_compatible(Dataset.Transactions, "count()", "") is False
|
|
|
+ assert (
|
|
|
+ is_standard_metrics_compatible(Dataset.Discover, "count()", "os.name:android") is False
|
|
|
)
|
|
|
- is True
|
|
|
- )
|
|
|
|
|
|
+ def test_no_query(self):
|
|
|
+ assert is_standard_metrics_compatible(Dataset.PerformanceMetrics, "count()", "") is True
|
|
|
|
|
|
-def test_is_on_demand_query_false():
|
|
|
- dataset = Dataset.PerformanceMetrics
|
|
|
+ def test_invalid_query(self):
|
|
|
+ dataset = Dataset.PerformanceMetrics
|
|
|
|
|
|
- assert is_on_demand_query(dataset, "count()", "") is False
|
|
|
- assert is_on_demand_query(dataset, "count()", "environment:dev") is False
|
|
|
- assert is_on_demand_query(dataset, "count()", "release:initial OR os.name:android") is False
|
|
|
- assert (
|
|
|
- is_on_demand_query(
|
|
|
- dataset, "count()", "(http.method:POST OR http.status_code:404) browser.name:chrome"
|
|
|
- )
|
|
|
- is False
|
|
|
- )
|
|
|
+ assert is_standard_metrics_compatible(dataset, "count()", ")AND os.name:>=1") is False
|
|
|
+ assert is_standard_metrics_compatible(dataset, "count()", "os.name><=abc") is False
|
|
|
|
|
|
+ def test_on_demand_queries(self):
|
|
|
+ # # transaction.duration is a non-standard field
|
|
|
+ assert (
|
|
|
+ is_standard_metrics_compatible(self.perf_metrics, "count()", "transaction.duration:>=1")
|
|
|
+ is False
|
|
|
+ )
|
|
|
+ # # geo.city is a non-standard field
|
|
|
+ assert (
|
|
|
+ is_standard_metrics_compatible(self.perf_metrics, "count()", "geo.city:Vienna") is False
|
|
|
+ )
|
|
|
+ # os.name is a standard field, browser.version is not
|
|
|
+ assert (
|
|
|
+ is_standard_metrics_compatible(
|
|
|
+ self.perf_metrics, "count()", "geo.city:Vienna os.name:android"
|
|
|
+ )
|
|
|
+ is False
|
|
|
+ )
|
|
|
+ # os.version is not a standard field
|
|
|
+ assert (
|
|
|
+ is_standard_metrics_compatible(
|
|
|
+ self.perf_metrics,
|
|
|
+ "count()",
|
|
|
+ "(release:a OR transaction.op:b) transaction.duration:>1s",
|
|
|
+ )
|
|
|
+ is False
|
|
|
+ )
|
|
|
|
|
|
-def test_is_on_demand_query_countif():
|
|
|
- dataset = Dataset.PerformanceMetrics
|
|
|
+ def test_standard_comaptible_queries(self):
|
|
|
+ assert is_standard_metrics_compatible(self.perf_metrics, "count()", "") is True
|
|
|
+ assert (
|
|
|
+ is_standard_metrics_compatible(self.perf_metrics, "count()", "environment:dev") is True
|
|
|
+ )
|
|
|
+ assert (
|
|
|
+ is_standard_metrics_compatible(
|
|
|
+ self.perf_metrics, "count()", "release:initial OR os.name:android"
|
|
|
+ )
|
|
|
+ is True
|
|
|
+ )
|
|
|
+ assert (
|
|
|
+ is_standard_metrics_compatible(
|
|
|
+ self.perf_metrics,
|
|
|
+ "count()",
|
|
|
+ "(http.method:POST OR http.status_code:404) browser.name:chrome",
|
|
|
+ )
|
|
|
+ is True
|
|
|
+ )
|
|
|
|
|
|
- assert is_on_demand_query(dataset, "count_if(transaction.duration,equals,300)", "") is True
|
|
|
- assert is_on_demand_query(dataset, 'count_if(release,equals,"foo")', "") is False
|
|
|
+ def test_countif(self):
|
|
|
+ assert (
|
|
|
+ is_standard_metrics_compatible(
|
|
|
+ self.perf_metrics, "count_if(transaction.duration,equals,300)", ""
|
|
|
+ )
|
|
|
+ is False
|
|
|
+ )
|
|
|
+ assert (
|
|
|
+ is_standard_metrics_compatible(self.perf_metrics, 'count_if(release,equals,"foo")', "")
|
|
|
+ is True
|
|
|
+ )
|
|
|
|
|
|
|
|
|
def test_spec_simple_query_count():
|