Skip to content
Merged
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
31 changes: 23 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ jobs:
fi

test:
needs:
- filter-pr-changes
- determine-revision
strategy:
fail-fast: false
matrix:
Expand All @@ -105,8 +102,8 @@ jobs:
cache-dependency-path: pyproject.toml
- name: "Install dependencies"
run: python -m pip install .[develop]
- name: "Run tests${{ needs.filter-pr-changes.outputs.track_filter }}${{ needs.determine-revision.outputs.revision }}"
run: hatch -v -e unit run test${{ needs.filter-pr-changes.outputs.track_filter }}${{ needs.determine-revision.outputs.revision }}
- name: "Run tests"
run: hatch -v -e unit run test
- uses: elastic/es-perf-github-status@v2
if: ${{ failure() && ( github.event_name == 'schedule' || ( github.event_name == 'push' && github.ref_name == env.DEFAULT_BRANCH ) ) }}
with:
Expand All @@ -128,6 +125,9 @@ jobs:

name: rally-tracks-compat ${{ matrix.python-version }}
steps:
- name: Check public IP address
run: curl -4s ifconfig.me
continue-on-error: true
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
Expand All @@ -140,15 +140,30 @@ jobs:
java-version: "21"
- run: echo "JAVA21_HOME=$JAVA_HOME_21_X64" >> $GITHUB_ENV
- run: echo "JAVA11_HOME=$JAVA_HOME_11_X64" >> $GITHUB_ENV
- name: Free Disk Space
continue-on-error: true
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be
with:
android: true
dotnet: true
haskell: true
large-packages: false
docker-images: false
swap-storage: false
tool-cache: false
- name: Check disk space before
run: df -h
- name: "Install dependencies"
run: python -m pip install .[develop]
- name: "Run tests${{ needs.filter-pr-changes.outputs.track_filter }}${{ needs.determine-revision.outputs.revision }}"
run: hatch -v -e it run test${{ needs.filter-pr-changes.outputs.track_filter }}${{ needs.determine-revision.outputs.revision }}
timeout-minutes: 120
- name: "Run tests${{ needs.filter-pr-changes.outputs.track_filter }}${{ needs.determine-revision.outputs.revision }} --source-build-release"
run: hatch -v -e it run test${{ needs.filter-pr-changes.outputs.track_filter }}${{ needs.determine-revision.outputs.revision }} --source-build-release
timeout-minutes: 160
env:
# elastic/endpoint fetches assets from GitHub, authenticate to avoid
# being rate limited
ASSETS_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check disk space after
run: df -h
- uses: elastic/es-perf-github-status@v2
if: ${{ failure() && ( github.event_name == 'schedule' || ( github.event_name == 'push' && github.ref_name == env.DEFAULT_BRANCH ) ) }}
with:
Expand Down
2 changes: 1 addition & 1 deletion elastic/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ install: venv-create
# install pytest for tests
. $(VENV_ACTIVATE_FILE); pip3 install pytest==6.2.5 pytest-benchmark==3.2.2
# install dependencies for tests
. $(VENV_ACTIVATE_FILE); pip3 install geneve==0.0.3 pytest-asyncio==0.18.1 git+https://github.com/elastic/package-assets.git
. $(VENV_ACTIVATE_FILE); pip3 install geneve==0.3.0 pytest-asyncio==0.18.1 git+https://github.com/elastic/package-assets.git
# install (latest) Rally for smoke tests
. $(VENV_ACTIVATE_FILE); pip3 install git+ssh://git@github.com/elastic/rally.git --use-feature=2020-resolver

Expand Down
2 changes: 1 addition & 1 deletion elastic/security/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ This challenge executes indexing and querying sequentially. Queries will be issu

### Generate source events for detection rules (generate-alerts-source-events)

This challenge is a demo usage of [Geneve](https://github.com/elastic/geneve) via the `events-emitter-source` [parameter source](https://github.com/elastic/rally-tracks/blob/master/elastic/security/parameter_sources/events_emitter.py), it generates source events but does not interact with anything else. It's executed as part of the [it/test_security.py](https://github.com/elastic/rally-tracks/blob/master/it/test_security.py) integration tests. Currently, Geneve is pinned to version [v0.2.0](https://github.com/elastic/rally-tracks/blob/master/elastic/security/track.json#L410). This is the only challenge that depends on Geneve and pyyaml (Geneve requires pyyaml).
This challenge is a demo usage of [Geneve](https://github.com/elastic/geneve) via the `events-emitter-source` [parameter source](https://github.com/elastic/rally-tracks/blob/master/elastic/security/parameter_sources/events_emitter.py), it generates source events but does not interact with anything else. It's executed as part of the [it/test_security.py](https://github.com/elastic/rally-tracks/blob/master/it/test_security.py) integration tests. Currently, Geneve is pinned to version [v0.3.0](https://github.com/elastic/rally-tracks/blob/master/elastic/security/track.json#L410). This is the only challenge that depends on Geneve and pyyaml (Geneve requires pyyaml).

## Ratios

Expand Down
2 changes: 1 addition & 1 deletion elastic/security/track.json
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@
{% endfor %}
],
"dependencies": [
"geneve==0.2.0",
"geneve==0.3.0",
"pyyaml",
"elastic-transport==8.4.1",
"elasticsearch==8.6.1"
Expand Down
2 changes: 1 addition & 1 deletion elastic/shared/parameter_sources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
DEFAULT_MAX_DATE = "2020-01-01"

# this provides a universal start date for `now` if we are using it as the current time
now = datetime.utcnow().replace(tzinfo=timezone.utc)
now = datetime.now(tz=timezone.utc)


def utc_now():
Expand Down
2 changes: 1 addition & 1 deletion elastic/shared/parameter_sources/processed.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self, track, params, **kwargs):
self._volume_per_day_gb = convert_to_gib(raw_volume_per_day)
self.start_time = int(time.perf_counter())
self._profile = params.get("profile", "fixed_interval")
now = datetime.utcnow().replace(tzinfo=timezone.utc)
now = datetime.now(tz=timezone.utc)

def utc_now():
return now
Expand Down
6 changes: 3 additions & 3 deletions elastic/shared/parameter_sources/workflow_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def __init__(self, track, params, **kwargs):
self.logger.info("Workflow [%s] is using seed [%s]", self.workflow, self.random_seed)
self.number_of_tasks = track.selected_challenge_or_default.parameters.get("number-of-workflows")
# for testing purposes only we allow a configurable now function
self._utc_now = kwargs.get("utc_now", datetime.utcnow)
self._init_date = self._utc_now().replace(tzinfo=timezone.utc)
self._utc_now = kwargs.get("utc_now", lambda: datetime.now(tz=timezone.utc))
self._init_date = self._utc_now()
self._detailed_results = params.get(
"detailed-results", track.selected_challenge_or_default.parameters.get("detailed-results", False)
)
Expand Down Expand Up @@ -266,7 +266,7 @@ def copy_and_modify_action(self, action):
else:
# process fields - use the start_date + the time passed since we started, as the time
# all dates for the action should be the same
query_max_date = self._max_date_start + (self._utc_now().replace(tzinfo=timezone.utc) - self._init_date)
query_max_date = self._max_date_start + (self._utc_now() - self._init_date)

for query_handler in self.workflow_handlers[action_id]:
# scale the duration based on the max if set
Expand Down
4 changes: 2 additions & 2 deletions elastic/shared/query_handlers/date_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def read_ranges(self):
self.request_body["time_zone"] = "UTC"
if "min" in self.extended_bounds and "max" in self.extended_bounds:
try:
self.max_bound = datetime.datetime.utcfromtimestamp(int(self.extended_bounds["max"]) / 1000)
self.min_bound = datetime.datetime.utcfromtimestamp(int(self.extended_bounds["min"]) / 1000)
self.max_bound = datetime.datetime.fromtimestamp(int(self.extended_bounds["max"]) / 1000, tz=datetime.timezone.utc)
self.min_bound = datetime.datetime.fromtimestamp(int(self.extended_bounds["min"]) / 1000, tz=datetime.timezone.utc)
except ValueError:
raise exceptions.TrackConfigError(
f"Date Histogram aggregation requires epoch milliseconds for its "
Expand Down
2 changes: 1 addition & 1 deletion elastic/shared/utils/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def parse_interval(offset: str) -> Optional[timedelta]:
raise TimeParsingError(f"Invalid offset: {offset}")


def parse_date_time(point: str, utcnow: Callable[..., datetime] = datetime.utcnow) -> Optional[datetime]:
def parse_date_time(point: str, utcnow: Callable[..., datetime] = lambda: datetime.now(tz=timezone.utc)) -> Optional[datetime]:
now = "now"
if not point:
return None
Expand Down
7 changes: 6 additions & 1 deletion elastic/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ def as_future(result=None, exception=None):
:param exception: Exceptional result.
:return: The corresponding future.
"""
f = asyncio.Future()
try:
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
f = loop.create_future()
if exception and result:
raise AssertionError("Specify a result or an exception but not both")
if exception:
Expand Down
2 changes: 1 addition & 1 deletion elastic/tests/query_handlers/date_histogram_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_process_contract_bounds_with_min_date():
"fixed_interval": "1m",
}
date_histogram_handler = DateHistogramHandler(date_histogram_agg)
min_date = datetime.datetime.utcfromtimestamp(1606911780).replace(tzinfo=datetime.timezone.utc)
min_date = datetime.datetime.fromtimestamp(1606911780, tz=datetime.timezone.utc)
date_histogram_handler.process(DateTimeValues(min_date=min_date, max_date=start, duration=None))
assert date_histogram_agg["extended_bounds"]["min"] == 1606911780000
assert date_histogram_agg["extended_bounds"]["max"] == 1606912380000
Expand Down
8 changes: 4 additions & 4 deletions elastic/tests/query_handlers/range_query_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_invalid_time_date():
"format": "strict_date_optional_time",
}
}
).process(DateTimeValues(min_date=None, max_date=datetime.datetime.utcnow(), duration=None))
).process(DateTimeValues(min_date=None, max_date=datetime.datetime.now(tz=datetime.timezone.utc), duration=None))
assert rae.value.args[0] == "Invalid time format: 2020-11-30T:16:59.340Z"


Expand All @@ -138,7 +138,7 @@ def test_missing_gte():
"format": "strict_date_optional_time",
}
}
).process(DateTimeValues(min_date=None, max_date=datetime.datetime.utcnow(), duration=None))
).process(DateTimeValues(min_date=None, max_date=datetime.datetime.now(tz=datetime.timezone.utc), duration=None))
assert (
rae.value.message == 'Range query for date does not have both "gte" or "gt" and '
"\"lte\" or \"lt\" key - [{'@timestamp': {'lte': '2020-12-01T12:16:59.340Z', "
Expand All @@ -155,7 +155,7 @@ def test_missing_lte():
"format": "strict_date_optional_time",
}
}
).process(DateTimeValues(min_date=None, max_date=datetime.datetime.utcnow(), duration=None))
).process(DateTimeValues(min_date=None, max_date=datetime.datetime.now(tz=datetime.timezone.utc), duration=None))
assert (
rae.value.message == 'Range query for date does not have both "gte" or "gt" and '
"\"lte\" or \"lt\" key - [{'@timestamp': {'gte': '2020-12-01T12:16:59.340Z', "
Expand All @@ -166,7 +166,7 @@ def test_missing_lte():
def test_pass_through():
range_query = {"http.status.code": {"gte": 200, "lte": 300}}
range_query_handler = RangeQueryHandler(range_query)
range_query_handler.process(DateTimeValues(min_date=None, max_date=datetime.datetime.utcnow(), duration=None))
range_query_handler.process(DateTimeValues(min_date=None, max_date=datetime.datetime.now(tz=datetime.timezone.utc), duration=None))
assert range_query["http.status.code"]["gte"] == 200
assert range_query["http.status.code"]["lte"] == 300

Expand Down
8 changes: 4 additions & 4 deletions elastic/tests/utils/time_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_generate_new_bounds_preserve_interval():
upper_bound = parse_date_optional_time("2020-01-03T12:00:00.000Z")
lower_bound = parse_date_optional_time("2020-01-02T12:00:00.000Z")

utc_now = datetime.datetime.utcnow()
utc_now = datetime.datetime.now(tz=datetime.timezone.utc)
date_data = DateTimeValues(min_date=None, max_date=utc_now, duration=None)

new_lower, new_upper = date_data.generate_new_bounds(lower_bound, upper_bound)
Expand All @@ -151,7 +151,7 @@ def test_generate_new_bounds_replace_interval():
upper_bound = parse_date_optional_time("2020-01-03T12:00:00.000Z")
lower_bound = parse_date_optional_time("2020-01-02T12:00:00.000Z")

utc_now = datetime.datetime.utcnow()
utc_now = datetime.datetime.now(tz=datetime.timezone.utc)
date_data = DateTimeValues(min_date=None, max_date=utc_now, duration=datetime.timedelta(minutes=1))

new_lower, new_upper = date_data.generate_new_bounds(lower_bound, upper_bound)
Expand All @@ -172,7 +172,7 @@ def test_generate_new_bounds_respects_min_and_max_date():


def test_calendar_intervals():
utc_now = datetime.datetime.utcnow()
utc_now = datetime.datetime.now(tz=datetime.timezone.utc)
date_data = DateTimeValues(None, utc_now, None)
assert date_data.calendar_interval is None

Expand All @@ -187,7 +187,7 @@ def test_calendar_intervals():


def test_fixed_intervals():
utc_now = datetime.datetime.utcnow()
utc_now = datetime.datetime.now(tz=datetime.timezone.utc)
date_data = DateTimeValues(None, utc_now, None)
assert date_data.calendar_interval is None

Expand Down
5 changes: 5 additions & 0 deletions it/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ def es_cluster_cleanup(es_cluster):
es = Elasticsearch(f"http://localhost:{es_cluster.http_port}")
es.indices.delete(index="*")
es.indices.delete_data_stream(name="*")


@pytest.fixture
def es_release_build(es_cluster) -> bool:
return es_cluster.source_build_release
4 changes: 3 additions & 1 deletion it/logs/test_logs_unmapped.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

@pytest.mark.track("elastic/logs")
class TestLogsUnmapped:
def test_logs_chicken(self, es_cluster, rally):
def test_logs_chicken(self, es_cluster, rally, es_release_build):
if es_release_build:
pytest.skip("logging-insist-chicken is not supported on release builds")
custom = {"mapping": "unmapped"}
ret = rally.race(
track="elastic/logs",
Expand Down
7 changes: 5 additions & 2 deletions it/test_all_tracks_and_challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ class TestTrackRepository:
"nyc_taxis": ["update-aggs-only"],
}
skip_challenges = {"esql": ["query-searchable-snapshot"]}
snapshot_only_challenges = {"wikipedia": ["esql-full-text-functions"]}

def test_autogenerated(self, es_cluster, rally, track, challenge, rally_options, es_cluster_cleanup):
def test_autogenerated(self, es_cluster, rally, track, challenge, rally_options, es_cluster_cleanup, es_release_build):
track_params = {}
if es_release_build and challenge in self.snapshot_only_challenges.get(track, []):
pytest.skip(f"{track}-{challenge} is not supported on release builds")
if track not in self.skip_tracks and challenge not in self.skip_challenges.get(track, []):
if challenge in self.disable_assertions.get(track, []):
rally_options.update({"enable_assertions": False})
Expand All @@ -47,4 +50,4 @@ def test_autogenerated(self, es_cluster, rally, track, challenge, rally_options,
ret = rally.race(track=track, challenge=challenge, track_params=track_params, **rally_options)
assert ret == 0
else:
pytest.skip(msg=f"{track}-{challenge} included in skip list")
pytest.skip(f"{track}-{challenge} included in skip list")
Loading