test_metrics_extraction.py 4.3 KB

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