Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add autoscaling target config #304

Merged
merged 2 commits into from
Jan 28, 2025
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
7 changes: 7 additions & 0 deletions hatchet_sdk/clients/dispatcher/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ def __init__(self, config: ClientConfig):
async def get_action_listener(
self, req: GetActionListenerRequest
) -> ActionListener:

# Override labels with the preset labels
preset_labels = self.config.worker_preset_labels

for key, value in preset_labels.items():
req.labels[key] = WorkerLabels(strValue=str(value))

# Register the worker
response: WorkerRegisterResponse = await self.aio_client.Register(
WorkerRegisterRequest(
Expand Down
13 changes: 13 additions & 0 deletions hatchet_sdk/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(
otel_exporter_oltp_protocol: str | None = None,
worker_healthcheck_port: int | None = None,
worker_healthcheck_enabled: bool | None = None,
worker_preset_labels: dict[str, str] = {},
):
self.tenant_id = tenant_id
self.tls_config = tls_config
Expand All @@ -61,6 +62,7 @@ def __init__(
self.otel_exporter_oltp_protocol = otel_exporter_oltp_protocol
self.worker_healthcheck_port = worker_healthcheck_port
self.worker_healthcheck_enabled = worker_healthcheck_enabled
self.worker_preset_labels = worker_preset_labels

if not self.logInterceptor:
self.logInterceptor = getLogger()
Expand Down Expand Up @@ -184,6 +186,16 @@ def get_config_value(key, env_var):
== "True"
)

# Add preset labels to the worker config
worker_preset_labels: dict[str, str] = defaults.worker_preset_labels

autoscaling_target = get_config_value(
"autoscaling_target", "HATCHET_CLIENT_AUTOSCALING_TARGET"
grutt marked this conversation as resolved.
Show resolved Hide resolved
)

if autoscaling_target:
worker_preset_labels["hatchet-autoscaling-target"] = autoscaling_target

return ClientConfig(
tenant_id=tenant_id,
tls_config=tls_config,
Expand All @@ -201,6 +213,7 @@ def get_config_value(key, env_var):
otel_exporter_oltp_protocol=otel_exporter_oltp_protocol,
worker_healthcheck_port=worker_healthcheck_port,
worker_healthcheck_enabled=worker_healthcheck_enabled,
worker_preset_labels=worker_preset_labels,
)

def _load_tls_config(self, tls_data: Dict, host_port) -> ClientTLSConfig:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "hatchet-sdk"
version = "0.44.2"
version = "0.45.0"
description = ""
authors = ["Alexander Belanger <[email protected]>"]
readme = "README.md"
Expand Down