12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151 |
- import pytest
- from django.urls import reverse
- from sentry.search.events import constants
- from sentry.search.utils import map_device_class_level
- from sentry.testutils.cases import MetricsEnhancedPerformanceTestCase
- from sentry.testutils.helpers.datetime import before_now
- from sentry.testutils.silo import region_silo_test
- pytestmark = pytest.mark.sentry_metrics
- class OrganizationEventsMetricsEnhancedPerformanceEndpointTest(MetricsEnhancedPerformanceTestCase):
- viewname = "sentry-api-0-organization-events"
- # Poor intentionally omitted for test_measurement_rating_that_does_not_exist
- METRIC_STRINGS = [
- "foo_transaction",
- "bar_transaction",
- ]
- def setUp(self):
- super().setUp()
- self.min_ago = before_now(minutes=1)
- self.six_min_ago = before_now(minutes=6)
- self.three_days_ago = before_now(days=3)
- self.features = {
- "organizations:starfish-view": True,
- }
- def do_request(self, query, features=None):
- if features is None:
- features = {"organizations:discover-basic": True}
- features.update(self.features)
- self.login_as(user=self.user)
- url = reverse(
- self.viewname,
- kwargs={"organization_slug": self.organization.slug},
- )
- with self.feature(features):
- return self.client.get(url, query, format="json")
- def test_p50_with_no_data(self):
- response = self.do_request(
- {
- "field": ["p50()"],
- "query": "",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["p50()"] == 0
- assert meta["dataset"] == "spansMetrics"
- def test_count(self):
- self.store_span_metric(
- 1,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.three_days_ago,
- )
- response = self.do_request(
- {
- "field": ["count()"],
- "query": "",
- "project": self.project.id,
- "dataset": "spansMetrics",
- "statsPeriod": "7d",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["count()"] == 1
- assert meta["dataset"] == "spansMetrics"
- def test_count_unique(self):
- self.store_span_metric(
- 1,
- "user",
- timestamp=self.min_ago,
- )
- self.store_span_metric(
- 2,
- "user",
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["count_unique(user)"],
- "query": "",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["count_unique(user)"] == 2
- assert meta["dataset"] == "spansMetrics"
- def test_sum(self):
- self.store_span_metric(
- 321,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- )
- self.store_span_metric(
- 99,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["sum(span.self_time)"],
- "query": "",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["sum(span.self_time)"] == 420
- assert meta["dataset"] == "spansMetrics"
- def test_percentile(self):
- self.store_span_metric(
- 1,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["percentile(span.self_time, 0.95)"],
- "query": "",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["percentile(span.self_time, 0.95)"] == 1
- assert meta["dataset"] == "spansMetrics"
- def test_fixed_percentile_functions(self):
- self.store_span_metric(
- 1,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- )
- for function in ["p50()", "p75()", "p95()", "p99()", "p100()"]:
- response = self.do_request(
- {
- "field": [function],
- "query": "",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0][function] == 1, function
- assert meta["dataset"] == "spansMetrics", function
- assert meta["fields"][function] == "duration", function
- def test_fixed_percentile_functions_with_duration(self):
- self.store_span_metric(
- 1,
- internal_metric=constants.SPAN_METRICS_MAP["span.duration"],
- timestamp=self.min_ago,
- )
- for function in [
- "p50(span.duration)",
- "p75(span.duration)",
- "p95(span.duration)",
- "p99(span.duration)",
- "p100(span.duration)",
- ]:
- response = self.do_request(
- {
- "field": [function],
- "query": "",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1, function
- assert data[0][function] == 1, function
- assert meta["dataset"] == "spansMetrics", function
- assert meta["fields"][function] == "duration", function
- def test_avg(self):
- self.store_span_metric(
- 1,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["avg()"],
- "query": "",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["avg()"] == 1
- assert meta["dataset"] == "spansMetrics"
- def test_eps(self):
- for _ in range(6):
- self.store_span_metric(
- 1,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["eps()", "sps()"],
- "query": "",
- "project": self.project.id,
- "dataset": "spansMetrics",
- "statsPeriod": "10m",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["eps()"] == 0.01
- assert data[0]["sps()"] == 0.01
- assert meta["fields"]["eps()"] == "rate"
- assert meta["fields"]["sps()"] == "rate"
- assert meta["units"]["eps()"] == "1/second"
- assert meta["units"]["sps()"] == "1/second"
- assert meta["dataset"] == "spansMetrics"
- def test_epm(self):
- for _ in range(6):
- self.store_span_metric(
- 1,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["epm()", "spm()"],
- "query": "",
- "project": self.project.id,
- "dataset": "spansMetrics",
- "statsPeriod": "10m",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["epm()"] == 0.6
- assert data[0]["spm()"] == 0.6
- assert meta["fields"]["epm()"] == "rate"
- assert meta["fields"]["spm()"] == "rate"
- assert meta["units"]["epm()"] == "1/minute"
- assert meta["units"]["spm()"] == "1/minute"
- assert meta["dataset"] == "spansMetrics"
- def test_time_spent_percentage(self):
- for _ in range(4):
- self.store_span_metric(
- 1,
- internal_metric=constants.SELF_TIME_LIGHT,
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_span_metric(
- 1,
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_span_metric(
- 1,
- internal_metric=constants.SELF_TIME_LIGHT,
- tags={"transaction": "bar_transaction"},
- timestamp=self.min_ago,
- )
- self.store_span_metric(
- 1,
- tags={"transaction": "bar_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["transaction", "time_spent_percentage()"],
- "query": "",
- "orderby": ["-time_spent_percentage()"],
- "project": self.project.id,
- "dataset": "spansMetrics",
- "statsPeriod": "10m",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 2
- assert data[0]["time_spent_percentage()"] == 0.8
- assert data[0]["transaction"] == "foo_transaction"
- assert data[1]["time_spent_percentage()"] == 0.2
- assert data[1]["transaction"] == "bar_transaction"
- assert meta["dataset"] == "spansMetrics"
- def test_time_spent_percentage_local(self):
- response = self.do_request(
- {
- "field": ["time_spent_percentage(local)"],
- "query": "",
- "orderby": ["-time_spent_percentage(local)"],
- "project": self.project.id,
- "dataset": "spansMetrics",
- "statsPeriod": "10m",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["time_spent_percentage(local)"] is None
- assert meta["dataset"] == "spansMetrics"
- def test_http_error_rate_and_count(self):
- for _ in range(4):
- self.store_span_metric(
- 1,
- internal_metric=constants.SELF_TIME_LIGHT,
- tags={"span.status_code": "500"},
- timestamp=self.min_ago,
- )
- self.store_span_metric(
- 1,
- internal_metric=constants.SELF_TIME_LIGHT,
- tags={"span.status_code": "200"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["http_error_count()", "http_error_rate()"],
- "query": "",
- "orderby": ["-http_error_rate()"],
- "project": self.project.id,
- "dataset": "spansMetrics",
- "statsPeriod": "10m",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["http_error_rate()"] == 0.8
- assert meta["dataset"] == "spansMetrics"
- assert meta["fields"]["http_error_count()"] == "integer"
- assert meta["fields"]["http_error_rate()"] == "percentage"
- def test_ttid_rate_and_count(self):
- for _ in range(8):
- self.store_span_metric(
- 1,
- internal_metric=constants.SELF_TIME_LIGHT,
- tags={"ttid": "ttid", "ttfd": "ttfd"},
- timestamp=self.min_ago,
- )
- self.store_span_metric(
- 1,
- internal_metric=constants.SELF_TIME_LIGHT,
- tags={"ttfd": "ttfd", "ttid": ""},
- timestamp=self.min_ago,
- )
- self.store_span_metric(
- 1,
- internal_metric=constants.SELF_TIME_LIGHT,
- tags={"ttfd": "", "ttid": ""},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "ttid_contribution_rate()",
- "ttid_count()",
- "ttfd_contribution_rate()",
- "ttfd_count()",
- ],
- "query": "",
- "orderby": ["-ttid_contribution_rate()"],
- "project": self.project.id,
- "dataset": "spansMetrics",
- "statsPeriod": "10m",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["ttid_contribution_rate()"] == 0.8
- assert data[0]["ttid_count()"] == 8
- assert data[0]["ttfd_contribution_rate()"] == 0.9
- assert data[0]["ttfd_count()"] == 9
- assert meta["dataset"] == "spansMetrics"
- assert meta["fields"]["ttid_count()"] == "integer"
- assert meta["fields"]["ttid_contribution_rate()"] == "percentage"
- assert meta["fields"]["ttfd_count()"] == "integer"
- assert meta["fields"]["ttfd_contribution_rate()"] == "percentage"
- def test_main_thread_count(self):
- for _ in range(8):
- self.store_span_metric(
- 1,
- internal_metric=constants.SELF_TIME_LIGHT,
- tags={"span.main_thread": "true"},
- timestamp=self.min_ago,
- )
- self.store_span_metric(
- 1,
- internal_metric=constants.SELF_TIME_LIGHT,
- tags={},
- timestamp=self.min_ago,
- )
- self.store_span_metric(
- 1,
- internal_metric=constants.SELF_TIME_LIGHT,
- tags={"span.main_thread": ""},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "main_thread_count()",
- ],
- "query": "",
- "orderby": ["-main_thread_count()"],
- "project": self.project.id,
- "dataset": "spansMetrics",
- "statsPeriod": "10m",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["main_thread_count()"] == 8
- assert meta["dataset"] == "spansMetrics"
- assert meta["fields"]["main_thread_count()"] == "integer"
- def test_use_self_time_light(self):
- self.store_span_metric(
- 100,
- internal_metric=constants.SELF_TIME_LIGHT,
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["p50(span.self_time)"],
- # Should be 0 since its filtering on transaction
- "query": "transaction:foo_transaction",
- "orderby": ["-p50(span.self_time)"],
- "project": self.project.id,
- "dataset": "spansMetrics",
- "statsPeriod": "10m",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["p50(span.self_time)"] == 0
- assert meta["dataset"] == "spansMetrics"
- assert meta["fields"]["p50(span.self_time)"] == "duration"
- response = self.do_request(
- {
- # Should be 0 since it has a transaction column
- "field": ["transaction", "p50(span.self_time)"],
- "query": "",
- "orderby": ["-p50(span.self_time)"],
- "project": self.project.id,
- "dataset": "spansMetrics",
- "statsPeriod": "10m",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 0
- response = self.do_request(
- {
- "field": ["p50(span.self_time)"],
- # Should be 100 since its not filtering on transaction
- "query": "",
- "orderby": ["-p50(span.self_time)"],
- "project": self.project.id,
- "dataset": "spansMetrics",
- "statsPeriod": "10m",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["p50(span.self_time)"] == 100
- assert meta["dataset"] == "spansMetrics"
- assert meta["fields"]["p50(span.self_time)"] == "duration"
- def test_span_module(self):
- self.store_span_metric(
- 1,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.six_min_ago,
- tags={"span.category": "http", "span.description": "f"},
- )
- self.store_span_metric(
- 3,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.six_min_ago,
- tags={"span.category": "db", "span.description": "e"},
- )
- self.store_span_metric(
- 5,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.six_min_ago,
- tags={"span.category": "foobar", "span.description": "d"},
- )
- self.store_span_metric(
- 7,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.six_min_ago,
- tags={"span.category": "cache", "span.description": "c"},
- )
- self.store_span_metric(
- 9,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.six_min_ago,
- tags={"span.category": "db", "span.op": "db.redis", "span.description": "b"},
- )
- self.store_span_metric(
- 11,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.six_min_ago,
- tags={"span.category": "db", "span.op": "db.sql.room", "span.description": "a"},
- )
- response = self.do_request(
- {
- "field": ["span.module", "span.description", "p50(span.self_time)"],
- "query": "",
- "orderby": ["-p50(span.self_time)"],
- "project": self.project.id,
- "dataset": "spansMetrics",
- "statsPeriod": "10m",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 6
- assert data[0]["p50(span.self_time)"] == 11
- assert data[0]["span.module"] == "other"
- assert data[0]["span.description"] == "a"
- assert data[1]["p50(span.self_time)"] == 9
- assert data[1]["span.module"] == "cache"
- assert data[1]["span.description"] == "b"
- assert data[2]["p50(span.self_time)"] == 7
- assert data[2]["span.module"] == "cache"
- assert data[2]["span.description"] == "c"
- assert data[3]["p50(span.self_time)"] == 5
- assert data[3]["span.module"] == "other"
- assert data[3]["span.description"] == "d"
- assert data[4]["p50(span.self_time)"] == 3
- assert data[4]["span.module"] == "db"
- assert data[4]["span.description"] == "e"
- assert data[5]["p50(span.self_time)"] == 1
- assert data[5]["span.module"] == "http"
- assert data[5]["span.description"] == "f"
- assert meta["dataset"] == "spansMetrics"
- assert meta["fields"]["p50(span.self_time)"] == "duration"
- def test_tag_search(self):
- self.store_span_metric(
- 321,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.description": "foo"},
- )
- self.store_span_metric(
- 99,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.description": "bar"},
- )
- response = self.do_request(
- {
- "field": ["sum(span.self_time)"],
- "query": "span.description:bar",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["sum(span.self_time)"] == 99
- assert meta["dataset"] == "spansMetrics"
- def test_free_text_search(self):
- self.store_span_metric(
- 321,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.description": "foo"},
- )
- self.store_span_metric(
- 99,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.description": "bar"},
- )
- response = self.do_request(
- {
- "field": ["sum(span.self_time)"],
- "query": "foo",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["sum(span.self_time)"] == 321
- assert meta["dataset"] == "spansMetrics"
- def test_avg_compare(self):
- self.store_span_metric(
- 100,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"release": "foo"},
- )
- self.store_span_metric(
- 10,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"release": "bar"},
- )
- for function_name in [
- "avg_compare(span.self_time, release, foo, bar)",
- 'avg_compare(span.self_time, release, "foo", "bar")',
- ]:
- response = self.do_request(
- {
- "field": [function_name],
- "query": "",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0][function_name] == -0.9
- assert meta["dataset"] == "spansMetrics"
- assert meta["fields"][function_name] == "percent_change"
- def test_avg_compare_invalid_column(self):
- response = self.do_request(
- {
- "field": ["avg_compare(span.self_time, transaction, foo, bar)"],
- "query": "",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 400, response.content
- def test_span_domain_array(self):
- self.store_span_metric(
- 321,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.domain": ",sentry_table1,"},
- )
- self.store_span_metric(
- 21,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.domain": ",sentry_table1,sentry_table2,"},
- )
- response = self.do_request(
- {
- "field": ["span.domain", "p75(span.self_time)"],
- "query": "",
- "project": self.project.id,
- "orderby": ["-p75(span.self_time)"],
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 2
- assert data[0]["span.domain"] == ["sentry_table1"]
- assert data[1]["span.domain"] == ["sentry_table1", "sentry_table2"]
- assert meta["dataset"] == "spansMetrics"
- assert meta["fields"]["span.domain"] == "array"
- def test_span_domain_array_filter(self):
- self.store_span_metric(
- 321,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.domain": ",sentry_table1,"},
- )
- self.store_span_metric(
- 21,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.domain": ",sentry_table1,sentry_table2,"},
- )
- response = self.do_request(
- {
- "field": ["span.domain", "p75(span.self_time)"],
- "query": "span.domain:sentry_table2",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["span.domain"] == ["sentry_table1", "sentry_table2"]
- assert meta["dataset"] == "spansMetrics"
- assert meta["fields"]["span.domain"] == "array"
- def test_span_domain_array_filter_wildcard(self):
- self.store_span_metric(
- 321,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.domain": ",sentry_table1,"},
- )
- self.store_span_metric(
- 21,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.domain": ",sentry_table1,sentry_table2,"},
- )
- for query in ["sentry*2", "*table2", "sentry_table2*"]:
- response = self.do_request(
- {
- "field": ["span.domain", "p75(span.self_time)"],
- "query": f"span.domain:{query}",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1, query
- assert data[0]["span.domain"] == ["sentry_table1", "sentry_table2"], query
- assert meta["dataset"] == "spansMetrics", query
- assert meta["fields"]["span.domain"] == "array"
- def test_span_domain_array_has_filter(self):
- self.store_span_metric(
- 321,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.domain": ""},
- )
- self.store_span_metric(
- 21,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.domain": ",sentry_table1,sentry_table2,"},
- )
- response = self.do_request(
- {
- "field": ["span.domain", "p75(span.self_time)"],
- "query": "has:span.domain",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["span.domain"] == ["sentry_table1", "sentry_table2"]
- assert meta["dataset"] == "spansMetrics"
- response = self.do_request(
- {
- "field": ["span.domain", "p75(span.self_time)"],
- "query": "!has:span.domain",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert meta["dataset"] == "spansMetrics"
- assert meta["fields"]["span.domain"] == "array"
- def test_unique_values_span_domain(self):
- self.store_span_metric(
- 321,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.domain": ",sentry_table1,"},
- )
- self.store_span_metric(
- 21,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.domain": ",sentry_table2,sentry_table3,"},
- )
- response = self.do_request(
- {
- "field": ["unique.span_domains", "count()"],
- "query": "",
- "orderby": "unique.span_domains",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 3
- assert data[0]["unique.span_domains"] == "sentry_table1"
- assert data[1]["unique.span_domains"] == "sentry_table2"
- assert data[2]["unique.span_domains"] == "sentry_table3"
- assert meta["fields"]["unique.span_domains"] == "string"
- def test_unique_values_span_domain_with_filter(self):
- self.store_span_metric(
- 321,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.domain": ",sentry_tible1,"},
- )
- self.store_span_metric(
- 21,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.domain": ",sentry_table2,sentry_table3,"},
- )
- response = self.do_request(
- {
- "field": ["unique.span_domains", "count()"],
- "query": "span.domain:sentry_tab*",
- "orderby": "unique.span_domains",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 2
- assert data[0]["unique.span_domains"] == "sentry_table2"
- assert data[1]["unique.span_domains"] == "sentry_table3"
- assert meta["fields"]["unique.span_domains"] == "string"
- def test_avg_if(self):
- self.store_span_metric(
- 100,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"release": "foo"},
- )
- self.store_span_metric(
- 200,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"release": "foo"},
- )
- self.store_span_metric(
- 10,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"release": "bar"},
- )
- response = self.do_request(
- {
- "field": ["avg_if(span.self_time, release, foo)"],
- "query": "",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["avg_if(span.self_time, release, foo)"] == 150
- assert meta["dataset"] == "spansMetrics"
- assert meta["fields"]["avg_if(span.self_time, release, foo)"] == "duration"
- def test_device_class(self):
- self.store_span_metric(
- 123,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"device.class": "1"},
- )
- self.store_span_metric(
- 678,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"device.class": "2"},
- )
- self.store_span_metric(
- 999,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"device.class": ""},
- )
- response = self.do_request(
- {
- "field": ["device.class", "p95()"],
- "query": "",
- "orderby": "p95()",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 3
- # Need to actually check the dict since the level for 1 isn't guaranteed to stay `low` or `medium`
- assert data[0]["device.class"] == map_device_class_level("1")
- assert data[1]["device.class"] == map_device_class_level("2")
- assert data[2]["device.class"] == "Unknown"
- assert meta["fields"]["device.class"] == "string"
- def test_device_class_filter(self):
- self.store_span_metric(
- 123,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"device.class": "1"},
- )
- # Need to actually check the dict since the level for 1 isn't guaranteed to stay `low`
- level = map_device_class_level("1")
- response = self.do_request(
- {
- "field": ["device.class", "count()"],
- "query": f"device.class:{level}",
- "orderby": "count()",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["device.class"] == level
- assert meta["fields"]["device.class"] == "string"
- def test_device_class_filter_unknown(self):
- self.store_span_metric(
- 123,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"device.class": ""},
- )
- response = self.do_request(
- {
- "field": ["device.class", "count()"],
- "query": "device.class:Unknown",
- "orderby": "count()",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["device.class"] == "Unknown"
- assert meta["fields"]["device.class"] == "string"
- def test_http_response_rate(self):
- self.store_span_metric(
- 1,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.status_code": "200"},
- )
- self.store_span_metric(
- 3,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.status_code": "301"},
- )
- self.store_span_metric(
- 3,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.status_code": "404"},
- )
- self.store_span_metric(
- 4,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.status_code": "503"},
- )
- self.store_span_metric(
- 5,
- internal_metric=constants.SELF_TIME_LIGHT,
- timestamp=self.min_ago,
- tags={"span.status_code": "501"},
- )
- response = self.do_request(
- {
- "field": [
- "http_response_rate(200)", # By exact code
- "http_response_rate(3)", # By code class
- "http_response_rate(4)",
- "http_response_rate(5)",
- ],
- "query": "",
- "project": self.project.id,
- "dataset": "spansMetrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["http_response_rate(200)"] == 0.2
- assert data[0]["http_response_rate(3)"] == 0.2
- assert data[0]["http_response_rate(4)"] == 0.2
- assert data[0]["http_response_rate(5)"] == 0.4
- meta = response.data["meta"]
- assert meta["dataset"] == "spansMetrics"
- assert meta["fields"]["http_response_rate(200)"] == "percentage"
- @region_silo_test
- class OrganizationEventsMetricsEnhancedPerformanceEndpointTestWithMetricLayer(
- OrganizationEventsMetricsEnhancedPerformanceEndpointTest
- ):
- def setUp(self):
- super().setUp()
- self.features["organizations:use-metrics-layer"] = True
- @pytest.mark.xfail(reason="Not implemented")
- def test_time_spent_percentage(self):
- super().test_time_spent_percentage()
- @pytest.mark.xfail(reason="Not implemented")
- def test_time_spent_percentage_local(self):
- super().test_time_spent_percentage_local()
- @pytest.mark.xfail(reason="Cannot group by function 'if'")
- def test_span_module(self):
- super().test_span_module()
- @pytest.mark.xfail(reason="Cannot search by tags")
- def test_tag_search(self):
- super().test_tag_search()
- @pytest.mark.xfail(reason="Cannot search by tags")
- def test_free_text_search(self):
- super().test_free_text_search()
- @pytest.mark.xfail(reason="Not implemented")
- def test_avg_compare(self):
- super().test_avg_compare()
- @pytest.mark.xfail(reason="Not implemented")
- def test_span_domain_array(self):
- super().test_span_domain_array()
- @pytest.mark.xfail(reason="Not implemented")
- def test_span_domain_array_filter(self):
- super().test_span_domain_array_filter()
- @pytest.mark.xfail(reason="Not implemented")
- def test_span_domain_array_filter_wildcard(self):
- super().test_span_domain_array_filter_wildcard()
- @pytest.mark.xfail(reason="Not implemented")
- def test_span_domain_array_has_filter(self):
- super().test_span_domain_array_has_filter()
- @pytest.mark.xfail(reason="Not implemented")
- def test_unique_values_span_domain(self):
- super().test_unique_values_span_domain()
- @pytest.mark.xfail(reason="Not implemented")
- def test_unique_values_span_domain_with_filter(self):
- super().test_unique_values_span_domain_with_filter()
- @pytest.mark.xfail(reason="Not implemented")
- def test_avg_if(self):
- super().test_avg_if()
- @pytest.mark.xfail(reason="Not implemented")
- def test_device_class_filter(self):
- super().test_device_class_filter()
- @pytest.mark.xfail(reason="Not implemented")
- def test_device_class(self):
- super().test_device_class()
|