getsentry / sentry-infra-tools

An attempt to move senytry-kube to its own repository
1 stars 0 forks source link

fix(service_registry): Dynamic detection of path #33

Open nikhars opened 1 day ago

nikhars commented 1 day ago

Description

Since the service registry is moving to its own repository, we need a mechanism to get the relevant data from there. This PR introduces a mechanism which first checks whether the service registry package is installed or not. If yes, uses the file from the package. If not, falls back to hardcoded path from before.

Local testing

Added this test code to see the path being resolved

def test_get_service_registry_package_installed():
    path = get_service_registry_filepath()
    print(path)

Output Without the sentry-service-registry, notice the path

~/w/sentry-infra-tools/l/tests  nikhars/fix/service-registry +2 !2 ?2  pytest -vv test_utils.py::test_get_service_registry_package_installed -s
============================================== test session starts ===============================================
platform darwin -- Python 3.11.6, pytest-8.3.3, pluggy-1.5.0 -- /Users/nikharsaxena/workspace/sentry-infra-tools/.venv/bin/python3
cachedir: .pytest_cache
rootdir: /Users/nikharsaxena/workspace/sentry-infra-tools
configfile: pyproject.toml
plugins: anyio-4.4.0
collected 1 item

test_utils.py::test_get_service_registry_package_installed /Users/nikharsaxena/workspace/sentry-infra-tools/libsentrykube/tests/shared_config/_materialized_configs/service_registry/combined/service_registry.json
PASSED

=============================================== 1 passed in 0.02s ================================================
 ~/w/sentry-infra-tools/l/tests  nikhars/fix/service-registry +2 !2 ?2  pip show sentry-service-registry
WARNING: Package(s) not found: sentry-service-registry

With sentry-service-registry installed, notice the path printed at the end of the test

 ~/w/sentry-infra-tools/l/tests  nikhars/fix/service-registry +2 !2 ?2  pip install git+ssh://git@github.com/getsentry/service-registry.git@0.0.10
Collecting git+ssh://****@github.com/getsentry/service-registry.git@0.0.10
  Cloning ssh://****@github.com/getsentry/service-registry.git (to revision 0.0.10) to /private/var/folders/tb/g9_mm4k51rq0z28tykhkr66m0000gn/T/pip-req-build-2defvos1
  Running command git clone --filter=blob:none --quiet 'ssh://****@github.com/getsentry/service-registry.git' /private/var/folders/tb/g9_mm4k51rq0z28tykhkr66m0000gn/T/pip-req-build-2defvos1
  Running command git checkout -q c1cec4f193d167035c544c679e444f94836a6bf0
  Resolved ssh://****@github.com/getsentry/service-registry.git to commit c1cec4f193d167035c544c679e444f94836a6bf0
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: sentry-service-registry
  Building wheel for sentry-service-registry (pyproject.toml) ... done
  Created wheel for sentry-service-registry: filename=sentry_service_registry-0.0.10-py3-none-any.whl size=39005 sha256=287d40116aeb45ef1dd9093112d9ec7dfd6894ab138af1848f21d111464b498b
  Stored in directory: /private/var/folders/tb/g9_mm4k51rq0z28tykhkr66m0000gn/T/pip-ephem-wheel-cache-z717bjbd/wheels/cb/cc/5d/f07e02cab7ca2cfa2373ef52620c6ea7d4752793a1d3f7f6f1
Successfully built sentry-service-registry
Installing collected packages: sentry-service-registry
Successfully installed sentry-service-registry-0.0.10

[notice] A new release of pip available: 22.2.2 -> 24.2
[notice] To update, run: pip install --upgrade pip
 ~/w/sentry-infra-tools/l/tests  nikhars/fix/service-registry +2 !2 ?2  pytest -vv test_utils.py::test_get_service_registry_package_installed -s
============================================== test session starts ===============================================
platform darwin -- Python 3.11.6, pytest-8.3.3, pluggy-1.5.0 -- /Users/nikharsaxena/workspace/sentry-infra-tools/.venv/bin/python3
cachedir: .pytest_cache
rootdir: /Users/nikharsaxena/workspace/sentry-infra-tools
configfile: pyproject.toml
plugins: anyio-4.4.0
collected 1 item

test_utils.py::test_get_service_registry_package_installed /Users/nikharsaxena/workspace/sentry-infra-tools/.venv/lib/python3.11/site-packages/sentry_service_registry/sentry_service_registry/services.json
PASSED

=============================================== 1 passed in 0.01s ================================================
 ~/w/sentry-infra-tools/l/tests  nikhars/fix/service-registry +2 !2 ?2  pip show sentry-service-registry
 ok | direnv  3.11.6 py  10:48:17
Name: sentry-service-registry
Version: 0.0.10
Summary: Sentry Internal Service Registry
Home-page:
Author:
Author-email:
License:
Location: /Users/nikharsaxena/workspace/sentry-infra-tools/.venv/lib/python3.11/site-packages
Requires:
Required-by:
fpacifici commented 8 hours ago

Isn't the ops repo still using its own version of sentry-kube? People are still making changes there, would it be more sensible to make this change inside the ops repo in order not to have the two implementations diverge ?