Skip to content

fix(grouping): Only collect metadata timing metric when actually getting metadata #81252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/sentry/grouping/ingest/grouphash_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
TemplateHashingMetadata,
)
from sentry.utils import metrics
from sentry.utils.metrics import MutableTags

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -93,7 +94,7 @@
}


def create_or_update_grouphash_metadata(
def create_or_update_grouphash_metadata_if_needed(
event: Event,
project: Project,
grouphash: GroupHash,
Expand All @@ -105,7 +106,12 @@ def create_or_update_grouphash_metadata(
# we'll have to override the metadata creation date for them.

if created:
hash_basis, hashing_metadata = get_hash_basis_and_metadata(event, project, variants)
with metrics.timer(
"grouping.grouphashmetadata.get_hash_basis_and_metadata"
) as metrics_timer_tags:
hash_basis, hashing_metadata = get_hash_basis_and_metadata(
event, project, variants, metrics_timer_tags
)

GroupHashMetadata.objects.create(
grouphash=grouphash,
Expand All @@ -121,7 +127,10 @@ def create_or_update_grouphash_metadata(


def get_hash_basis_and_metadata(
event: Event, project: Project, variants: dict[str, BaseVariant]
event: Event,
project: Project,
variants: dict[str, BaseVariant],
metrics_timer_tags: MutableTags,
) -> tuple[HashBasis, HashingMetadata]:
hashing_metadata: HashingMetadata = {}

Expand Down Expand Up @@ -168,6 +177,8 @@ def get_hash_basis_and_metadata(
)
return (HashBasis.UNKNOWN, {})

metrics_timer_tags["hash_basis"] = hash_basis

# Gather different metadata depending on the grouping method

if hash_basis == HashBasis.STACKTRACE:
Expand Down
9 changes: 4 additions & 5 deletions src/sentry/grouping/ingest/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)
from sentry.grouping.ingest.config import is_in_transition
from sentry.grouping.ingest.grouphash_metadata import (
create_or_update_grouphash_metadata,
create_or_update_grouphash_metadata_if_needed,
record_grouphash_metadata_metrics,
)
from sentry.grouping.variants import BaseVariant
Expand Down Expand Up @@ -233,10 +233,9 @@ def get_or_create_grouphashes(
if options.get("grouping.grouphash_metadata.ingestion_writes_enabled") and features.has(
"organizations:grouphash-metadata-creation", project.organization
):
with metrics.timer("grouping.grouphashmetadata.create_or_update_grouphash_metadata"):
create_or_update_grouphash_metadata(
event, project, grouphash, created, grouping_config, variants
)
create_or_update_grouphash_metadata_if_needed(
event, project, grouphash, created, grouping_config, variants
)

if grouphash.metadata:
record_grouphash_metadata_metrics(grouphash.metadata)
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/grouping/test_grouphash_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _assert_and_snapshot_results(
lines: list[str] = []
variants = event.get_grouping_variants()

hash_basis, hashing_metadata = get_hash_basis_and_metadata(event, project, variants)
hash_basis, hashing_metadata = get_hash_basis_and_metadata(event, project, variants, {})

with patch("sentry.grouping.ingest.grouphash_metadata.metrics.incr") as mock_metrics_incr:
record_grouphash_metadata_metrics(
Expand Down
Loading