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
10 changes: 9 additions & 1 deletion src/splunk_ao/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def records(
experiment_id: str | None = None,
column_ids: list[str] | None = None,
redact: bool = True,
include_code_metric_metadata: bool = False,
) -> Iterator[dict[str, Any]]:
if filters is None:
filters = []
Expand All @@ -56,6 +57,7 @@ def records(
column_ids=column_ids,
sort=sort,
redact=redact,
include_code_metric_metadata=include_code_metric_metadata,
),
)

Expand All @@ -78,8 +80,9 @@ def export_records(
experiment_id: str | None = None,
column_ids: list[str] | None = None,
redact: bool = True,
include_code_metric_metadata: bool = False,
) -> Iterator[dict[str, Any]]:
"""Exports records from a Galileo project.
"""Exports records from a Splunk AO project.

Defaults to the first logstream if `log_stream_id` and `experiment_id` are not provided.

Expand All @@ -103,6 +106,10 @@ def export_records(
A sort clause to order the exported records.
redact
Redact sensitive data from the response.
include_code_metric_metadata
If True, include per-row scorer metadata (the dict returned alongside the score by
code-based scorers via the (score, metadata) tuple-return contract) on each
MetricSuccess in the export. Off by default to keep payloads small.

Returns
-------
Expand Down Expand Up @@ -132,4 +139,5 @@ def export_records(
column_ids=column_ids,
sort=sort,
redact=redact,
include_code_metric_metadata=include_code_metric_metadata,
)
11 changes: 11 additions & 0 deletions src/splunk_ao/resources/models/log_records_export_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class LogRecordsExportRequest:
'LogRecordsTextFilter']]]): Filters to apply on the export
sort (Union['LogRecordsSortClause', None, Unset]): Sort clause for the export. Defaults to native sort
(created_at, id descending).
include_code_metric_metadata (Union[Unset, bool]): If True, include per-row scorer metadata (the dict
returned alongside the score by code-based scorers via the (score, metadata) tuple-return contract) on
each MetricSuccess in the export. Default: False.
"""

root_type: RootType
Expand All @@ -69,6 +72,7 @@ class LogRecordsExportRequest:
]
) = UNSET
sort: Union["LogRecordsSortClause", None, Unset] = UNSET
include_code_metric_metadata: Unset | bool = False

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟠 major (bug): This field was manually added to a file generated by openapi-python-client, but the corresponding property is missing from the LogRecordsExportRequest schema in openapi.yaml. Running scripts/auto-generate-api-client.sh will regenerate this file and silently drop the field, after which the constructor calls in export.py (include_code_metric_metadata=...) will raise TypeError. Add the property to openapi.yaml so the codegen output includes it.

🤖 Generated by the Astra agent

additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

def to_dict(self) -> dict[str, Any]:
Expand Down Expand Up @@ -136,6 +140,8 @@ def to_dict(self) -> dict[str, Any]:
else:
sort = self.sort

include_code_metric_metadata = self.include_code_metric_metadata

field_dict: dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update({"root_type": root_type})
Expand All @@ -157,6 +163,8 @@ def to_dict(self) -> dict[str, Any]:
field_dict["filters"] = filters
if sort is not UNSET:
field_dict["sort"] = sort
if include_code_metric_metadata is not UNSET:
field_dict["include_code_metric_metadata"] = include_code_metric_metadata

return field_dict

Expand Down Expand Up @@ -313,6 +321,8 @@ def _parse_sort(data: object) -> Union["LogRecordsSortClause", None, Unset]:

sort = _parse_sort(d.pop("sort", UNSET))

include_code_metric_metadata = d.pop("include_code_metric_metadata", UNSET)

log_records_export_request = cls(
root_type=root_type,
column_ids=column_ids,
Expand All @@ -324,6 +334,7 @@ def _parse_sort(data: object) -> Union["LogRecordsSortClause", None, Unset]:
metrics_testing_id=metrics_testing_id,
filters=filters,
sort=sort,
include_code_metric_metadata=include_code_metric_metadata,
)

log_records_export_request.additional_properties = d
Expand Down
24 changes: 24 additions & 0 deletions tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,27 @@ def test_export_records_redact(mock_export_records_stream, redact_param):
mock_export_records_stream.assert_called_once()
request_body = mock_export_records_stream.call_args.kwargs["body"]
assert request_body.redact == redact_param


@patch("splunk_ao.export.export_records_stream")
def test_export_records_include_code_metric_metadata_default(mock_export_records_stream):
project_id = str(uuid4())
mock_export_records_stream.return_value = iter([])

list(export_records(project_id=project_id, log_stream_id=str(uuid4())))

request_body = mock_export_records_stream.call_args.kwargs["body"]
assert request_body.include_code_metric_metadata is False
assert request_body.to_dict()["include_code_metric_metadata"] is False


@patch("splunk_ao.export.export_records_stream")
def test_export_records_include_code_metric_metadata_opt_in(mock_export_records_stream):
project_id = str(uuid4())
mock_export_records_stream.return_value = iter([])

list(export_records(project_id=project_id, log_stream_id=str(uuid4()), include_code_metric_metadata=True))

request_body = mock_export_records_stream.call_args.kwargs["body"]
assert request_body.include_code_metric_metadata is True
assert request_body.to_dict()["include_code_metric_metadata"] is True
Loading