-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(group-attributes): expose storage and entity, process messages (#…
…4507) * part 2 of setting up group_attributes * type * fix stuff after testing * add simple tests * typing, dlq incr * fix test * set literal * fix test * more tests * dev * project_id filter column
- Loading branch information
1 parent
17d74b9
commit 11ff698
Showing
13 changed files
with
408 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: v1 | ||
kind: dataset | ||
name: group_attributes | ||
|
||
entities: | ||
- group_attributes |
56 changes: 56 additions & 0 deletions
56
snuba/datasets/configuration/group_attributes/entities/group_attributes.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
version: v1 | ||
kind: entity | ||
name: group_attributes | ||
|
||
schema: | ||
[ | ||
{ name: project_id, type: UInt, args: { size: 64 } }, | ||
{ name: group_id, type: UInt, args: { size: 64 } }, | ||
|
||
{ name: group_status, type: UInt, args: { size: 8 } }, | ||
{ name: group_substatus, type: UInt, args: { size: 8, schema_modifiers: [ nullable ] } }, | ||
{ name: group_first_seen, type: DateTime }, | ||
{ name: group_num_comments, type: UInt, args: { size: 64 } }, | ||
|
||
{ name: assignee_user_id, type: UInt, args: { size: 64, schema_modifiers: [ nullable ] } }, | ||
{ name: assignee_team_id, type: UInt, args: { size: 64, schema_modifiers: [ nullable ] } }, | ||
|
||
{ name: owner_suspect_commit_user_id, type: UInt, args: { size: 64, schema_modifiers: [ nullable ] } }, | ||
{ name: owner_ownership_rule_user_id, type: UInt, args: { size: 64, schema_modifiers: [ nullable ] } }, | ||
{ name: owner_ownership_rule_team_id, type: UInt, args: { size: 64, schema_modifiers: [ nullable ] } }, | ||
{ name: owner_codeowners_user_id, type: UInt, args: { size: 64, schema_modifiers: [ nullable ] } }, | ||
{ name: owner_codeowners_team_id, type: UInt, args: { size: 64, schema_modifiers: [ nullable ] } }, | ||
|
||
{ name: deleted, type: UInt, args: { size: 8 } }, | ||
{ name: message_timestamp, type: DateTime }, | ||
{ name: partition, type: UInt, args: { size: 16 } }, | ||
{ name: offset, type: UInt, args: { size: 64 } }, | ||
] | ||
|
||
storages: | ||
- storage: group_attributes | ||
is_writable: true | ||
|
||
storage_selector: | ||
selector: DefaultQueryStorageSelector | ||
|
||
query_processors: | ||
- processor: ReferrerRateLimiterProcessor | ||
# - processor: ProjectReferrerRateLimiter | ||
# args: | ||
# project_column: project_id | ||
# - processor: ProjectRateLimiterProcessor | ||
# args: | ||
# project_column: project_id | ||
# - processor: ResourceQuotaProcessor | ||
# args: | ||
# project_field: project_id | ||
- processor: BasicFunctionsProcessor | ||
|
||
validate_data_model: error | ||
validators: | ||
- validator: EntityRequiredColumnValidator | ||
args: | ||
required_filter_columns: ["project_id"] | ||
|
||
required_time_column: null |
55 changes: 55 additions & 0 deletions
55
snuba/datasets/configuration/group_attributes/storages/group_attributes.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
version: v1 | ||
kind: writable_storage | ||
name: group_attributes | ||
|
||
storage: | ||
key: group_attributes | ||
set_key: group_attributes | ||
|
||
readiness_state: limited | ||
|
||
schema: | ||
columns: | ||
[ | ||
{ name: project_id, type: UInt, args: { size: 64 } }, | ||
{ name: group_id, type: UInt, args: { size: 64 } }, | ||
|
||
{ name: group_status, type: UInt, args: { size: 8 } }, | ||
{ name: group_substatus, type: UInt, args: { size: 8, schema_modifiers: [ nullable ] } }, | ||
{ name: group_first_seen, type: DateTime }, | ||
{ name: group_num_comments, type: UInt, args: { size: 64 } }, | ||
|
||
{ name: assignee_user_id, type: UInt, args: { size: 64, schema_modifiers: [ nullable ] } }, | ||
{ name: assignee_team_id, type: UInt, args: { size: 64, schema_modifiers: [ nullable ] } }, | ||
|
||
{ name: owner_suspect_commit_user_id, type: UInt, args: { size: 64, schema_modifiers: [ nullable ] } }, | ||
{ name: owner_ownership_rule_user_id, type: UInt, args: { size: 64, schema_modifiers: [ nullable ] } }, | ||
{ name: owner_ownership_rule_team_id, type: UInt, args: { size: 64, schema_modifiers: [ nullable ] } }, | ||
{ name: owner_codeowners_user_id, type: UInt, args: { size: 64, schema_modifiers: [ nullable ] } }, | ||
{ name: owner_codeowners_team_id, type: UInt, args: { size: 64, schema_modifiers: [ nullable ] } }, | ||
|
||
{ name: deleted, type: UInt, args: { size: 8 } }, | ||
{ name: message_timestamp, type: DateTime }, | ||
{ name: partition, type: UInt, args: { size: 16 } }, | ||
{ name: offset, type: UInt, args: { size: 64 } }, | ||
] | ||
local_table_name: group_attributes_local | ||
dist_table_name: group_attributes_dist | ||
|
||
allocation_policies: | ||
- name: PassthroughPolicy | ||
args: | ||
required_tenant_types: | ||
- blank | ||
|
||
query_processors: | ||
- processor: TableRateLimit | ||
|
||
mandatory_condition_checkers: | ||
- condition: ProjectIdEnforcer | ||
|
||
stream_loader: | ||
processor: | ||
name: GroupAttributesMessageProcessor | ||
default_topic: group-attributes | ||
dlq_topic: snuba-dead-letter-group-attributes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from datetime import datetime | ||
from typing import Optional | ||
|
||
from sentry_kafka_schemas.schema_types.group_attributes_v1 import ( | ||
GroupAttributesSnapshot, | ||
) | ||
|
||
from snuba import environment, settings | ||
from snuba.consumers.types import KafkaMessageMetadata | ||
from snuba.datasets.processors import DatasetMessageProcessor | ||
from snuba.processor import InsertBatch, ProcessedMessage | ||
from snuba.utils.metrics.wrapper import MetricsWrapper | ||
|
||
metrics = MetricsWrapper(environment.metrics, "group_attributes.processor") | ||
|
||
|
||
class GroupAttributesMessageProcessor(DatasetMessageProcessor): | ||
def process_message( | ||
self, message: GroupAttributesSnapshot, metadata: KafkaMessageMetadata | ||
) -> Optional[ProcessedMessage]: | ||
return InsertBatch( | ||
[ | ||
{ | ||
"project_id": message["project_id"], | ||
"group_id": message["group_id"], | ||
"group_status": message["status"], | ||
"group_substatus": message["substatus"], | ||
"group_first_seen": datetime.strptime( | ||
message["first_seen"], settings.PAYLOAD_DATETIME_FORMAT | ||
), | ||
"group_num_comments": message["num_comments"], | ||
"assignee_user_id": message["assignee_user_id"], | ||
"assignee_team_id": message["assignee_team_id"], | ||
"owner_suspect_commit_user_id": message[ | ||
"owner_suspect_commit_user_id" | ||
], | ||
"owner_ownership_rule_user_id": message[ | ||
"owner_ownership_rule_user_id" | ||
], | ||
"owner_ownership_rule_team_id": message[ | ||
"owner_ownership_rule_team_id" | ||
], | ||
"owner_codeowners_user_id": message["owner_codeowners_user_id"], | ||
"owner_codeowners_team_id": message["owner_codeowners_team_id"], | ||
"deleted": 1 if message["group_deleted"] else 0, | ||
"message_timestamp": metadata.timestamp, | ||
"partition": metadata.partition, | ||
"offset": metadata.offset, | ||
} | ||
], | ||
None, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
|
||
def test_dlq() -> None: | ||
assert len(get_dlq_topics()) == 7 | ||
assert len(get_dlq_topics()) == 8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from datetime import datetime | ||
from typing import Optional | ||
|
||
import pytest | ||
from sentry_kafka_schemas.schema_types.group_attributes_v1 import ( | ||
GroupAttributesSnapshot, | ||
) | ||
|
||
from snuba import settings | ||
from snuba.consumers.types import KafkaMessageMetadata | ||
from snuba.datasets.processors.group_attributes_processor import ( | ||
GroupAttributesMessageProcessor, | ||
) | ||
from snuba.processor import ProcessedMessage | ||
from snuba.writer import WriterTableRow | ||
|
||
|
||
@pytest.fixture | ||
def group_created() -> GroupAttributesSnapshot: | ||
return { | ||
"group_deleted": False, | ||
"project_id": 1, | ||
"group_id": 1, | ||
"status": 0, | ||
"substatus": 7, | ||
"first_seen": "2023-02-27T15:40:12.223000Z", | ||
"num_comments": 0, | ||
"assignee_user_id": None, | ||
"assignee_team_id": None, | ||
"owner_suspect_commit_user_id": None, | ||
"owner_ownership_rule_user_id": None, | ||
"owner_ownership_rule_team_id": None, | ||
"owner_codeowners_user_id": None, | ||
"owner_codeowners_team_id": None, | ||
"timestamp": "2023-02-27T15:40:12.223000Z", | ||
} | ||
|
||
|
||
class TestGroupAttributesMessageProcessor: | ||
KAFKA_META = KafkaMessageMetadata( | ||
offset=0, partition=0, timestamp=datetime(1970, 1, 1) | ||
) | ||
|
||
processor = GroupAttributesMessageProcessor() | ||
|
||
def process_message( | ||
self, message, kafka_meta: KafkaMessageMetadata = KAFKA_META | ||
) -> Optional[ProcessedMessage]: | ||
return self.processor.process_message(message, kafka_meta) | ||
|
||
def processed_single_row(self, message) -> WriterTableRow: | ||
return self.process_message(message).rows[0] | ||
|
||
def test_group_created(self, group_created): | ||
assert ( | ||
self.processed_single_row(group_created).items() | ||
>= { | ||
"project_id": 1, | ||
"group_id": 1, | ||
"group_status": 0, | ||
"group_substatus": 7, | ||
"group_first_seen": datetime.strptime( | ||
group_created["first_seen"], settings.PAYLOAD_DATETIME_FORMAT | ||
), | ||
"group_num_comments": 0, | ||
"assignee_user_id": None, | ||
"assignee_team_id": None, | ||
"owner_suspect_commit_user_id": None, | ||
"owner_ownership_rule_user_id": None, | ||
"owner_ownership_rule_team_id": None, | ||
"owner_codeowners_user_id": None, | ||
"owner_codeowners_team_id": None, | ||
"deleted": 0, | ||
}.items() | ||
) |
Oops, something went wrong.