Skip to content

Commit 58048aa

Browse files
committed
Add cross organisation methods for the string indexer
1 parent 302f747 commit 58048aa

File tree

6 files changed

+66
-0
lines changed

6 files changed

+66
-0
lines changed

src/sentry/sentry_metrics/indexer/base.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,19 @@ def reverse_resolve(self, use_case_id: UseCaseKey, org_id: int, id: int) -> Opti
265265
Returns None if the entry cannot be found.
266266
"""
267267
raise NotImplementedError()
268+
269+
def resolve_shared_org(self, string: str) -> Optional[int]:
270+
"""
271+
Look up the index for a shared (cross organisation) string.
272+
273+
Typically, this function will only lookup strings that are statically defined but
274+
regardless of the mechanism these are strings that are not organisation or use-case specific.
275+
"""
276+
raise NotImplementedError()
277+
278+
def reverse_shared_org_resolve(self, id: int) -> Optional[str]:
279+
"""Lookup the stored string given integer for a shared (cross organisation) ID.
280+
281+
Returns None if the entry cannot be found.
282+
"""
283+
raise NotImplementedError()

src/sentry/sentry_metrics/indexer/cache.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,13 @@ def resolve(self, use_case_id: UseCaseKey, org_id: int, string: str) -> Optional
167167

168168
def reverse_resolve(self, use_case_id: UseCaseKey, org_id: int, id: int) -> Optional[str]:
169169
return self.indexer.reverse_resolve(use_case_id, org_id, id)
170+
171+
def resolve_shared_org(self, string: str) -> Optional[int]:
172+
raise NotImplementedError(
173+
"This class should not be used directly, use a wrapping class that derives from StaticStringIndexer"
174+
)
175+
176+
def reverse_shared_org_resolve(self, id: int) -> Optional[str]:
177+
raise NotImplementedError(
178+
"This class should not be used directly, use a wrapping class that derives from StaticStringIndexer"
179+
)

src/sentry/sentry_metrics/indexer/cloudspanner/cloudspanner.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,16 @@ def reverse_resolve(self, use_case_id: UseCaseKey, org_id: int, id: int) -> Opti
431431
else:
432432
return str(results_list[0][0])
433433

434+
def resolve_shared_org(self, string: str) -> Optional[int]:
435+
raise NotImplementedError(
436+
"This class should not be used directly, use the wrapping class CloudSpannerIndexer"
437+
)
438+
439+
def reverse_shared_org_resolve(self, id: int) -> Optional[str]:
440+
raise NotImplementedError(
441+
"This class should not be used directly, use the wrapping class CloudSpannerIndexer"
442+
)
443+
434444

435445
class CloudSpannerIndexer(StaticStringIndexer):
436446
def __init__(self, **kwargs: Any) -> None:

src/sentry/sentry_metrics/indexer/mock.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ def _record(self, org_id: int, string: str) -> Optional[int]:
6767
self._reverse[index] = string
6868
return index
6969

70+
def resolve_shared_org(self, string: str) -> Optional[int]:
71+
raise NotImplementedError(
72+
"This class should not be used directly, use the wrapping class SimpleIndexer"
73+
)
74+
75+
def reverse_shared_org_resolve(self, id: int) -> Optional[str]:
76+
raise NotImplementedError(
77+
"This class should not be used directly, use the wrapping class SimpleIndexer"
78+
)
79+
7080

7181
class SimpleIndexer(StaticStringIndexer):
7282
def __init__(self) -> None:

src/sentry/sentry_metrics/indexer/postgres/postgres_v2.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,16 @@ def reverse_resolve(self, use_case_id: UseCaseKey, org_id: int, id: int) -> Opti
198198
def _table(self, use_case_id: UseCaseKey) -> IndexerTable:
199199
return TABLE_MAPPING[use_case_id]
200200

201+
def resolve_shared_org(self, string: str) -> Optional[int]:
202+
raise NotImplementedError(
203+
"This class should not be used directly, use the wrapping class PostgresIndexer"
204+
)
205+
206+
def reverse_shared_org_resolve(self, id: int) -> Optional[str]:
207+
raise NotImplementedError(
208+
"This class should not be used directly, use the wrapping class PostgresIndexer"
209+
)
210+
201211

202212
class PostgresIndexer(StaticStringIndexer):
203213
def __init__(self) -> None:

src/sentry/sentry_metrics/indexer/strings.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,13 @@ def reverse_resolve(self, use_case_id: UseCaseKey, org_id: int, id: int) -> Opti
175175
if id in REVERSE_SHARED_STRINGS:
176176
return REVERSE_SHARED_STRINGS[id]
177177
return self.indexer.reverse_resolve(use_case_id=use_case_id, org_id=org_id, id=id)
178+
179+
def resolve_shared_org(self, string: str) -> Optional[int]:
180+
if string in SHARED_STRINGS:
181+
return SHARED_STRINGS[string]
182+
return None
183+
184+
def reverse_shared_org_resolve(self, id: int) -> Optional[str]:
185+
if id in REVERSE_SHARED_STRINGS:
186+
return REVERSE_SHARED_STRINGS[id]
187+
return None

0 commit comments

Comments
 (0)