Skip to content

Commit e1f70cc

Browse files
jishnundthmrkaye97
andauthored
feat: add health and metrics api on typescript sdk worker (#2457)
* feat: add health and metrics api on typescript sdk worker add: prom-client to fetch metrics data add: track health status of worker across different states * refactor: keep prom-client as optional dependency * refactor: remove async import of prom-client * chore: update package version for ts sdk * fix: lint * fix: lint, const enum --------- Co-authored-by: mrkaye97 <[email protected]>
1 parent f12c3e9 commit e1f70cc

File tree

10 files changed

+338
-2
lines changed

10 files changed

+338
-2
lines changed

sdks/typescript/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hatchet-dev/typescript-sdk",
3-
"version": "1.9.8",
3+
"version": "1.10.0",
44
"description": "Background task orchestration & visibility for developers",
55
"types": "dist/index.d.ts",
66
"files": [
@@ -91,5 +91,8 @@
9191
"yaml": "^2.7.1",
9292
"zod": "^3.24.2"
9393
},
94+
"optionalDependencies": {
95+
"prom-client": "^15.1.3"
96+
},
9497
"packageManager": "[email protected]"
9598
}

sdks/typescript/pnpm-lock.yaml

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdks/typescript/src/clients/hatchet-client/client-config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ const ClientTLSConfigSchema = z.object({
1010
server_name: z.string().optional(),
1111
});
1212

13+
const HealthcheckConfigSchema = z.object({
14+
enabled: z.boolean().optional().default(false),
15+
port: z.number().optional().default(8001),
16+
});
17+
1318
export const ClientConfigSchema = z.object({
1419
token: z.string(),
1520
tls_config: ClientTLSConfigSchema,
21+
healthcheck: HealthcheckConfigSchema.optional(),
1622
host_port: z.string(),
1723
api_url: z.string(),
1824
log_level: z.enum(['OFF', 'DEBUG', 'INFO', 'WARN', 'ERROR']).optional(),

sdks/typescript/src/clients/hatchet-client/fixtures/.hatchet.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ tls_config:
66
key_file: 'TLS_KEY_FILE_YAML'
77
ca_file: 'TLS_ROOT_CA_FILE_YAML'
88
server_name: 'TLS_SERVER_NAME_YAML'
9+
healthcheck:
10+
enabled: true
11+
port: 8005

sdks/typescript/src/clients/hatchet-client/hatchet-client.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ describe('Client', () => {
2525
server_name: 'TLS_SERVER_NAME',
2626
tls_strategy: 'tls',
2727
},
28+
healthcheck: {
29+
enabled: true,
30+
port: 8002,
31+
},
2832
},
2933
{
3034
credentials: ChannelCredentials.createInsecure(),
@@ -47,6 +51,10 @@ describe('Client', () => {
4751
ca_file: 'TLS_ROOT_CA_FILE',
4852
server_name: 'TLS_SERVER_NAME',
4953
},
54+
healthcheck: {
55+
enabled: true,
56+
port: 8002,
57+
},
5058
})
5159
);
5260
});
@@ -78,6 +86,10 @@ describe('Client', () => {
7886
server_name: 'TLS_SERVER_NAME',
7987
tls_strategy: 'tls',
8088
},
89+
healthcheck: {
90+
enabled: false,
91+
port: 8003,
92+
},
8193
},
8294
{
8395
config_path: './fixtures/.hatchet.yaml',
@@ -101,6 +113,10 @@ describe('Client', () => {
101113
ca_file: 'TLS_ROOT_CA_FILE',
102114
server_name: 'TLS_SERVER_NAME',
103115
},
116+
healthcheck: {
117+
enabled: false,
118+
port: 8003,
119+
},
104120
})
105121
);
106122
});

sdks/typescript/src/util/config-loader/config-loader.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ fdescribe('ConfigLoader', () => {
88
process.env.HATCHET_CLIENT_TLS_KEY_FILE = 'TLS_KEY_FILE';
99
process.env.HATCHET_CLIENT_TLS_ROOT_CA_FILE = 'TLS_ROOT_CA_FILE';
1010
process.env.HATCHET_CLIENT_TLS_SERVER_NAME = 'TLS_SERVER_NAME';
11+
process.env.HATCHET_CLIENT_WORKER_HEALTHCHECK_ENABLED = 'true';
12+
process.env.HATCHET_CLIENT_WORKER_HEALTHCHECK_PORT = '8001';
1113
});
1214

1315
it('should load from environment variables', () => {
@@ -27,6 +29,10 @@ fdescribe('ConfigLoader', () => {
2729
ca_file: 'TLS_ROOT_CA_FILE',
2830
server_name: 'TLS_SERVER_NAME',
2931
},
32+
healthcheck: {
33+
enabled: true,
34+
port: 8001,
35+
},
3036
});
3137
});
3238

@@ -75,6 +81,10 @@ fdescribe('ConfigLoader', () => {
7581
ca_file: 'TLS_ROOT_CA_FILE_YAML',
7682
server_name: 'TLS_SERVER_NAME_YAML',
7783
},
84+
healthcheck: {
85+
enabled: true,
86+
port: 8002,
87+
},
7888
});
7989
});
8090

@@ -97,6 +107,10 @@ fdescribe('ConfigLoader', () => {
97107
ca_file: 'TLS_ROOT_CA_FILE_YAML',
98108
server_name: 'TLS_SERVER_NAME_YAML',
99109
},
110+
healthcheck: {
111+
enabled: true,
112+
port: 8002,
113+
},
100114
});
101115
});
102116
});

sdks/typescript/src/util/config-loader/config-loader.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ type EnvVars =
1717
| 'HATCHET_CLIENT_TLS_ROOT_CA_FILE'
1818
| 'HATCHET_CLIENT_TLS_SERVER_NAME'
1919
| 'HATCHET_CLIENT_LOG_LEVEL'
20-
| 'HATCHET_CLIENT_NAMESPACE';
20+
| 'HATCHET_CLIENT_NAMESPACE'
21+
| 'HATCHET_CLIENT_WORKER_HEALTHCHECK_ENABLED'
22+
| 'HATCHET_CLIENT_WORKER_HEALTHCHECK_PORT';
2123

2224
type TLSStrategy = 'tls' | 'mtls';
2325

@@ -46,6 +48,12 @@ export class ConfigLoader {
4648

4749
const token = override?.token ?? yaml?.token ?? this.env('HATCHET_CLIENT_TOKEN');
4850

51+
const healthCheckConfig = override?.healthcheck ??
52+
yaml?.healthcheck ?? {
53+
enabled: this.env('HATCHET_CLIENT_WORKER_HEALTHCHECK_ENABLED') === 'true',
54+
port: parseInt(this.env('HATCHET_CLIENT_WORKER_HEALTHCHECK_PORT') || '8001', 10),
55+
};
56+
4957
if (!token) {
5058
throw new Error(
5159
'No token provided. Provide it by setting the HATCHET_CLIENT_TOKEN environment variable.'
@@ -91,6 +99,7 @@ export class ConfigLoader {
9199
host_port: grpcBroadcastAddress,
92100
api_url: apiUrl,
93101
tls_config: tlsConfig,
102+
healthcheck: healthCheckConfig,
94103
log_level:
95104
override?.log_level ??
96105
yaml?.log_level ??

sdks/typescript/src/util/config-loader/fixtures/.hatchet.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ tls_config:
66
key_file: 'TLS_KEY_FILE_YAML'
77
ca_file: 'TLS_ROOT_CA_FILE_YAML'
88
server_name: 'TLS_SERVER_NAME_YAML'
9+
healthcheck:
10+
enabled: true
11+
port: 8002

0 commit comments

Comments
 (0)