Skip to content

Commit

Permalink
feat(uptime): Ability to ingest and query in_incident
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser committed Feb 14, 2025
1 parent 8a0159f commit e8d4d6e
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ python-dateutil==2.8.2
python-rapidjson==1.8
redis==4.5.4
sentry-arroyo==2.19.12
sentry-kafka-schemas==1.0.4
sentry-kafka-schemas==1.0.8
sentry-protos==0.1.59
sentry-redis-tools==0.3.0
sentry-relay==0.9.5
Expand Down
8 changes: 4 additions & 4 deletions rust_snuba/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust_snuba/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ procspawn = { version = "1.0.0", features = ["json"] }
pyo3 = { version = "0.18.1", features = ["chrono"] }
reqwest = { version = "0.11.11", features = ["stream"] }
sentry = { version = "0.32.0", features = ["anyhow", "tracing"] }
sentry-kafka-schemas = "1.0.4"
sentry-kafka-schemas = "1.0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
thiserror = "1.0"
Expand Down
7 changes: 7 additions & 0 deletions rust_snuba/src/processors/uptime_monitor_checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub fn deserialize_message(payload: &[u8]) -> anyhow::Result<(Vec<UptimeMonitorC
.http_status_code,
trace_id: monitor_message.trace_id,
retention_days: monitor_message.retention_days,
incident_status: monitor_message.incident_status,
}];
Ok((rows, monitor_message.actual_check_time_ms as f64))
}
Expand All @@ -63,6 +64,7 @@ struct UptimeMonitorCheckMessage<'a> {
status_reason: Option<CheckStatusReason<'a>>,
trace_id: Uuid,
request_info: Option<RequestInfo>,
incident_status: u16,
}
#[derive(Debug, Deserialize, Default)]
pub struct RequestInfo {
Expand Down Expand Up @@ -95,6 +97,7 @@ pub struct UptimeMonitorCheckRow<'a> {
http_status_code: Option<u16>,
trace_id: Uuid,
retention_days: u16,
incident_status: u16,
}

#[cfg(test)]
Expand All @@ -121,6 +124,7 @@ mod tests {
},
"http_status_code": 200,
"trace_id": "550e8400-e29b-41d4-a716-446655440000",
"incident_status": 0,
"request_info": {
"request_type": "GET",
"http_status_code": 200
Expand All @@ -145,6 +149,7 @@ mod tests {
assert_eq!(monitor_row.retention_days, 30);
assert_eq!(monitor_row.scheduled_check_time, 1702659277);
assert_eq!(monitor_row.timestamp, 1702659277000);
assert_eq!(monitor_row.incident_status, 0);
assert_eq!(timestamp, 1702659277000.0);
}

Expand All @@ -165,6 +170,7 @@ mod tests {
"status_reason": null,
"http_status_code": 200,
"trace_id": "550e8400-e29b-41d4-a716-446655440000",
"incident_status": 0,
"request_info": {
"request_type": "GET",
"http_status_code": 200
Expand All @@ -188,6 +194,7 @@ mod tests {
assert_eq!(monitor_row.check_status_reason, "");
assert_eq!(monitor_row.http_status_code, Some(200));
assert_eq!(monitor_row.retention_days, 30);
assert_eq!(monitor_row.incident_status, 0);
assert_eq!(timestamp, 1702659277.0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ schema:
{ name: http_status_code, type: UInt, args: { size: 16, schema_modifiers: [nullable] } },
{ name: trace_id, type: UUID },
{ name: retention_days, type: UInt, args: { size: 16 } },
{ name: incident_status, type: UInt, args: { size: 16 } },
]

storages:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ schema:
{ name: http_status_code, type: UInt, args: { size: 16, schema_modifiers: [nullable] } },
{ name: trace_id, type: UUID },
{ name: retention_days, type: UInt, args: { size: 16 } },
{ name: incident_status, type: UInt, args: { size: 16 } },
]
local_table_name: uptime_monitor_checks_v2_local
dist_table_name: uptime_monitor_checks_v2_dist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def transform(exp: Expression) -> Expression:
"check_status_reason": AttributeKey.Type.TYPE_STRING,
"http_status_code": AttributeKey.Type.TYPE_INT,
"trace_id": AttributeKey.Type.TYPE_STRING,
"incident_status": AttributeKey.Type.TYPE_INT,
"retention_days": AttributeKey.Type.TYPE_INT,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def gen_message(
},
"http_status_code": 200,
"trace_id": _TRACE_ID,
"incident_status": 0,
"request_info": {
"request_type": "GET",
"http_status_code": 200,
Expand All @@ -73,7 +74,8 @@ def store_timeseries(
dt = start_datetime + timedelta(seconds=secs)
messages.append(gen_message(dt))
uptime_checks_storage = get_storage(StorageKey("uptime_monitor_checks"))
write_raw_unprocessed_events(uptime_checks_storage, messages) # type: ignore
write_raw_unprocessed_events(
uptime_checks_storage, messages) # type: ignore


@pytest.mark.clickhouse_db
Expand Down Expand Up @@ -193,6 +195,7 @@ def test_with_group_by(self) -> None:
],
group_by=[
AttributeKey(type=AttributeKey.TYPE_STRING, name="region"),
AttributeKey(type=AttributeKey.TYPE_STRING, name="incident_status"),
],
granularity_secs=granularity_secs,
)
Expand All @@ -206,7 +209,7 @@ def test_with_group_by(self) -> None:
TimeSeries(
label="count",
buckets=expected_buckets,
group_by_attributes={"region": "global"},
group_by_attributes={"region": "global", "incident_status": 0},
data_points=[
DataPoint(data=300, data_present=True)
for _ in range(len(expected_buckets))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def gen_message(
},
"http_status_code": 200,
"trace_id": _TRACE_ID,
"incident_status": False,
"request_info": {
"request_type": "GET",
"http_status_code": 200,
Expand Down

0 comments on commit e8d4d6e

Please sign in to comment.