-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathconfig.py
More file actions
164 lines (145 loc) · 6.24 KB
/
config.py
File metadata and controls
164 lines (145 loc) · 6.24 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
# 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 OpenLineageConfig:
"""
Configuration for OpenLineage integration.
Attributes:
enabled: Whether OpenLineage integration is enabled
transport_type: Type of transport (http, console, file, kafka)
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
"""
enabled: bool = True
transport_type: str = "console"
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)
@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
"""
return cls(
enabled=config_dict.get("enabled", True),
transport_type=config_dict.get("transport_type", "console"),
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", {}),
)
@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: console)
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
"""
return cls(
enabled=os.getenv("FEAST_OPENLINEAGE_ENABLED", "true").lower() == "true",
transport_type=os.getenv("FEAST_OPENLINEAGE_TRANSPORT_TYPE", "console"),
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",
)
def to_dict(self) -> Dict[str, Any]:
"""
Convert configuration to dictionary.
Returns:
Dictionary representation of the configuration
"""
return {
"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,
}
def get_transport_config(self) -> Dict[str, Any]:
"""
Get transport-specific configuration for OpenLineage client.
Returns:
Dictionary with transport configuration
"""
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