Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/sentry/preprod/eap/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
ResolvedAttribute(
public_alias="metrics_artifact_type",
internal_name="metrics_artifact_type",
search_type="integer",
search_type="string",
),
ResolvedAttribute(
public_alias="max_install_size",
Expand Down
15 changes: 14 additions & 1 deletion src/sentry/preprod/eap/write.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import logging
import uuid
from typing import Any

Expand Down Expand Up @@ -27,6 +28,18 @@
from sentry.utils.eap import hex_to_item_id
from sentry.utils.kafka_config import get_topic_definition

logger = logging.getLogger(__name__)


def _metrics_artifact_type_label(value: int | None) -> str | None:
if value is None:
return None
try:
return PreprodArtifactSizeMetrics.MetricsArtifactType(value).to_choice_label()
except (ValueError, KeyError):
logger.warning("preprod.eap.unknown_metrics_artifact_type", extra={"value": value})
return None


def produce_preprod_size_metric_to_eap(
size_metric: PreprodArtifactSizeMetrics,
Expand Down Expand Up @@ -65,7 +78,7 @@ def produce_preprod_size_metric_to_eap(
"preprod_artifact_id": size_metric.preprod_artifact_id,
"size_metric_id": size_metric.id,
"sub_item_type": "size_metric",
"metrics_artifact_type": size_metric.metrics_artifact_type,
"metrics_artifact_type": _metrics_artifact_type_label(size_metric.metrics_artifact_type),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to confirm this is safe to do and that you've tested changing a column type with existing data.

"identifier": size_metric.identifier,
"min_install_size": size_metric.min_install_size,
"max_install_size": size_metric.max_install_size,
Expand Down
8 changes: 8 additions & 0 deletions src/sentry/preprod/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,14 @@ def as_choices(cls) -> tuple[tuple[int, str], ...]:
(cls.APP_CLIP_ARTIFACT, "app_clip_artifact"),
)

def to_choice_label(self) -> str:
"""Return the human-readable choice label for this enum value.

Used by the EAP write path to store artifact type as a string attribute.
"""
choices = dict(self.as_choices())
return choices[self.value]

class SizeAnalysisState(IntEnum):
PENDING = 0
"""Size analysis has not started yet."""
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/search/eap/preprod_size/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
for column in COMMON_COLUMNS
+ [
ResolvedAttribute(
public_alias="metrics_artifact_type",
public_alias="artifact_type",
internal_name="metrics_artifact_type",
search_type="integer",
search_type="string",
),
ResolvedAttribute(
public_alias="install_size",
Expand Down
7 changes: 7 additions & 0 deletions static/app/utils/fields/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {TagCollection} from 'sentry/types/group';
import {CONDITIONS_ARGUMENTS, WEB_VITALS_QUALITY} from 'sentry/utils/discover/types';
import {OurLogKnownFieldKey} from 'sentry/views/explore/logs/types';
import {SpanFields} from 'sentry/views/insights/types';
import {METRICS_ARTIFACT_TYPES} from 'sentry/views/settings/project/preprod/types';

// Don't forget to update https://docs.sentry.io/product/sentry-basics/search/searchable-properties/ for any changes made here

Expand Down Expand Up @@ -2518,6 +2519,12 @@ const PREPROD_FIELD_DEFINITIONS: Record<string, FieldDefinition> = {
kind: FieldKind.FIELD,
valueType: FieldValueType.STRING,
},
artifact_type: {
desc: t('The type of artifact component (e.g., main app, watch app, app clip)'),
kind: FieldKind.FIELD,
valueType: FieldValueType.STRING,
values: [...METRICS_ARTIFACT_TYPES],
},
build_configuration_name: {
desc: t('The name of the build configuration (e.g., Debug, Release)'),
kind: FieldKind.FIELD,
Expand Down
4 changes: 4 additions & 0 deletions static/app/views/explore/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const SENTRY_LOG_NUMBER_TAGS: string[] = [OurLogKnownFieldKey.SEVERITY_NU
export const SENTRY_PREPROD_STRING_TAGS: string[] = [
'app_id',
'app_name',
'artifact_type',
'build_configuration_name',
'build_number',
'build_version',
Expand Down Expand Up @@ -126,6 +127,9 @@ export const HIDDEN_PREPROD_ATTRIBUTES = [
'tags[artifact_state,number]',
'tags[artifact_date_built,number]',
'tags[build_number,number]',
'metrics_artifact_type',
'tags[metrics_artifact_type,number]',
'tags[artifact_type,number]',
];

export const SENTRY_TRACEMETRIC_STRING_TAGS: string[] = [
Expand Down
10 changes: 8 additions & 2 deletions static/app/views/settings/project/preprod/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ const ALL_MEASUREMENTS = ['absolute', 'absolute_diff', 'relative_diff'] as const

export type MeasurementType = (typeof ALL_MEASUREMENTS)[number];

export const ALL_ARTIFACT_TYPES = [
'all_artifacts',
/**
* Canonical list of metrics artifact types.
* Keep in sync with PreprodArtifactSizeMetrics.MetricsArtifactType.as_choices() in
* src/sentry/preprod/models.py
*/
export const METRICS_ARTIFACT_TYPES = [
'main_artifact',
'watch_artifact',
'android_dynamic_feature_artifact',
'app_clip_artifact',
] as const;

export const ALL_ARTIFACT_TYPES = ['all_artifacts', ...METRICS_ARTIFACT_TYPES] as const;

export type ArtifactType = (typeof ALL_ARTIFACT_TYPES)[number];

export const DEFAULT_ARTIFACT_TYPE: ArtifactType = 'main_artifact';
Expand Down
4 changes: 2 additions & 2 deletions tests/sentry/preprod/eap/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def test_write_preprod_size_metric_encodes_all_fields_correctly(self, mock_produ
assert attrs["preprod_artifact_id"].int_value == artifact.id
assert attrs["size_metric_id"].int_value == size_metric.id
assert (
attrs["metrics_artifact_type"].int_value
== PreprodArtifactSizeMetrics.MetricsArtifactType.MAIN_ARTIFACT
attrs["metrics_artifact_type"].string_value
== PreprodArtifactSizeMetrics.MetricsArtifactType.MAIN_ARTIFACT.to_choice_label()
)
assert attrs["identifier"].string_value == "com.example.feature"
assert attrs["min_install_size"].int_value == 1000
Expand Down
4 changes: 2 additions & 2 deletions tests/snuba/preprod/eap/test_preprod_eap_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def test_write_and_read_size_metric_round_trip(self):
response.column_values[columns["size_metric_id"]].results[0].val_int == size_metric.id
)
assert (
response.column_values[columns["metrics_artifact_type"]].results[0].val_int
== PreprodArtifactSizeMetrics.MetricsArtifactType.MAIN_ARTIFACT
response.column_values[columns["metrics_artifact_type"]].results[0].val_str
== PreprodArtifactSizeMetrics.MetricsArtifactType.MAIN_ARTIFACT.to_choice_label()
)
assert response.column_values[columns["max_install_size"]].results[0].val_int == 5000
assert response.column_values[columns["max_download_size"]].results[0].val_int == 3000
Expand Down
Loading