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: autoscaling target #563

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hatchet-dev/typescript-sdk",
"version": "0.20.0",
"version": "0.21.0",
"description": "Background task orchestration & visibility for developers",
"types": "dist/index.d.ts",
"files": [
Expand Down
9 changes: 8 additions & 1 deletion src/clients/dispatcher/dispatcher-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,17 @@ export class DispatcherClient {
}

async getActionListener(options: GetActionListenerOptions) {
// merge preset labels with labels

const mergedLabels = {
...this.config.preset_labels,
...options.labels,
};

// Register the worker
const registration = await this.client.register({
...options,
labels: options.labels ? mapLabels(options.labels) : undefined,
labels: mergedLabels ? mapLabels(mergedLabels) : undefined,
runtimeInfo: this.getRuntimeInfo(),
});

Expand Down
2 changes: 2 additions & 0 deletions src/clients/hatchet-client/client-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const ClientConfigSchema = z.object({
log_level: z.enum(['OFF', 'DEBUG', 'INFO', 'WARN', 'ERROR']).optional(),
tenant_id: z.string(),
namespace: z.string().optional(),
autoscaling_target: z.string().optional(),
preset_labels: z.record(z.string(), z.string()).optional(),
});

export type LogConstructor = (context: string, logLevel?: LogLevel) => Logger;
Expand Down
15 changes: 14 additions & 1 deletion src/util/config-loader/config-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ type EnvVars =
| 'HATCHET_CLIENT_TLS_ROOT_CA_FILE'
| 'HATCHET_CLIENT_TLS_SERVER_NAME'
| 'HATCHET_CLIENT_LOG_LEVEL'
| 'HATCHET_CLIENT_NAMESPACE';
| 'HATCHET_CLIENT_NAMESPACE'
| 'HATCHET_CLIENT_AUTOSCALING_TARGET';

type TLSStrategy = 'tls' | 'mtls';

Expand Down Expand Up @@ -83,6 +84,16 @@ export class ConfigLoader {
const namespace =
override?.namespace ?? yaml?.namespace ?? this.env('HATCHET_CLIENT_NAMESPACE');

const autoscalingTarget =
override?.autoscaling_target ??
yaml?.autoscaling_target ??
this.env('HATCHET_CLIENT_AUTOSCALING_TARGET');

const presetLabels = {
...(override?.preset_labels ?? yaml?.preset_labels ?? {}),
...(autoscalingTarget ? { 'hatchet-autoscaling-target': autoscalingTarget } : {}),
};

return {
token: override?.token ?? yaml?.token ?? this.env('HATCHET_CLIENT_TOKEN'),
host_port: grpcBroadcastAddress,
Expand All @@ -95,6 +106,8 @@ export class ConfigLoader {
'INFO',
tenant_id: tenantId,
namespace: namespace ? `${namespace}_`.toLowerCase() : '',
autoscaling_target: autoscalingTarget,
preset_labels: presetLabels,
};
}

Expand Down
Loading