Repository navigation
Expand file tree
/
Copy pathfeast_services.py
More file actions
212 lines (185 loc) · 6.45 KB
/
Copy pathfeast_services.py
File metadata and controls
212 lines (185 loc) · 6.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import os
import shutil
import socket
import subprocess
import tempfile
import time
from typing import Any, Dict, Tuple
import pyspark
import pytest
import yaml
from pytest_postgresql.executor import PostgreSQLExecutor
from pytest_redis.executor import RedisExecutor
__all__ = (
"feast_core",
"feast_serving",
"enable_auth",
"feast_jobservice",
)
def _start_jar(jar, options=None) -> subprocess.Popen:
if not os.path.isfile(jar):
raise ValueError(f"{jar} doesn't exist")
cmd = [shutil.which("java"), "-jar", jar]
if options:
cmd.extend(options)
return subprocess.Popen(cmd) # type: ignore
def _wait_port_open(port, max_wait=60):
print(f"Waiting for port {port}")
start = time.time()
while True:
try:
socket.create_connection(("localhost", port), timeout=1)
except OSError:
if time.time() - start > max_wait:
raise
time.sleep(1)
else:
return
@pytest.fixture(
scope="session", params=[False],
)
def enable_auth(request):
return request.param
@pytest.fixture(scope="session")
def feast_core(
java_project_root, project_version, enable_auth, postgres_server: PostgreSQLExecutor
):
jar = str(
java_project_root / "core" / "target" / f"feast-core-{project_version}-exec.jar"
)
config = dict(
feast=dict(
security=dict(
enabled=enable_auth,
provider="jwt",
options=dict(
jwkEndpointURI="https://www.googleapis.com/oauth2/v3/certs"
),
)
),
spring=dict(
datasource=dict(
url=f"jdbc:postgresql://{postgres_server.host}:{postgres_server.port}/postgres"
)
),
)
with tempfile.NamedTemporaryFile(suffix=".yaml", mode="w+") as config_file:
yaml.dump(config, config_file)
config_file.flush()
process = _start_jar(
jar,
[
f"--spring.config.location=classpath:/application.yml,file://{config_file.name}"
],
)
_wait_port_open(6565)
yield "localhost", 6565
process.terminate()
@pytest.fixture(scope="session")
def feast_serving(
java_project_root,
project_version,
enable_auth,
redis_server: RedisExecutor,
feast_core,
pytestconfig,
):
_wait_port_open(6565) # in case core is restarting with new config
jar = str(
java_project_root
/ "serving"
/ "target"
/ f"feast-serving-{project_version}-exec.jar"
)
if pytestconfig.getoption("redis_cluster"):
store: Dict[str, Any] = dict(
name="online",
type="REDIS_CLUSTER",
config=dict(connection_string=f"{redis_server.host}:{redis_server.port}"),
)
else:
store = dict(
name="online",
type="REDIS",
config=dict(host=redis_server.host, port=redis_server.port),
)
config = dict(
feast=dict(
stores=[store],
coreAuthentication=dict(enabled=enable_auth, provider="google"),
security=dict(authentication=dict(enabled=enable_auth, provider="jwt")),
)
)
with tempfile.NamedTemporaryFile(suffix=".yaml", mode="w+") as config_file:
yaml.dump(config, config_file)
config_file.flush()
process = _start_jar(
jar,
[
f"--spring.config.location=classpath:/application.yml,file://{config_file.name}"
],
)
_wait_port_open(6566)
yield "localhost", 6566
process.terminate()
@pytest.fixture(scope="session")
def feast_jobservice(
pytestconfig,
ingestion_job_jar,
redis_server: RedisExecutor,
feast_core: Tuple[str, int],
feast_serving: Tuple[str, int],
global_staging_path,
):
if not pytestconfig.getoption("with_job_service"):
yield None
else:
env = os.environ.copy()
if pytestconfig.getoption("env") == "local":
env["FEAST_CORE_URL"] = f"{feast_core[0]}:{feast_core[1]}"
env["FEAST_SERVING_URL"] = f"{feast_serving[0]}:{feast_serving[1]}"
env["FEAST_SPARK_LAUNCHER"] = "standalone"
env["FEAST_SPARK_STANDALONE_MASTER"] = "local"
env["FEAST_SPARK_HOME"] = os.getenv("SPARK_HOME") or os.path.dirname(
pyspark.__file__
)
env["FEAST_SPARK_INGESTION_JAR"] = ingestion_job_jar
env["FEAST_REDIS_HOST"] = redis_server.host
env["FEAST_REDIS_PORT"] = str(redis_server.port)
env["FEAST_SPARK_STAGING_LOCATION"] = os.path.join(
global_staging_path, "spark"
)
env["FEAST_HISTORICAL_FEATURE_OUTPUT_LOCATION"] = os.path.join(
global_staging_path, "historical_output"
)
if pytestconfig.getoption("env") == "gcloud":
env["FEAST_CORE_URL"] = f"{feast_core[0]}:{feast_core[1]}"
env["FEAST_SERVING_URL"] = f"{feast_serving[0]}:{feast_serving[1]}"
env["FEAST_SPARK_LAUNCHER"] = "dataproc"
env["FEAST_DATAPROC_CLUSTER_NAME"] = pytestconfig.getoption(
"dataproc_cluster_name"
)
env["FEAST_DATAPROC_PROJECT"] = pytestconfig.getoption("dataproc_project")
env["FEAST_DATAPROC_REGION"] = pytestconfig.getoption("dataproc_region")
env["FEAST_DATAPROC_EXECUTOR_INSTANCES"] = pytestconfig.getoption(
"dataproc_executor_instances"
)
env["FEAST_DATAPROC_EXECUTOR_CORES"] = pytestconfig.getoption(
"dataproc_executor_cores"
)
env["FEAST_DATAPROC_EXECUTOR_MEMORY"] = pytestconfig.getoption(
"dataproc_executor_memory"
)
env["FEAST_SPARK_STAGING_LOCATION"] = os.path.join(
global_staging_path, "dataproc"
)
env["FEAST_SPARK_INGESTION_JAR"] = ingestion_job_jar
env["FEAST_REDIS_HOST"] = pytestconfig.getoption("redis_url").split(":")[0]
env["FEAST_REDIS_PORT"] = pytestconfig.getoption("redis_url").split(":")[1]
env["FEAST_HISTORICAL_FEATURE_OUTPUT_LOCATION"] = os.path.join(
global_staging_path, "historical_output"
)
process = subprocess.Popen(["feast-spark", "server"], env=env)
_wait_port_open(6568)
yield "localhost", 6568
process.terminate()