test_metrics_extraction.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import uuid
  2. import confluent_kafka as kafka
  3. import pytest
  4. from sentry.sentry_metrics.indexer.strings import SHARED_STRINGS
  5. from sentry.testutils.cases import TransactionTestCase
  6. from sentry.testutils.helpers.datetime import before_now, iso_format
  7. from sentry.testutils.helpers.features import Feature
  8. from sentry.testutils.helpers.options import override_options
  9. from sentry.testutils.relay import RelayStoreHelper
  10. from sentry.testutils.skips import requires_kafka
  11. from sentry.utils import json
  12. pytestmark = [requires_kafka]
  13. class MetricsExtractionTest(RelayStoreHelper, TransactionTestCase):
  14. @pytest.mark.skip("breaks in Relay for unknown reasons")
  15. @override_options({"relay.transaction-names-client-based": 1.0})
  16. def test_all_transaction_metrics_emitted(self):
  17. with Feature(
  18. {
  19. "organizations:transaction-metrics-extraction": True,
  20. }
  21. ):
  22. event_data = {
  23. "type": "transaction",
  24. "transaction": "foo",
  25. "transaction_info": {"source": "url"}, # 'transaction' tag not extracted
  26. "timestamp": iso_format(before_now(seconds=1)),
  27. "start_timestamp": iso_format(before_now(seconds=2)),
  28. "contexts": {
  29. "trace": {
  30. "trace_id": 32 * "b",
  31. "span_id": 16 * "c",
  32. "type": "trace",
  33. }
  34. },
  35. "user": {"id": 123},
  36. "measurements": {
  37. "fp": {"value": 2258.060000000114},
  38. "fcp": {"value": 2258.060000000114},
  39. "lcp": {"value": 2807.335},
  40. "inp": {"value": 51.318},
  41. "fid": {"value": 3.4900000027846545},
  42. "cls": {"value": 0.0382},
  43. "frames_total": {"value": 100},
  44. "frames_slow": {"value": 10},
  45. "frames_frozen": {"value": 5},
  46. "stall_count": {"value": 2},
  47. "stall_total_time": {"value": 12},
  48. "stall_longest_time": {"value": 7},
  49. "app_start_warm": {"value": 0.001},
  50. "app_start_cold": {"value": 0.001},
  51. "ttfb": {"value": 5},
  52. "ttfb.requesttime": {"value": 6},
  53. },
  54. "spans": [
  55. {
  56. "op": op,
  57. "trace_id": 32 * "b",
  58. "span_id": 16 * "1",
  59. "start_timestamp": iso_format(before_now(seconds=2)),
  60. "timestamp": iso_format(before_now(seconds=1)),
  61. }
  62. for op in ("db", "http", "resource", "browser", "ui")
  63. ],
  64. }
  65. settings = {
  66. "bootstrap.servers": "127.0.0.1:9092", # TODO: read from django settings here
  67. "group.id": "test-consumer-%s" % uuid.uuid4().hex,
  68. "enable.auto.commit": True,
  69. "auto.offset.reset": "earliest",
  70. }
  71. consumer = kafka.Consumer(settings)
  72. consumer.assign([kafka.TopicPartition("ingest-metrics", 0)])
  73. self.post_and_retrieve_event(event_data)
  74. strings_emitted = set()
  75. for _ in range(1000):
  76. message = consumer.poll(timeout=1.0)
  77. if message is None:
  78. break
  79. message = json.loads(message.value())
  80. if message["project_id"] == self.project.id:
  81. strings_emitted.add(message["name"])
  82. for key, value in message["tags"].items():
  83. strings_emitted.add(key)
  84. strings_emitted.add(value)
  85. consumer.close()
  86. #: These strings should be common strings, but we cannot add them
  87. #: to the indexer because they already exist in the release health
  88. #: indexer db.
  89. known_non_common_strings = {
  90. "other",
  91. "platform",
  92. "d:transactions/measurements.inp@millisecond",
  93. }
  94. # Make sure that all the standard strings are part of the list of common strings:
  95. non_common_strings = strings_emitted - SHARED_STRINGS.keys()
  96. assert non_common_strings == known_non_common_strings