Skip to content

Commit

Permalink
ref(grouping): Add create_or_update_grouphash_metadata helper (#79512)
Browse files Browse the repository at this point in the history
This moves the grouphash-metadata-related code from `get_or_create_grouphashes` into a new helper function, `create_or_update_grouphash_metadata`, in its own module, in anticipation of a bunch more related code being added shortly.
  • Loading branch information
lobsterkatie authored Oct 24, 2024
1 parent a345553 commit 57b3184
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
24 changes: 24 additions & 0 deletions src/sentry/grouping/ingest/grouphash_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from __future__ import annotations

from sentry.models.grouphash import GroupHash
from sentry.models.grouphashmetadata import GroupHashMetadata


def create_or_update_grouphash_metadata(
grouphash: GroupHash,
created: bool,
grouping_config: str,
) -> None:
# TODO: Do we want to expand this to backfill metadata for existing grouphashes? If we do,
# we'll have to override the metadata creation date for them.

if created:
GroupHashMetadata.objects.create(
grouphash=grouphash,
latest_grouping_config=grouping_config,
)
elif grouphash.metadata and grouphash.metadata.latest_grouping_config != grouping_config:
# Keep track of the most recent config which computed this hash, so that once a
# config is deprecated, we can clear out the GroupHash records which are no longer
# being produced
grouphash.metadata.update(latest_grouping_config=grouping_config)
17 changes: 2 additions & 15 deletions src/sentry/grouping/ingest/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
load_grouping_config,
)
from sentry.grouping.ingest.config import is_in_transition
from sentry.grouping.ingest.grouphash_metadata import create_or_update_grouphash_metadata
from sentry.grouping.variants import BaseVariant
from sentry.models.grouphash import GroupHash
from sentry.models.grouphashmetadata import GroupHashMetadata
from sentry.models.project import Project
from sentry.utils import metrics
from sentry.utils.metrics import MutableTags
Expand Down Expand Up @@ -223,23 +223,10 @@ def get_or_create_grouphashes(
for hash_value in hashes:
grouphash, created = GroupHash.objects.get_or_create(project=project, hash=hash_value)

# TODO: Do we want to expand this to backfill metadata for existing grouphashes? If we do,
# we'll have to override the metadata creation date for them.
if options.get("grouping.grouphash_metadata.ingestion_writes_enabled") and features.has(
"organizations:grouphash-metadata-creation", project.organization
):
if created:
GroupHashMetadata.objects.create(
grouphash=grouphash,
latest_grouping_config=grouping_config,
)
elif (
grouphash.metadata and grouphash.metadata.latest_grouping_config != grouping_config
):
# Keep track of the most recent config which computed this hash, so that once a
# config is deprecated, we can clear out the GroupHash records which are no longer
# being produced
grouphash.metadata.update(latest_grouping_config=grouping_config)
create_or_update_grouphash_metadata(grouphash, created, grouping_config)

grouphashes.append(grouphash)

Expand Down

0 comments on commit 57b3184

Please sign in to comment.