Sentry 监控 - Snuba 数据中台本地开发环境配置实战

安全 应用安全 中台
如果您的开发机器没有运行上述系统之一,则需要安装 Rust 工具链。按照 https://www.rust-lang.org/tools/install 上的说明安装编译器和相关工具。安装后,Sentry 安装程序将自动使用 Rust 构建所有二进制模块,无需额外配置。

[[437983]]

本文转载自微信公众号「黑客下午茶」,作者为少 。转载本文请联系黑客下午茶公众号。

克隆仓库

分别克隆 getsentry/sentry 与 getsentry/snuba:

git clone https://github.com/getsentry/sentry.git

git clone https://github.com/getsentry/snuba.git

安装系统依赖(以 Mac 为例)

Xcode CLI tools

  1. xcode-select --install 

Brewfile

进入 sentry 文件夹,你会看到一个 Brewfile 文件:

  1. cd sentry 

Brewfile

  1. # required to run devservices 
  2. cask 'docker' 
  3.  
  4. brew 'pyenv' 
  5.  
  6. # required for pyenv's python-build 
  7. brew 'openssl' 
  8. brew 'readline' 
  9.  
  10. # required for yarn test -u 
  11. brew 'watchman' 
  12.  
  13. # required to build some of sentry's dependencies 
  14. brew 'pkgconfig' 
  15. brew 'libxslt' 
  16. brew 'libxmlsec1' 
  17. brew 'geoip' 
  18.  
  19. # Currently needed because on Big Sur there's no wheel for it 
  20. brew 'librdkafka' 
  21.  
  22. # direnv isn't defined here, because we have it configured to check for a bootstrapped environment. 
  23. # If it's installed in the early steps of the setup process, it just leads to confusion. 
  24. # brew 'direnv' 
  25.  
  26. tap 'homebrew/cask' 
  27.  
  28. # required for acceptance testing 
  29. cask 'chromedriver' 

如果你本地已经安装了 Docker Desktop 并且已经启动,可以把 cask 'docker' 注释掉。

接下来,运行:

  1. brew bundle --verbose 

如果你之前本地没有 Docker Desktop,则还需要手动启动一下它:

  1. open -g -a Docker.app 

构建工具链

Sentry 依赖于 Python Wheels(包含二进制扩展模块的包),官方为以下平台分发:

  • Linux 兼容 PEP-513 (manylinux1)
  • macOS 10.15 或更高版本

如果您的开发机器没有运行上述系统之一,则需要安装 Rust 工具链。按照 https://www.rust-lang.org/tools/install 上的说明安装编译器和相关工具。安装后,Sentry 安装程序将自动使用 Rust 构建所有二进制模块,无需额外配置。

官方通常会跟踪最新的稳定 Rust 版本,该版本每六周更新一次。因此,请确保通过偶尔运行来使您的 Rust 工具链保持最新:

  1. rustup update stable 

Python

Sentry 使用 pyenv 来安装和管理 Python 版本。它是在您运行 brew bundle 时安装的。

要安装所需版本的 Python,您需要运行以下命令。这将需要一段时间,因为您的计算机实际上正在编译 Python!

  1. make setup-pyenv 

这里假设你是 Zsh 用户。

如果您键入 which python,您应该看到类似 $HOME/.pyenv/shims/python 而不是 /usr/bin/python 的内容。这是因为以下内容已添加到您的启动脚本中:

cat ~/.zprofile,你会看到如下内容:

  1. # MacPorts Installer addition on 2021-10-20_at_11:48:22: adding an appropriate PATH variable for use with MacPorts. 
  2. export PATH="/opt/local/bin:/opt/local/sbin:$PATH" 
  3. # Finished adapting your PATH environment variable for use with MacPorts. 
  4.  
  5. # It is assumed that pyenv is installed via Brew, so this is all we need to do. 
  6. eval "$(pyenv init --path)" 

虚拟环境

您现在已准备好创建 Python 虚拟环境。运行:

  1. python -m venv .venv 

并激活虚拟环境:

  1. source .venv/bin/activate 

如果一切正常,运行 which python 现在应该会导致类似 /Users/you/sentry/.venv/bin/python 的结果。

Snuba 配置实战

启动 Snuba 相关依赖项容器

 

  1. cd ../sentry 
  2. git checkout master 
  3. git pull 
  4.  
  5. source .venv/bin/activate 
  6. sentry devservices up --exclude=snuba 
  7.  
  8. # 11:17:59 [WARNING] sentry.utils.geo: settings.GEOIP_PATH_MMDB not configured. 
  9. # 11:18:01 [INFO] sentry.plugins.github: apps-not-configured 
  10. # > Pulling image 'postgres:9.6-alpine' 
  11. # > Pulling image 'yandex/clickhouse-server:20.3.9.70' 
  12. # > Not starting container 'sentry_relay' because it should be started on-demand with devserver. 
  13. # > Creating 'sentry_redis' volume 
  14. # > Creating 'sentry_zookeeper_6' volume 
  15. # > Creating 'sentry_kafka_6' volume 
  16. # > Creating container 'sentry_redis' 
  17. # > Creating container 'sentry_zookeeper' 
  18. # > Creating container 'sentry_kafka' 
  19. # > Starting container 'sentry_redis' (listening: ('127.0.0.1', 6379)) 
  20. # > Starting container 'sentry_kafka' (listening: ('127.0.0.1', 9092)) 
  21. # > Starting container 'sentry_zookeeper' 
  22. # > Creating 'sentry_clickhouse' volume 
  23. # > Creating container 'sentry_clickhouse' 
  24. # > Creating 'sentry_postgres' volume 
  25. # > Creating 'sentry_wal2json' volume 
  26. # > Starting container 'sentry_clickhouse' (listening: ('127.0.0.1', 9000), ('127.0.0.1', 9009), ('127.0.0.1', 8123)) 
  27. # > Creating container 'sentry_postgres' 
  28. # > Starting container 'sentry_postgres' (listening: ('127.0.0.1', 5432)) 

这将在 master 上获取最新版本的 Sentry,并调出所有 snuba 的依赖项。

Snuba 主要依赖 clickhouse,zookeeper,kafka,redis 相关容器。

docker ps 查看一下:

  1. 1149a6f6ff23   postgres:9.6-alpine                  "docker-entrypoint.s…"   3 minutes ago   Up 3 minutes   127.0.0.1:5432->5432/tcp                                                       sentry_postgres 
  2. a7f3af7d52bb   yandex/clickhouse-server:20.3.9.70   "/entrypoint.sh"         3 minutes ago   Up 3 minutes   127.0.0.1:8123->8123/tcp, 127.0.0.1:9000->9000/tcp, 127.0.0.1:9009->9009/tcp   sentry_clickhouse 
  3. 68913ee15c43   confluentinc/cp-zookeeper:6.2.0      "/etc/confluent/dock…"   3 minutes ago   Up 3 minutes   2181/tcp, 2888/tcp, 3888/tcp                                                   sentry_zookeeper 
  4. 5a248eb26ed3   confluentinc/cp-kafka:6.2.0          "/etc/confluent/dock…"   3 minutes ago   Up 3 minutes   127.0.0.1:9092->9092/tcp                                                       sentry_kafka 
  5. 0573aff7b5af   redis:5.0-alpine                     "docker-entrypoint.s…"   3 minutes ago   Up 3 minutes   127.0.0.1:6379->6379/tcp                                                       sentry_redis 

设置 Snuba 虚拟环境

  1. cd snuba 
  2. make pyenv-setup 
  3. python -m venv .venv 
  4. source .venv/bin/activate 
  5. pip install --upgrade pip==21.1.3 
  6. make develop 

查看迁移列表

  1. snuba migrations list 
  2. #  system 
  3. #  [ ]  0001_migrations 
  4. #  events 
  5. #  [ ]  0001_events_initial 
  6. #  [ ]  0002_events_onpremise_compatibility 
  7. #  [ ]  0003_errors 
  8. #  [ ]  0004_errors_onpremise_compatibility 
  9. #  [ ]  0005_events_tags_hash_map (blocking) 
  10. #  [ ]  0006_errors_tags_hash_map (blocking) 
  11. #  [ ]  0007_groupedmessages 
  12. #  [ ]  0008_groupassignees 
  13. #  [ ]  0009_errors_add_http_fields 
  14. #  [ ]  0010_groupedmessages_onpremise_compatibility (blocking) 
  15. #  [ ]  0011_rebuild_errors 
  16. #  [ ]  0012_errors_make_level_nullable 
  17. #  [ ]  0013_errors_add_hierarchical_hashes 
  18. #  [ ]  0014_backfill_errors (blocking) 
  19. #  [ ]  0015_truncate_events 
  20. #  transactions 
  21. #  [ ]  0001_transactions 
  22. #  [ ]  0002_transactions_onpremise_fix_orderby_and_partitionby (blocking) 
  23. #  [ ]  0003_transactions_onpremise_fix_columns (blocking) 
  24. #  [ ]  0004_transactions_add_tags_hash_map (blocking) 
  25. #  [ ]  0005_transactions_add_measurements 
  26. #  [ ]  0006_transactions_add_http_fields 
  27. #  [ ]  0007_transactions_add_discover_cols 
  28. #  [ ]  0008_transactions_add_timestamp_index 
  29. #  [ ]  0009_transactions_fix_title_and_message 
  30. #  [ ]  0010_transactions_nullable_trace_id 
  31. #  [ ]  0011_transactions_add_span_op_breakdowns 
  32. #  [ ]  0012_transactions_add_spans 
  33. #  discover 
  34. #  [ ]  0001_discover_merge_table 
  35. #  [ ]  0002_discover_add_deleted_tags_hash_map 
  36. #  [ ]  0003_discover_fix_user_column 
  37. #  [ ]  0004_discover_fix_title_and_message 
  38. #  [ ]  0005_discover_fix_transaction_name 
  39. #  [ ]  0006_discover_add_trace_id 
  40. #  [ ]  0007_discover_add_span_id 
  41. #  outcomes 
  42. #  [ ]  0001_outcomes 
  43. #  [ ]  0002_outcomes_remove_size_and_bytes 
  44. #  [ ]  0003_outcomes_add_category_and_quantity 
  45. #  [ ]  0004_outcomes_matview_additions (blocking) 
  46. #  metrics 
  47. #  [ ]  0001_metrics_buckets 
  48. #  [ ]  0002_metrics_sets 
  49. #  [ ]  0003_counters_to_buckets 
  50. #  [ ]  0004_metrics_counters 
  51. #  [ ]  0005_metrics_distributions_buckets 
  52. #  [ ]  0006_metrics_distributions 
  53. #  [ ]  0007_metrics_sets_granularity_10 
  54. #  [ ]  0008_metrics_counters_granularity_10 
  55. #  [ ]  0009_metrics_distributions_granularity_10 
  56. #  [ ]  0010_metrics_sets_granularity_1h 
  57. #  [ ]  0011_metrics_counters_granularity_1h 
  58. #  [ ]  0012_metrics_distributions_granularity_1h 
  59. #  [ ]  0013_metrics_sets_granularity_1d 
  60. #  [ ]  0014_metrics_counters_granularity_1d 
  61. #  [ ]  0015_metrics_distributions_granularity_1d 
  62. #  sessions 
  63. #  [ ]  0001_sessions 
  64. #  [ ]  0002_sessions_aggregates 
  65. #  [ ]  0003_sessions_matview 

运行迁移

  1. snuba migrations migrate --force 
  2. #  ...... 
  3. #  2021-12-01 19:45:57,557 Running migration: 0014_metrics_counters_granularity_1d 
  4. #  2021-12-01 19:45:57,575 Finished: 0014_metrics_counters_granularity_1d 
  5. #  2021-12-01 19:45:57,589 Running migration: 0015_metrics_distributions_granularity_1d 
  6. #  2021-12-01 19:45:57,610 Finished: 0015_metrics_distributions_granularity_1d 
  7. #  2021-12-01 19:45:57,623 Running migration: 0001_sessions 
  8. #  2021-12-01 19:45:57,656 Finished: 0001_sessions 
  9. #  2021-12-01 19:45:57,669 Running migration: 0002_sessions_aggregates 
  10. #  2021-12-01 19:45:57,770 Finished: 0002_sessions_aggregates 
  11. #  2021-12-01 19:45:57,792 Running migration: 0003_sessions_matview 
  12. #  2021-12-01 19:45:57,849 Finished: 0003_sessions_matview 
  13. #  Finished running migrations 

检查迁移

进入 Clickhouse 容器:

  1. docker exec -it sentry_clickhouse clickhouse-client 
  2. # 运行如下 `sql` 语句: 
  3. select count() from sentry_local 
  4.  
  5. # ClickHouse client version 20.3.9.70 (official build). 
  6. # Connecting to localhost:9000 as user default
  7. # Connected to ClickHouse server version 20.3.9 revision 54433. 
  8.  
  9. # a7f3af7d52bb :) select count() from sentry_local 
  10.  
  11. SELECT count() 
  12. FROM sentry_local 
  13.  
  14. # ┌─count()─┐ 
  15. # │       0 │ 
  16. # └─────────┘ 
  17.  
  18. # 1 rows in set. Elapsed: 0.008 sec.  
  19.  
  20. # a7f3af7d52bb :) 

查看相关实体数据集

  1. snuba entities list 
  2.  
  3. # Declared Entities: 
  4. # discover 
  5. # events 
  6. # groups 
  7. # groupassignee 
  8. # groupedmessage 
  9. # metrics_sets 
  10. # metrics_counters 
  11. # metrics_distributions 
  12. # outcomes 
  13. # outcomes_raw 
  14. # sessions 
  15. # org_sessions 
  16. # spans 
  17. # transactions 
  18. # discover_transactions 
  19. # discover_events 

启动开发服务器

此命令将启动 api 和所有 Snuba 消费者以从 Kafka 摄取数据:

  1. snuba devserver 

转到 http://localhost:1218/events/snql,你将会看到一个简易的查询 UI。

 

责任编辑:武晓燕 来源: 黑客下午茶
相关推荐

2021-11-26 18:53:53

监控数据中台

2021-10-11 19:36:08

监控Sentry架构

2021-10-09 23:33:55

监控

2021-10-09 00:00:40

Sentr 监控架构

2021-11-27 23:54:44

监控Snuba数据

2021-09-29 07:47:49

Sentry 监控Environment事件数据

2021-12-31 18:35:40

监控Sentry开发

2021-12-25 22:31:55

Sentry 监控SDK 开发 性能监控

2021-09-14 23:50:17

Sentry后端监控

2021-09-27 19:41:31

监控Sentry Alerts

2022-01-15 23:33:47

SentryPyCharm配置

2021-09-26 16:20:04

Sentry Dashboards 数据可视化

2011-06-13 13:06:48

Gtk Qt

2021-09-13 05:00:09

监控Trends 性能

2021-09-11 21:02:24

监控Sentry Web性能

2021-09-16 23:33:41

大数据Sentry监控

2013-01-25 14:08:32

S40Series 40

2010-05-12 16:24:32

Black Berry

2021-09-09 12:28:50

Sentry Web性能监控

2009-07-07 10:47:58

Servlet开发环境
点赞
收藏

51CTO技术栈公众号