Skip to content

Commit

Permalink
Add excluded/included events to get_event_logs api (apache#37641)
Browse files Browse the repository at this point in the history
* Add excluded/included events to get_event_logs api

* Clean up tests

* fix tests
  • Loading branch information
bbovenzi authored Feb 23, 2024
1 parent 3568b09 commit 0b9e2a7
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
8 changes: 8 additions & 0 deletions airflow/api_connexion/endpoints/event_log_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def get_event_logs(
task_id: str | None = None,
owner: str | None = None,
event: str | None = None,
excluded_events: str | None = None,
included_events: str | None = None,
before: str | None = None,
after: str | None = None,
limit: int,
Expand Down Expand Up @@ -88,6 +90,12 @@ def get_event_logs(
query = query.where(Log.owner == owner)
if event:
query = query.where(Log.event == event)
if included_events:
included_events_list = included_events.split(",")
query = query.where(Log.event.in_(included_events_list))
if excluded_events:
excluded_events_list = excluded_events.split(",")
query = query.where(Log.event.notin_(excluded_events_list))
if before:
query = query.where(Log.dttm < timezone.parse(before))
if after:
Expand Down
16 changes: 16 additions & 0 deletions airflow/api_connexion/openapi/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,22 @@ paths:
- $ref: "#/components/parameters/Owner"
- $ref: "#/components/parameters/Before"
- $ref: "#/components/parameters/After"
- name: included_events
in: query
schema:
type: string
required: false
description: |
One or more event names separated by commas. If set, only return event logs with events matching this pattern.
*New in version 2.9.0*
- name: excluded_events
in: query
schema:
type: string
required: false
description: |
One or more event names separated by commas. If set, only return event logs with events that do not match this pattern.
*New in version 2.9.0*
responses:
"200":
description: Success.
Expand Down
10 changes: 10 additions & 0 deletions airflow/www/static/js/types/api-generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3510,6 +3510,16 @@ export interface operations {
before?: components["parameters"]["Before"];
/** Timestamp to select event logs occurring after. */
after?: components["parameters"]["After"];
/**
* One or more event names separated by commas. If set, only return event logs with events matching this pattern.
* *New in version 2.9.0*
*/
included_events?: string;
/**
* One or more event names separated by commas. If set, only return event logs with events that do not match this pattern.
* *New in version 2.9.0*
*/
excluded_events?: string;
};
};
responses: {
Expand Down
24 changes: 24 additions & 0 deletions tests/api_connexion/endpoints/test_event_log_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,30 @@ def test_should_filter_eventlogs_by_when(self, create_log_model, session):
assert response.status_code == 200
assert {eventlog["event"] for eventlog in response.json["event_logs"]} == expected_eventlogs

def test_should_filter_eventlogs_by_included_events(self, create_log_model):
for event in ["TEST_EVENT_1", "TEST_EVENT_2", "cli_scheduler"]:
create_log_model(event=event, when=self.default_time)
response = self.client.get(
"/api/v1/eventLogs?included_events=TEST_EVENT_1,TEST_EVENT_2",
environ_overrides={"REMOTE_USER": "test_granular"},
)
assert response.status_code == 200
response_data = response.json
assert len(response_data["event_logs"]) == 2
assert {"TEST_EVENT_1", "TEST_EVENT_2"} == {x["event"] for x in response_data["event_logs"]}

def test_should_filter_eventlogs_by_excluded_events(self, create_log_model):
for event in ["TEST_EVENT_1", "TEST_EVENT_2", "cli_scheduler"]:
create_log_model(event=event, when=self.default_time)
response = self.client.get(
"/api/v1/eventLogs?excluded_events=TEST_EVENT_1,TEST_EVENT_2",
environ_overrides={"REMOTE_USER": "test_granular"},
)
assert response.status_code == 200
response_data = response.json
assert len(response_data["event_logs"]) == 1
assert {"cli_scheduler"} == {x["event"] for x in response_data["event_logs"]}


class TestGetEventLogPagination(TestEventLogEndpoint):
@pytest.mark.parametrize(
Expand Down

0 comments on commit 0b9e2a7

Please sign in to comment.