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
17 changes: 17 additions & 0 deletions libs/executors/garf/executors/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,32 @@
from typing_extensions import Self


class ConfigMetadata(pydantic.BaseModel):
"""Contains optional metadata on config.

Attributes:
description: Brief description of workflow.
version: Version of workflow.
"""

description: str | None = None
version: str | None = None


class Config(pydantic.BaseModel):
"""Stores necessary parameters for one or multiple API sources.

Attributes:
source: Mapping between API source alias and execution parameters.
global_parameters: Common parameters for each source.
name: Optional name of config.
metadata: Optional metadata for config.
"""

sources: dict[str, ExecutionContext]
global_parameters: ExecutionContext | None = None
name: str | None = None
metadata: ConfigMetadata = ConfigMetadata()

@classmethod
def from_file(cls, path: str | pathlib.Path | os.PathLike[str]) -> Config:
Expand Down
4 changes: 4 additions & 0 deletions libs/executors/garf/executors/workflows/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ class Workflow(pydantic.BaseModel):
Attributes:
steps: Contains one or several fetcher executions.
context: Query and fetcher parameters to overwrite in steps.
execution_config: Optional config for running workflow.
prefix: Optional location of workflow.
name: Optional name of workflow.
metadata: Optional metadata.
"""

steps: list[ExecutionStep]
Expand Down
5 changes: 5 additions & 0 deletions libs/executors/garf/executors/workflows/workflow_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def run(
workflow_attributes.update({'workflow.name': name})
if version := self.workflow.metadata.version:
workflow_attributes.update({'workflow.version': version})
if config := self.workflow.execution_config:
if config_version := config.metadata.version:
workflow_attributes.update({'config.version': config_version})
if config_name := config.name:
workflow_attributes.update({'config.name': config_name})
if workflow_attributes:
span.set_attributes(workflow_attributes)
self.workflow.compile()
Expand Down
8 changes: 6 additions & 2 deletions libs/executors/tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TestConfig:
def test_from_file_returns_correct_context_from_data(self, tmp_path):
tmp_config = tmp_path / 'config.yaml'
data = {
'name': 'test_config',
'sources': {
'api': {
'query_parameters': {
Expand All @@ -38,7 +39,8 @@ def test_from_file_returns_correct_context_from_data(self, tmp_path):
'destination_folder': '/tmp',
},
}
}
},
'metadata': {'version': '0.0.0'},
}
with open(tmp_config, 'w', encoding='utf-8') as f:
yaml.dump(data, f, encoding='utf-8')
Expand All @@ -49,6 +51,7 @@ def test_from_file_returns_correct_context_from_data(self, tmp_path):
def test_save_returns_correct_data(self, tmp_path):
tmp_config = tmp_path / 'config.yaml'
data = {
'name': 'test_config',
'sources': {
'api': {
'query_parameters': {
Expand All @@ -67,7 +70,8 @@ def test_save_returns_correct_data(self, tmp_path):
'destination_folder': '/tmp',
},
}
}
},
'metadata': {'version': '0.0.0'},
}
config = Config(**data)
config.save(tmp_config)
Expand Down
Loading