sediment-api 0.7.0__tar.gz → 0.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sediment_api-0.7.0 → sediment_api-0.8.0}/PKG-INFO +6 -6
- {sediment_api-0.7.0 → sediment_api-0.8.0}/pyproject.toml +6 -6
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/__init__.py +1 -1
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/deps.py +1 -2
- sediment_api-0.8.0/sediment_api/ingest_envelopes.py +55 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/reports/compute_report.py +23 -3
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/routers/ci_vendor.py +3 -4
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/routers/compute.py +3 -4
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/routers/forge.py +65 -26
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/routers/gateway.py +4 -3
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/routers/otlp.py +9 -4
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/routers/v1.py +7 -34
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_compute_report_cli.py +74 -1
- sediment_api-0.8.0/tests/test_ingest_envelopes.py +139 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_push_mirror.py +167 -4
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_v1.py +1 -1
- {sediment_api-0.7.0 → sediment_api-0.8.0}/.gitignore +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/LICENSE +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/config.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/database.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/main.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/mirror_gc.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/reports/__init__.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/reports/abandonment_report.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/reports/attribution_share_report.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/reports/dataset_diagnostics.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/reports/label_confidence_inspection.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/reports/lifecycle_report.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/reports/merge_retention_report.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/reports/model_report.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/reports/precision_report.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/reports/recovery_yield_report.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/routers/__init__.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/routers/query.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/routers/reports.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/services/__init__.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/services/operational_reports.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/worker.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/sediment_api/workers.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/conftest.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_attribution_share_report.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_baseline_gap_repro.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_bug_repro_offset.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_capture_record_isolation.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_ci_vendor.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_compute_ingest.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_config.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_context_discovery_authority.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_context_discovery_query.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_context_discovery_workers.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_context_evidence_query.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_context_query.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_credential_authorities.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_database_lifecycle.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_database_outage.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_database_role_startup.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_dataset_diagnostics_report.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_e2e_smoke.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_evidence_query.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_evidence_worker_imports.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_evidence_workers.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_gateway_capture_receipt.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_gateway_identity.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_lifecycle_report_cli.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_merge_retention_cli.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_one_shot_database.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_operational_reports.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_operational_reports_service.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_postgres_gateway_tracer.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_query.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_report_attachment_scope.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_report_routes.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_repository_identity_ingest.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_repository_identity_model_service.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_repository_identity_queries.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_retrieval_authority.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_worker_processes.py +0 -0
- {sediment_api-0.7.0 → sediment_api-0.8.0}/tests/test_worker_routes.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: sediment-api
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
4
4
|
Summary: Sediment ingest API: facts in through three doors
|
|
5
5
|
Project-URL: Source, https://github.com/sediment-ai/sediment
|
|
6
6
|
Project-URL: Documentation, https://github.com/sediment-ai/sediment/tree/main/docs
|
|
@@ -9,12 +9,12 @@ Project-URL: Changelog, https://github.com/sediment-ai/sediment/blob/main/CHANGE
|
|
|
9
9
|
License-Expression: AGPL-3.0-or-later
|
|
10
10
|
License-File: LICENSE
|
|
11
11
|
Requires-Python: >=3.12
|
|
12
|
-
Requires-Dist: anyio>=4.
|
|
12
|
+
Requires-Dist: anyio>=4.16.0
|
|
13
13
|
Requires-Dist: fastapi>=0.142.2
|
|
14
14
|
Requires-Dist: httpx>=0.27
|
|
15
15
|
Requires-Dist: pydantic-settings>=2.16.2
|
|
16
|
-
Requires-Dist: sediment-capture==0.
|
|
17
|
-
Requires-Dist: sediment-core==0.
|
|
18
|
-
Requires-Dist: sediment-derive==0.
|
|
19
|
-
Requires-Dist: sediment-export==0.
|
|
16
|
+
Requires-Dist: sediment-capture==0.8.0
|
|
17
|
+
Requires-Dist: sediment-core==0.8.0
|
|
18
|
+
Requires-Dist: sediment-derive==0.8.0
|
|
19
|
+
Requires-Dist: sediment-export==0.8.0
|
|
20
20
|
Requires-Dist: uvicorn>=0.54.0
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "sediment-api"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.8.0"
|
|
4
4
|
description = "Sediment ingest API: facts in through three doors"
|
|
5
5
|
requires-python = ">=3.12"
|
|
6
6
|
license = "AGPL-3.0-or-later"
|
|
7
7
|
license-files = ["LICENSE"]
|
|
8
8
|
dependencies = [
|
|
9
9
|
# Security floor for HTTPX/Starlette, including installations from wheels.
|
|
10
|
-
"anyio>=4.
|
|
10
|
+
"anyio>=4.16.0",
|
|
11
11
|
"fastapi>=0.142.2",
|
|
12
12
|
"httpx>=0.27",
|
|
13
13
|
"uvicorn>=0.54.0",
|
|
14
14
|
"pydantic-settings>=2.16.2",
|
|
15
|
-
"sediment-core==0.
|
|
16
|
-
"sediment-capture==0.
|
|
17
|
-
"sediment-derive==0.
|
|
18
|
-
"sediment-export==0.
|
|
15
|
+
"sediment-core==0.8.0",
|
|
16
|
+
"sediment-capture==0.8.0",
|
|
17
|
+
"sediment-derive==0.8.0",
|
|
18
|
+
"sediment-export==0.8.0",
|
|
19
19
|
]
|
|
20
20
|
|
|
21
21
|
[project.urls]
|
|
@@ -14,8 +14,7 @@ from __future__ import annotations
|
|
|
14
14
|
import json
|
|
15
15
|
import secrets
|
|
16
16
|
from dataclasses import dataclass
|
|
17
|
-
from typing import Literal
|
|
18
|
-
from typing import Any
|
|
17
|
+
from typing import Any, Literal
|
|
19
18
|
|
|
20
19
|
from fastapi import Depends, Header, HTTPException, Request
|
|
21
20
|
from sediment_capture import verify_signature
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
"""Typed response envelopes for the ingest doors (AGENTS.md §API Conventions).
|
|
3
|
+
|
|
4
|
+
Routers return these instead of bare dicts so the generated OpenAPI names
|
|
5
|
+
each outcome. The wire bodies stay exactly the documented shapes.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
from typing import Annotated, Literal
|
|
12
|
+
|
|
13
|
+
from pydantic import ConfigDict, Field
|
|
14
|
+
|
|
15
|
+
_CLOSED = ConfigDict(extra="forbid")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass(frozen=True)
|
|
19
|
+
class IngestReceipt:
|
|
20
|
+
"""The retained Fact for one single-Fact ingest request."""
|
|
21
|
+
|
|
22
|
+
__pydantic_config__ = _CLOSED
|
|
23
|
+
|
|
24
|
+
fact_id: Annotated[
|
|
25
|
+
str,
|
|
26
|
+
Field(description="ID of the retained Fact, including on redelivery"),
|
|
27
|
+
]
|
|
28
|
+
stored: Annotated[
|
|
29
|
+
bool,
|
|
30
|
+
Field(
|
|
31
|
+
description=(
|
|
32
|
+
"False when a redelivery collapsed on a UNIQUE index (ADR "
|
|
33
|
+
"0003); success, not an error"
|
|
34
|
+
)
|
|
35
|
+
),
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass(frozen=True)
|
|
40
|
+
class IngestSkipped:
|
|
41
|
+
"""A declined delivery that the sender shouldn't retry."""
|
|
42
|
+
|
|
43
|
+
__pydantic_config__ = _CLOSED
|
|
44
|
+
|
|
45
|
+
skipped: Literal[True]
|
|
46
|
+
reason: Annotated[
|
|
47
|
+
str, Field(description="Why the route stored nothing for this delivery")
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass(frozen=True)
|
|
52
|
+
class OTLPExportLogsResponse:
|
|
53
|
+
"""The empty OTLP/HTTP JSON ExportLogsServiceResponse: full success."""
|
|
54
|
+
|
|
55
|
+
__pydantic_config__ = _CLOSED
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"""Compute report: Session completion time by final Compute allocation.
|
|
3
3
|
|
|
4
4
|
sediment report compute --org acme-corp
|
|
5
|
+
sediment report compute --org acme-corp --since-days 30
|
|
5
6
|
sediment report compute --org acme-corp --json
|
|
6
7
|
sediment report compute --org acme-corp --rows-out sessions.jsonl
|
|
7
8
|
"""
|
|
@@ -12,12 +13,14 @@ import argparse
|
|
|
12
13
|
import json
|
|
13
14
|
import os
|
|
14
15
|
import sys
|
|
16
|
+
from datetime import UTC, datetime
|
|
15
17
|
|
|
16
18
|
from sediment_core import normalize_org_id
|
|
17
19
|
from sediment_derive import ComputeArm
|
|
18
20
|
from sediment_export import (
|
|
19
21
|
ComputeReport,
|
|
20
22
|
DurationDistribution,
|
|
23
|
+
OperationalReportScope,
|
|
21
24
|
compute_report_to_json,
|
|
22
25
|
compute_timings_to_export_rows,
|
|
23
26
|
generate_compute_report_result,
|
|
@@ -60,7 +63,9 @@ def _difference(name: str, difference: MedianDifference) -> str:
|
|
|
60
63
|
)
|
|
61
64
|
|
|
62
65
|
|
|
63
|
-
def _print_table(report: ComputeReport) -> None:
|
|
66
|
+
def _print_table(report: ComputeReport, *, org_id: str, since_days: int | None) -> None:
|
|
67
|
+
window = f"last {since_days} day(s)" if since_days else "all history"
|
|
68
|
+
print(f"org: {org_id} window: {window}")
|
|
64
69
|
print(f"Sessions with a Compute allocation: {report.sessions_with_allocation}")
|
|
65
70
|
print(f"timed Sessions: {report.timed_sessions}")
|
|
66
71
|
skipped = ", ".join(f"{key}={value}" for key, value in report.skipped.items())
|
|
@@ -103,6 +108,13 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
103
108
|
required=not os.environ.get("SEDIMENT_ORG_ID"),
|
|
104
109
|
help="org id (default: $SEDIMENT_ORG_ID)",
|
|
105
110
|
)
|
|
111
|
+
parser.add_argument(
|
|
112
|
+
"--since-days",
|
|
113
|
+
type=int,
|
|
114
|
+
default=None,
|
|
115
|
+
help="window Compute allocations (and their Session timings) to the last N days by "
|
|
116
|
+
"capture time; default: all history",
|
|
117
|
+
)
|
|
106
118
|
parser.add_argument(
|
|
107
119
|
"--json", action="store_true", help="emit JSON instead of a text report"
|
|
108
120
|
)
|
|
@@ -117,19 +129,27 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
117
129
|
|
|
118
130
|
def main(argv: list[str] | None = None) -> int:
|
|
119
131
|
args = build_parser().parse_args(argv)
|
|
132
|
+
if args.since_days is not None and args.since_days <= 0:
|
|
133
|
+
print("error: --since-days must be a positive integer", file=sys.stderr)
|
|
134
|
+
return 2
|
|
120
135
|
try:
|
|
121
136
|
org_id = normalize_org_id(args.org)
|
|
122
137
|
except ValueError as exc:
|
|
123
138
|
print(f"error: {exc}", file=sys.stderr)
|
|
124
139
|
return 2
|
|
140
|
+
scope = (
|
|
141
|
+
OperationalReportScope.trailing_days(args.since_days, as_of=datetime.now(UTC))
|
|
142
|
+
if args.since_days is not None
|
|
143
|
+
else None
|
|
144
|
+
)
|
|
125
145
|
with one_shot_fact_store(
|
|
126
146
|
args.database_url, operation="generate compute report"
|
|
127
147
|
) as store:
|
|
128
|
-
result = generate_compute_report_result(store, org_id)
|
|
148
|
+
result = generate_compute_report_result(store, org_id, scope=scope)
|
|
129
149
|
if args.json:
|
|
130
150
|
print(json.dumps(compute_report_to_json(result.report), indent=2))
|
|
131
151
|
else:
|
|
132
|
-
_print_table(result.report)
|
|
152
|
+
_print_table(result.report, org_id=org_id, since_days=args.since_days)
|
|
133
153
|
if args.rows_out:
|
|
134
154
|
try:
|
|
135
155
|
write_result = write_jsonl(
|
|
@@ -16,8 +16,6 @@ collapses redeliveries; ``stored: false`` means success, not an error.
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
from typing import Any
|
|
20
|
-
|
|
21
19
|
from fastapi import APIRouter, Depends
|
|
22
20
|
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
|
23
21
|
from sediment_core import (
|
|
@@ -40,6 +38,7 @@ from sediment_core import (
|
|
|
40
38
|
|
|
41
39
|
from ..config import settings
|
|
42
40
|
from ..deps import get_store, verify_ingest_token
|
|
41
|
+
from ..ingest_envelopes import IngestReceipt
|
|
43
42
|
|
|
44
43
|
router = APIRouter(tags=["ci-vendor"])
|
|
45
44
|
|
|
@@ -121,7 +120,7 @@ def ingest_ci_vendor(
|
|
|
121
120
|
body: VendorCIRequest,
|
|
122
121
|
_: None = Depends(verify_ingest_token),
|
|
123
122
|
store: FactStore = Depends(get_store),
|
|
124
|
-
) ->
|
|
123
|
+
) -> IngestReceipt:
|
|
125
124
|
outcome = CIOutcome(
|
|
126
125
|
org_id=settings.org_id,
|
|
127
126
|
provider=body.provider,
|
|
@@ -146,4 +145,4 @@ def ingest_ci_vendor(
|
|
|
146
145
|
source_event_id=body.source_event_id,
|
|
147
146
|
)
|
|
148
147
|
receipt = store.store_ci_outcome_receipt(outcome)
|
|
149
|
-
return
|
|
148
|
+
return IngestReceipt(fact_id=receipt.fact_id, stored=receipt.stored)
|
|
@@ -17,8 +17,6 @@ not an error.
|
|
|
17
17
|
|
|
18
18
|
from __future__ import annotations
|
|
19
19
|
|
|
20
|
-
from typing import Any
|
|
21
|
-
|
|
22
20
|
from fastapi import APIRouter, Depends
|
|
23
21
|
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
|
24
22
|
from sediment_core import (
|
|
@@ -31,6 +29,7 @@ from sediment_core import (
|
|
|
31
29
|
|
|
32
30
|
from ..config import settings
|
|
33
31
|
from ..deps import get_store, verify_ingest_token
|
|
32
|
+
from ..ingest_envelopes import IngestReceipt
|
|
34
33
|
|
|
35
34
|
router = APIRouter(tags=["compute"])
|
|
36
35
|
|
|
@@ -89,7 +88,7 @@ def ingest_compute_allocation(
|
|
|
89
88
|
body: ComputeAllocationRequest,
|
|
90
89
|
_: None = Depends(verify_ingest_token),
|
|
91
90
|
store: FactStore = Depends(get_store),
|
|
92
|
-
) ->
|
|
91
|
+
) -> IngestReceipt:
|
|
93
92
|
allocation = ComputeAllocation(
|
|
94
93
|
org_id=settings.org_id,
|
|
95
94
|
session_id=body.session_id,
|
|
@@ -99,4 +98,4 @@ def ingest_compute_allocation(
|
|
|
99
98
|
occurred_at=body.occurred_at,
|
|
100
99
|
)
|
|
101
100
|
receipt = store.store_compute_allocation_receipt(allocation)
|
|
102
|
-
return
|
|
101
|
+
return IngestReceipt(fact_id=receipt.fact_id, stored=receipt.stored)
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"""
|
|
3
3
|
GitHub webhook ingest routes, mounted under /ingest/github in main.py.
|
|
4
4
|
|
|
5
|
-
One module for
|
|
6
|
-
which parser/store pair the payload walks through. The signature is
|
|
5
|
+
One module for all four routes: they share the HMAC intake and differ only
|
|
6
|
+
in which parser/store pair the payload walks through. The signature is
|
|
7
7
|
verified BEFORE the event type is examined: a wrong-secret delivery must
|
|
8
8
|
401 even for event types a route skips, or GitHub's setup ping would
|
|
9
9
|
green-light a misconfigured webhook. The push route stores the Push fact,
|
|
@@ -19,7 +19,6 @@ from __future__ import annotations
|
|
|
19
19
|
import logging
|
|
20
20
|
from collections import Counter
|
|
21
21
|
from datetime import UTC, datetime
|
|
22
|
-
from typing import Any
|
|
23
22
|
|
|
24
23
|
from fastapi import APIRouter, BackgroundTasks, Depends, Header, Request
|
|
25
24
|
from sediment_capture import (
|
|
@@ -53,6 +52,7 @@ from starlette.concurrency import run_in_threadpool
|
|
|
53
52
|
|
|
54
53
|
from ..config import settings
|
|
55
54
|
from ..deps import get_store, read_verified_webhook
|
|
55
|
+
from ..ingest_envelopes import IngestReceipt, IngestSkipped
|
|
56
56
|
|
|
57
57
|
logger = logging.getLogger("sediment.api.forge")
|
|
58
58
|
router = APIRouter(tags=["forge"])
|
|
@@ -202,12 +202,12 @@ def _capture_session_commit_observations(
|
|
|
202
202
|
return observations
|
|
203
203
|
|
|
204
204
|
|
|
205
|
-
def
|
|
205
|
+
def _store_session_commit_observations_per_edge(
|
|
206
206
|
push: Push,
|
|
207
207
|
observations: list[SessionCommitObservation],
|
|
208
208
|
store: FactStore,
|
|
209
|
-
) ->
|
|
210
|
-
"""
|
|
209
|
+
) -> tuple[int, int]:
|
|
210
|
+
"""Store edges one at a time after a batch failure; stop on DB outage."""
|
|
211
211
|
stored_count = 0
|
|
212
212
|
duplicate_count = 0
|
|
213
213
|
for observation in observations:
|
|
@@ -218,7 +218,7 @@ def _store_session_commit_observations(
|
|
|
218
218
|
"session_commit_observation_database_unavailable repo=%s",
|
|
219
219
|
push.repo,
|
|
220
220
|
)
|
|
221
|
-
return
|
|
221
|
+
return stored_count, duplicate_count
|
|
222
222
|
except Exception:
|
|
223
223
|
logger.exception(
|
|
224
224
|
"session_commit_observation_error repo=%s commit_sha=%s",
|
|
@@ -228,6 +228,46 @@ def _store_session_commit_observations(
|
|
|
228
228
|
continue
|
|
229
229
|
stored_count += int(stored)
|
|
230
230
|
duplicate_count += int(not stored)
|
|
231
|
+
return stored_count, duplicate_count
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def _store_session_commit_observations(
|
|
235
|
+
push: Push,
|
|
236
|
+
observations: list[SessionCommitObservation],
|
|
237
|
+
store: FactStore,
|
|
238
|
+
) -> None:
|
|
239
|
+
"""Persist collected observations after releasing the mirror lock."""
|
|
240
|
+
stored_count = 0
|
|
241
|
+
duplicate_count = 0
|
|
242
|
+
try:
|
|
243
|
+
stored_flags = store.store_session_commit_observations(observations)
|
|
244
|
+
except SQLAlchemyError:
|
|
245
|
+
# SQLAlchemy exception text can contain statements, parameters, and
|
|
246
|
+
# driver diagnostics. Fall back per edge without putting any of that
|
|
247
|
+
# secret-bearing context in the log (same posture as
|
|
248
|
+
# `_derive_push_attributions`).
|
|
249
|
+
logger.error(
|
|
250
|
+
"session_commit_observation_batch_database_unavailable "
|
|
251
|
+
"repo=%s; falling back per edge",
|
|
252
|
+
push.repo,
|
|
253
|
+
)
|
|
254
|
+
stored_count, duplicate_count = _store_session_commit_observations_per_edge(
|
|
255
|
+
push, observations, store
|
|
256
|
+
)
|
|
257
|
+
except Exception:
|
|
258
|
+
# Batch insert is one transaction. A contradictory edge rolls the
|
|
259
|
+
# whole delivery back; fall back per edge so a committed prefix
|
|
260
|
+
# still survives (same fail-soft as the pre-batch loop).
|
|
261
|
+
logger.exception(
|
|
262
|
+
"session_commit_observation_batch_error repo=%s; falling back per edge",
|
|
263
|
+
push.repo,
|
|
264
|
+
)
|
|
265
|
+
stored_count, duplicate_count = _store_session_commit_observations_per_edge(
|
|
266
|
+
push, observations, store
|
|
267
|
+
)
|
|
268
|
+
else:
|
|
269
|
+
stored_count = sum(stored_flags)
|
|
270
|
+
duplicate_count = len(stored_flags) - stored_count
|
|
231
271
|
logger.info(
|
|
232
272
|
"session_commit_observations_captured repo=%s stored=%d duplicates=%d",
|
|
233
273
|
push.repo,
|
|
@@ -295,15 +335,15 @@ async def ingest_push(
|
|
|
295
335
|
x_hub_signature_256: str | None = Header(None),
|
|
296
336
|
x_github_event: str = Header(...),
|
|
297
337
|
store: FactStore = Depends(get_store),
|
|
298
|
-
) ->
|
|
338
|
+
) -> IngestReceipt | IngestSkipped:
|
|
299
339
|
payload = await read_verified_webhook(request, x_hub_signature_256)
|
|
300
340
|
# GitHub delivers every subscribed event (incl. ping) to the one URL;
|
|
301
341
|
# the X-GitHub-Event header is the discriminator.
|
|
302
342
|
if x_github_event != "push":
|
|
303
|
-
return
|
|
343
|
+
return IngestSkipped(skipped=True, reason="not a push event")
|
|
304
344
|
push = parse_push(payload, org_id=settings.org_id, github_host=settings.github_host)
|
|
305
345
|
if push is None:
|
|
306
|
-
return
|
|
346
|
+
return IngestSkipped(skipped=True, reason="not a storable push")
|
|
307
347
|
receipt = await run_in_threadpool(store.store_push_receipt, push)
|
|
308
348
|
fetch_repo, fetch_clone_url = push.repo, push.clone_url
|
|
309
349
|
push = receipt.fact
|
|
@@ -325,12 +365,11 @@ async def ingest_push(
|
|
|
325
365
|
push, fetch_repo=fetch_repo, fetch_clone_url=fetch_clone_url
|
|
326
366
|
)
|
|
327
367
|
background.add_task(request.app.state.workers.wait_background, task)
|
|
328
|
-
return
|
|
368
|
+
return IngestReceipt(fact_id=push.push_id, stored=stored)
|
|
329
369
|
|
|
330
370
|
|
|
331
371
|
@router.post(
|
|
332
372
|
"/repository",
|
|
333
|
-
response_model=dict[str, Any],
|
|
334
373
|
responses={
|
|
335
374
|
503: {
|
|
336
375
|
"description": "Mirror work capacity, storage, or execution budget exceeded."
|
|
@@ -343,11 +382,11 @@ async def ingest_repository(
|
|
|
343
382
|
x_github_event: str = Header(...),
|
|
344
383
|
x_github_delivery: str | None = Header(None),
|
|
345
384
|
store: FactStore = Depends(get_store),
|
|
346
|
-
) ->
|
|
385
|
+
) -> IngestReceipt | IngestSkipped:
|
|
347
386
|
"""Store an immutable rename receipt independently of mirror availability."""
|
|
348
387
|
payload = await read_verified_webhook(request, x_hub_signature_256)
|
|
349
388
|
if x_github_event != "repository":
|
|
350
|
-
return
|
|
389
|
+
return IngestSkipped(skipped=True, reason="not a repository event")
|
|
351
390
|
rename, reason = parse_repository_rename(
|
|
352
391
|
payload,
|
|
353
392
|
org_id=settings.org_id,
|
|
@@ -356,12 +395,12 @@ async def ingest_repository(
|
|
|
356
395
|
)
|
|
357
396
|
if rename is None:
|
|
358
397
|
assert reason is not None
|
|
359
|
-
return
|
|
398
|
+
return IngestSkipped(skipped=True, reason=reason.value)
|
|
360
399
|
receipt = await run_in_threadpool(store.store_repository_rename_receipt, rename)
|
|
361
400
|
logger.info(
|
|
362
401
|
"repository_rename_stored fact_id=%s stored=%s", receipt.fact_id, receipt.stored
|
|
363
402
|
)
|
|
364
|
-
return
|
|
403
|
+
return IngestReceipt(fact_id=receipt.fact_id, stored=receipt.stored)
|
|
365
404
|
|
|
366
405
|
|
|
367
406
|
@router.post("/ci")
|
|
@@ -371,10 +410,10 @@ async def ingest_ci(
|
|
|
371
410
|
x_github_event: str = Header(...),
|
|
372
411
|
x_github_delivery: str | None = Header(None),
|
|
373
412
|
store: FactStore = Depends(get_store),
|
|
374
|
-
) ->
|
|
413
|
+
) -> IngestReceipt | IngestSkipped:
|
|
375
414
|
payload = await read_verified_webhook(request, x_hub_signature_256)
|
|
376
415
|
if x_github_event != "workflow_run":
|
|
377
|
-
return
|
|
416
|
+
return IngestSkipped(skipped=True, reason="not a workflow_run event")
|
|
378
417
|
outcome = parse_workflow_run(
|
|
379
418
|
payload,
|
|
380
419
|
org_id=settings.org_id,
|
|
@@ -382,7 +421,7 @@ async def ingest_ci(
|
|
|
382
421
|
github_host=settings.github_host,
|
|
383
422
|
)
|
|
384
423
|
if outcome is None:
|
|
385
|
-
return
|
|
424
|
+
return IngestSkipped(skipped=True, reason="not a completed workflow_run")
|
|
386
425
|
receipt = await run_in_threadpool(store.store_ci_outcome_receipt, outcome)
|
|
387
426
|
outcome = receipt.fact
|
|
388
427
|
stored = receipt.stored
|
|
@@ -393,7 +432,7 @@ async def ingest_ci(
|
|
|
393
432
|
outcome.repo,
|
|
394
433
|
outcome.result,
|
|
395
434
|
)
|
|
396
|
-
return
|
|
435
|
+
return IngestReceipt(fact_id=outcome.outcome_id, stored=stored)
|
|
397
436
|
|
|
398
437
|
|
|
399
438
|
@router.post("/pull-request")
|
|
@@ -403,10 +442,10 @@ async def ingest_pull_request(
|
|
|
403
442
|
x_github_event: str = Header(...),
|
|
404
443
|
x_github_delivery: str | None = Header(None),
|
|
405
444
|
store: FactStore = Depends(get_store),
|
|
406
|
-
) ->
|
|
445
|
+
) -> IngestReceipt | IngestSkipped:
|
|
407
446
|
payload = await read_verified_webhook(request, x_hub_signature_256)
|
|
408
447
|
if x_github_event != "pull_request":
|
|
409
|
-
return
|
|
448
|
+
return IngestSkipped(skipped=True, reason="not a pull_request event")
|
|
410
449
|
if payload.get("action") == "closed":
|
|
411
450
|
merge = parse_pull_request_merge(
|
|
412
451
|
payload,
|
|
@@ -415,7 +454,7 @@ async def ingest_pull_request(
|
|
|
415
454
|
github_host=settings.github_host,
|
|
416
455
|
)
|
|
417
456
|
if merge is None:
|
|
418
|
-
return
|
|
457
|
+
return IngestSkipped(skipped=True, reason="not a merged pull_request")
|
|
419
458
|
receipt = await run_in_threadpool(store.store_pull_request_merge_receipt, merge)
|
|
420
459
|
merge = receipt.fact
|
|
421
460
|
stored = receipt.stored
|
|
@@ -426,7 +465,7 @@ async def ingest_pull_request(
|
|
|
426
465
|
merge.repo,
|
|
427
466
|
merge.pr_number,
|
|
428
467
|
)
|
|
429
|
-
return
|
|
468
|
+
return IngestReceipt(fact_id=merge.merge_id, stored=stored)
|
|
430
469
|
|
|
431
470
|
revision, skip_reason = parse_pull_request_revision(
|
|
432
471
|
payload,
|
|
@@ -436,7 +475,7 @@ async def ingest_pull_request(
|
|
|
436
475
|
)
|
|
437
476
|
if revision is None:
|
|
438
477
|
assert skip_reason is not None
|
|
439
|
-
return
|
|
478
|
+
return IngestSkipped(skipped=True, reason=skip_reason.value)
|
|
440
479
|
receipt = await run_in_threadpool(
|
|
441
480
|
store.store_pull_request_revision_receipt, revision
|
|
442
481
|
)
|
|
@@ -449,4 +488,4 @@ async def ingest_pull_request(
|
|
|
449
488
|
revision.repo,
|
|
450
489
|
revision.pr_number,
|
|
451
490
|
)
|
|
452
|
-
return
|
|
491
|
+
return IngestReceipt(fact_id=revision.revision_id, stored=stored)
|
|
@@ -20,6 +20,7 @@ from sediment_core.models import AwareDatetime
|
|
|
20
20
|
|
|
21
21
|
from ..config import settings
|
|
22
22
|
from ..deps import get_store, verify_ingest_token
|
|
23
|
+
from ..ingest_envelopes import IngestReceipt, IngestSkipped
|
|
23
24
|
|
|
24
25
|
logger = logging.getLogger("sediment.api.gateway")
|
|
25
26
|
router = APIRouter(tags=["gateway"])
|
|
@@ -57,7 +58,7 @@ def ingest_gateway(
|
|
|
57
58
|
body: GatewayIngestRequest,
|
|
58
59
|
_: None = Depends(verify_ingest_token),
|
|
59
60
|
store: FactStore = Depends(get_store),
|
|
60
|
-
) ->
|
|
61
|
+
) -> IngestReceipt | IngestSkipped:
|
|
61
62
|
adapter = ADAPTERS.get(body.provider)
|
|
62
63
|
if adapter is None:
|
|
63
64
|
raise HTTPException(
|
|
@@ -85,7 +86,7 @@ def ingest_gateway(
|
|
|
85
86
|
body.provider,
|
|
86
87
|
body.payload.get("litellm_call_id"),
|
|
87
88
|
)
|
|
88
|
-
return
|
|
89
|
+
return IngestSkipped(skipped=True, reason="no_session")
|
|
89
90
|
|
|
90
91
|
try:
|
|
91
92
|
inference_call = adapter.normalize(
|
|
@@ -134,4 +135,4 @@ def ingest_gateway(
|
|
|
134
135
|
receipt.fact_id,
|
|
135
136
|
receipt.stored,
|
|
136
137
|
)
|
|
137
|
-
return
|
|
138
|
+
return IngestReceipt(fact_id=receipt.fact_id, stored=receipt.stored)
|
|
@@ -12,7 +12,6 @@ from __future__ import annotations
|
|
|
12
12
|
|
|
13
13
|
import json
|
|
14
14
|
import logging
|
|
15
|
-
from typing import Any
|
|
16
15
|
|
|
17
16
|
from fastapi import APIRouter, Depends, HTTPException, Request
|
|
18
17
|
from sediment_capture import parse_otlp_logs
|
|
@@ -21,6 +20,7 @@ from starlette.concurrency import run_in_threadpool
|
|
|
21
20
|
|
|
22
21
|
from ..config import settings
|
|
23
22
|
from ..deps import get_store, verify_ingest_token
|
|
23
|
+
from ..ingest_envelopes import OTLPExportLogsResponse
|
|
24
24
|
|
|
25
25
|
logger = logging.getLogger("sediment.api.otlp")
|
|
26
26
|
router = APIRouter(tags=["otlp"])
|
|
@@ -31,7 +31,7 @@ async def ingest_otlp_logs(
|
|
|
31
31
|
request: Request,
|
|
32
32
|
_: None = Depends(verify_ingest_token),
|
|
33
33
|
store: FactStore = Depends(get_store),
|
|
34
|
-
) ->
|
|
34
|
+
) -> OTLPExportLogsResponse:
|
|
35
35
|
try:
|
|
36
36
|
payload = await request.json()
|
|
37
37
|
except HTTPException:
|
|
@@ -98,7 +98,7 @@ async def ingest_otlp_logs(
|
|
|
98
98
|
},
|
|
99
99
|
)
|
|
100
100
|
# Empty ExportLogsServiceResponse = full success (OTLP/HTTP JSON).
|
|
101
|
-
return
|
|
101
|
+
return OTLPExportLogsResponse()
|
|
102
102
|
|
|
103
103
|
|
|
104
104
|
def _store_translated_facts(
|
|
@@ -108,7 +108,12 @@ def _store_translated_facts(
|
|
|
108
108
|
rejected: list,
|
|
109
109
|
retry_linkages: list,
|
|
110
110
|
) -> tuple[int, int, int, int]:
|
|
111
|
-
"""Store one translated OTLP request outside the event loop.
|
|
111
|
+
"""Store one translated OTLP request outside the event loop.
|
|
112
|
+
|
|
113
|
+
Decisions stay one batched transaction. Edit observations, RejectedEdits,
|
|
114
|
+
and RetryLinkages each commit separately so a later storage failure can
|
|
115
|
+
leave a committed prefix that replay deduplicates.
|
|
116
|
+
"""
|
|
112
117
|
stored = sum(store.store_decisions(decisions))
|
|
113
118
|
observations_stored = sum(
|
|
114
119
|
store.store_edit_observation(observation) for observation in observations
|
|
@@ -21,7 +21,7 @@ from __future__ import annotations
|
|
|
21
21
|
from typing import Any
|
|
22
22
|
|
|
23
23
|
from fastapi import APIRouter, Depends, HTTPException
|
|
24
|
-
from sediment_core import FactStore,
|
|
24
|
+
from sediment_core import FactStore, NonEmptyId
|
|
25
25
|
|
|
26
26
|
from .. import __version__
|
|
27
27
|
from ..config import settings
|
|
@@ -29,15 +29,6 @@ from ..deps import CredentialIdentity, get_store, verify_operator_token, verify_
|
|
|
29
29
|
|
|
30
30
|
router = APIRouter(tags=["v1"])
|
|
31
31
|
|
|
32
|
-
_SESSION_FACT_TABLES = (
|
|
33
|
-
FactTable.INFERENCE_CALLS,
|
|
34
|
-
FactTable.DEVELOPER_DECISIONS,
|
|
35
|
-
FactTable.EDIT_OBSERVATIONS,
|
|
36
|
-
FactTable.REJECTED_EDITS,
|
|
37
|
-
FactTable.RETRY_LINKAGES,
|
|
38
|
-
FactTable.COMPUTE_ALLOCATIONS,
|
|
39
|
-
)
|
|
40
|
-
|
|
41
32
|
|
|
42
33
|
@router.get("/me")
|
|
43
34
|
def me(identity: CredentialIdentity = Depends(verify_token)) -> dict[str, Any]:
|
|
@@ -66,21 +57,9 @@ def facts(
|
|
|
66
57
|
("visible" = not quarantined) count. Sessions are upserted metadata,
|
|
67
58
|
not quarantinable facts, so they carry a bare count with no visible
|
|
68
59
|
column — the same shape ``sediment facts`` prints."""
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"total": store.count_facts(
|
|
73
|
-
settings.org_id, table, include_quarantined=True
|
|
74
|
-
),
|
|
75
|
-
"visible": store.count_facts(settings.org_id, table),
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
"sessions": store.count_sessions(settings.org_id),
|
|
79
|
-
"tables": tables,
|
|
80
|
-
# quarantine_revision is the org's provenance high-water mark (MAX
|
|
81
|
-
# quarantine-log rowid, 0 when none) — already an int from the store.
|
|
82
|
-
"quarantine_revision": store.quarantine_revision(settings.org_id),
|
|
83
|
-
}
|
|
60
|
+
# quarantine_revision is the org's provenance high-water mark (MAX
|
|
61
|
+
# quarantine-log rowid, 0 when none) — already an int from the store.
|
|
62
|
+
return store.count_fact_inventory(settings.org_id)
|
|
84
63
|
|
|
85
64
|
|
|
86
65
|
@router.get("/facts/session/{session_id}")
|
|
@@ -91,16 +70,10 @@ def session_facts(
|
|
|
91
70
|
) -> dict[str, Any]:
|
|
92
71
|
"""Fact counts for one session, so a client can verify its own writes
|
|
93
72
|
without treating unrelated organization-wide totals as evidence."""
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
settings.org_id, table, session_id, include_quarantined=True
|
|
98
|
-
),
|
|
99
|
-
"visible": store.count_session_facts(settings.org_id, table, session_id),
|
|
100
|
-
}
|
|
101
|
-
for table in _SESSION_FACT_TABLES
|
|
73
|
+
return {
|
|
74
|
+
"session_id": session_id,
|
|
75
|
+
"tables": store.count_session_fact_inventory(settings.org_id, session_id),
|
|
102
76
|
}
|
|
103
|
-
return {"session_id": session_id, "tables": tables}
|
|
104
77
|
|
|
105
78
|
|
|
106
79
|
@router.get("/facts/session/{session_id}/inference-calls")
|