forked from feast-dev/feast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
236 lines (207 loc) · 8.92 KB
/
Copy pathconfig.py
File metadata and controls
236 lines (207 loc) · 8.92 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# Copyright 2026 The Feast Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Configuration classes for Feast OpenLineage integration.
"""
import os
from dataclasses import dataclass, field
from typing import Any, Dict, Optional
@dataclass
class OpenLineageConsumerConfig:
"""
Configuration for the OpenLineage consumer (event receiver).
Attributes:
enabled: Whether the consumer is enabled
store_type: Storage backend type ('sql' uses the SQL registry DB)
connection_string: Optional separate DB connection string
api_key: API key for authenticating producers sending events
namespace_mapping: Map of OL namespace -> Feast project for RBAC scoping
"""
enabled: bool = False
store_type: str = "sql"
connection_string: Optional[str] = None
api_key: Optional[str] = None
namespace_mapping: Dict[str, str] = field(default_factory=dict)
@classmethod
def from_dict(cls, config_dict: Dict[str, Any]) -> "OpenLineageConsumerConfig":
return cls(
enabled=config_dict.get("enabled", False),
store_type=config_dict.get("store_type", "sql"),
connection_string=config_dict.get("connection_string"),
api_key=config_dict.get("api_key"),
namespace_mapping=config_dict.get("namespace_mapping", {}),
)
def to_dict(self) -> Dict[str, Any]:
return {
"enabled": self.enabled,
"store_type": self.store_type,
"connection_string": self.connection_string,
"api_key": self.api_key,
"namespace_mapping": self.namespace_mapping,
}
@dataclass
class OpenLineageConfig:
"""
Configuration for OpenLineage integration.
Attributes:
enabled: Whether OpenLineage integration is enabled
transport_type: Type of transport (http, console, file, kafka), or None to use
OpenLineage SDK defaults
transport_url: URL for HTTP transport
transport_endpoint: API endpoint for HTTP transport
api_key: Optional API key for authentication
namespace: Default namespace for Feast jobs and datasets
producer: Producer identifier for OpenLineage events
emit_on_apply: Emit lineage events when feast apply is called
emit_on_materialize: Emit lineage events during materialization
additional_config: Additional transport-specific configuration
consumer: Consumer (event receiver) configuration
"""
enabled: bool = True
transport_type: Optional[str] = None
transport_url: Optional[str] = None
transport_endpoint: str = "api/v1/lineage"
api_key: Optional[str] = None
namespace: str = "feast"
producer: str = "feast"
emit_on_apply: bool = True
emit_on_materialize: bool = True
additional_config: Dict[str, Any] = field(default_factory=dict)
consumer: OpenLineageConsumerConfig = field(
default_factory=OpenLineageConsumerConfig
)
@classmethod
def from_dict(cls, config_dict: Dict[str, Any]) -> "OpenLineageConfig":
"""
Create OpenLineageConfig from a dictionary.
Args:
config_dict: Dictionary containing configuration values
Returns:
OpenLineageConfig instance
"""
consumer_dict = config_dict.get("consumer", {})
consumer = (
OpenLineageConsumerConfig.from_dict(consumer_dict)
if consumer_dict
else OpenLineageConsumerConfig()
)
return cls(
enabled=config_dict.get("enabled", True),
transport_type=config_dict.get("transport_type"),
transport_url=config_dict.get("transport_url"),
transport_endpoint=config_dict.get("transport_endpoint", "api/v1/lineage"),
api_key=config_dict.get("api_key"),
namespace=config_dict.get("namespace", "feast"),
producer=config_dict.get("producer", "feast"),
emit_on_apply=config_dict.get("emit_on_apply", True),
emit_on_materialize=config_dict.get("emit_on_materialize", True),
additional_config=config_dict.get("additional_config", {}),
consumer=consumer,
)
@classmethod
def from_env(cls) -> "OpenLineageConfig":
"""
Create OpenLineageConfig from environment variables.
Environment variables:
FEAST_OPENLINEAGE_ENABLED: Enable/disable OpenLineage (default: true)
FEAST_OPENLINEAGE_TRANSPORT_TYPE: Transport type (default: None, uses OL SDK defaults)
FEAST_OPENLINEAGE_URL: HTTP transport URL
FEAST_OPENLINEAGE_ENDPOINT: API endpoint (default: api/v1/lineage)
FEAST_OPENLINEAGE_API_KEY: API key for authentication
FEAST_OPENLINEAGE_NAMESPACE: Default namespace (default: feast)
FEAST_OPENLINEAGE_PRODUCER: Producer identifier
Returns:
OpenLineageConfig instance
"""
consumer = OpenLineageConsumerConfig(
enabled=os.getenv("FEAST_OPENLINEAGE_CONSUMER_ENABLED", "false").lower()
== "true",
store_type=os.getenv("FEAST_OPENLINEAGE_CONSUMER_STORE_TYPE", "sql"),
connection_string=os.getenv("FEAST_OPENLINEAGE_CONSUMER_CONNECTION_STRING"),
api_key=os.getenv("FEAST_OPENLINEAGE_CONSUMER_API_KEY"),
)
return cls(
enabled=os.getenv("FEAST_OPENLINEAGE_ENABLED", "true").lower() == "true",
transport_type=os.getenv("FEAST_OPENLINEAGE_TRANSPORT_TYPE"),
transport_url=os.getenv("FEAST_OPENLINEAGE_URL"),
transport_endpoint=os.getenv(
"FEAST_OPENLINEAGE_ENDPOINT", "api/v1/lineage"
),
api_key=os.getenv("FEAST_OPENLINEAGE_API_KEY"),
namespace=os.getenv("FEAST_OPENLINEAGE_NAMESPACE", "feast"),
producer=os.getenv("FEAST_OPENLINEAGE_PRODUCER", "feast"),
emit_on_apply=os.getenv("FEAST_OPENLINEAGE_EMIT_ON_APPLY", "true").lower()
== "true",
emit_on_materialize=os.getenv(
"FEAST_OPENLINEAGE_EMIT_ON_MATERIALIZE", "true"
).lower()
== "true",
consumer=consumer,
)
@property
def consumer_api_key(self) -> Optional[str]:
return self.consumer.api_key if self.consumer else None
def to_dict(self) -> Dict[str, Any]:
"""
Convert configuration to dictionary.
Returns:
Dictionary representation of the configuration
"""
result = {
"enabled": self.enabled,
"transport_type": self.transport_type,
"transport_url": self.transport_url,
"transport_endpoint": self.transport_endpoint,
"api_key": self.api_key,
"namespace": self.namespace,
"producer": self.producer,
"emit_on_apply": self.emit_on_apply,
"emit_on_materialize": self.emit_on_materialize,
"additional_config": self.additional_config,
}
if self.consumer:
result["consumer"] = self.consumer.to_dict()
return result
def get_transport_config(self) -> Optional[Dict[str, Any]]:
"""
Get transport-specific configuration for OpenLineage client.
Returns:
Dictionary with transport configuration, or None if transport_type
is not set (allowing the OpenLineage SDK to use its own defaults).
"""
if not self.transport_type:
return None
config: Dict[str, Any] = {"type": self.transport_type}
if self.transport_type == "http":
if not self.transport_url:
raise ValueError("transport_url is required for HTTP transport")
config["url"] = self.transport_url
config["endpoint"] = self.transport_endpoint
if self.api_key:
config["auth"] = {
"type": "api_key",
"apiKey": self.api_key,
}
elif self.transport_type == "file":
config["log_file_path"] = self.additional_config.get(
"log_file_path", "openlineage_events.json"
)
elif self.transport_type == "kafka":
config["bootstrap_servers"] = self.additional_config.get(
"bootstrap_servers"
)
config["topic"] = self.additional_config.get("topic", "openlineage.events")
# Merge additional config
config.update(self.additional_config)
return config