Skip to content

Commit

Permalink
Config Change: LHW_TASK_WORKER_ID
Browse files Browse the repository at this point in the history
Implements ticket #614 and introduces the LHW_TASK_WORKER_ID config which replaces the confusing LHC_CLIENT_ID config.
  • Loading branch information
coltmcnealy-lh committed Jan 22, 2024
1 parent ba49862 commit 4e56bd1
Show file tree
Hide file tree
Showing 38 changed files with 1,023 additions and 1,022 deletions.
2 changes: 1 addition & 1 deletion dashboard/apps/web/littlehorse-public-api/acls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ export type Exact<P, I extends P> = P extends Builtin ? P

function toTimestamp(dateStr: string): Timestamp {
const date = new globalThis.Date(dateStr);
const seconds = date.getTime() / 1_000;
const seconds = Math.trunc(date.getTime() / 1_000);
const nanos = (date.getTime() % 1_000) * 1_000_000;
return { seconds, nanos };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ export type Exact<P, I extends P> = P extends Builtin ? P

function toTimestamp(dateStr: string): Timestamp {
const date = new globalThis.Date(dateStr);
const seconds = date.getTime() / 1_000;
const seconds = Math.trunc(date.getTime() / 1_000);
const nanos = (date.getTime() % 1_000) * 1_000_000;
return { seconds, nanos };
}
Expand Down
2 changes: 1 addition & 1 deletion dashboard/apps/web/littlehorse-public-api/node_run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ export type Exact<P, I extends P> = P extends Builtin ? P

function toTimestamp(dateStr: string): Timestamp {
const date = new globalThis.Date(dateStr);
const seconds = date.getTime() / 1_000;
const seconds = Math.trunc(date.getTime() / 1_000);
const nanos = (date.getTime() % 1_000) * 1_000_000;
return { seconds, nanos };
}
Expand Down
2 changes: 1 addition & 1 deletion dashboard/apps/web/littlehorse-public-api/object_id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ export type Exact<P, I extends P> = P extends Builtin ? P

function toTimestamp(dateStr: string): Timestamp {
const date = new globalThis.Date(dateStr);
const seconds = date.getTime() / 1_000;
const seconds = Math.trunc(date.getTime() / 1_000);
const nanos = (date.getTime() % 1_000) * 1_000_000;
return { seconds, nanos };
}
Expand Down
20 changes: 10 additions & 10 deletions dashboard/apps/web/littlehorse-public-api/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ export interface ExternalEventList {
*/
export interface RegisterTaskWorkerRequest {
/** Is the ID of the Task Worker. */
clientId: string;
taskWorkerId: string;
/** The TaskDef the worker wants to poll for. */
taskDefId:
| TaskDefId
Expand Down Expand Up @@ -5115,13 +5115,13 @@ export const ExternalEventList = {
};

function createBaseRegisterTaskWorkerRequest(): RegisterTaskWorkerRequest {
return { clientId: "", taskDefId: undefined, listenerName: "" };
return { taskWorkerId: "", taskDefId: undefined, listenerName: "" };
}

export const RegisterTaskWorkerRequest = {
encode(message: RegisterTaskWorkerRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.clientId !== "") {
writer.uint32(10).string(message.clientId);
if (message.taskWorkerId !== "") {
writer.uint32(10).string(message.taskWorkerId);
}
if (message.taskDefId !== undefined) {
TaskDefId.encode(message.taskDefId, writer.uint32(18).fork()).ldelim();
Expand All @@ -5144,7 +5144,7 @@ export const RegisterTaskWorkerRequest = {
break;
}

message.clientId = reader.string();
message.taskWorkerId = reader.string();
continue;
case 2:
if (tag !== 18) {
Expand All @@ -5171,16 +5171,16 @@ export const RegisterTaskWorkerRequest = {

fromJSON(object: any): RegisterTaskWorkerRequest {
return {
clientId: isSet(object.clientId) ? globalThis.String(object.clientId) : "",
taskWorkerId: isSet(object.taskWorkerId) ? globalThis.String(object.taskWorkerId) : "",
taskDefId: isSet(object.taskDefId) ? TaskDefId.fromJSON(object.taskDefId) : undefined,
listenerName: isSet(object.listenerName) ? globalThis.String(object.listenerName) : "",
};
},

toJSON(message: RegisterTaskWorkerRequest): unknown {
const obj: any = {};
if (message.clientId !== "") {
obj.clientId = message.clientId;
if (message.taskWorkerId !== "") {
obj.taskWorkerId = message.taskWorkerId;
}
if (message.taskDefId !== undefined) {
obj.taskDefId = TaskDefId.toJSON(message.taskDefId);
Expand All @@ -5196,7 +5196,7 @@ export const RegisterTaskWorkerRequest = {
},
fromPartial<I extends Exact<DeepPartial<RegisterTaskWorkerRequest>, I>>(object: I): RegisterTaskWorkerRequest {
const message = createBaseRegisterTaskWorkerRequest();
message.clientId = object.clientId ?? "";
message.taskWorkerId = object.taskWorkerId ?? "";
message.taskDefId = (object.taskDefId !== undefined && object.taskDefId !== null)
? TaskDefId.fromPartial(object.taskDefId)
: undefined;
Expand Down Expand Up @@ -8638,7 +8638,7 @@ export type Exact<P, I extends P> = P extends Builtin ? P

function toTimestamp(dateStr: string): Timestamp {
const date = new globalThis.Date(dateStr);
const seconds = date.getTime() / 1_000;
const seconds = Math.trunc(date.getTime() / 1_000);
const nanos = (date.getTime() % 1_000) * 1_000_000;
return { seconds, nanos };
}
Expand Down
2 changes: 1 addition & 1 deletion dashboard/apps/web/littlehorse-public-api/task_def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export type Exact<P, I extends P> = P extends Builtin ? P

function toTimestamp(dateStr: string): Timestamp {
const date = new globalThis.Date(dateStr);
const seconds = date.getTime() / 1_000;
const seconds = Math.trunc(date.getTime() / 1_000);
const nanos = (date.getTime() % 1_000) * 1_000_000;
return { seconds, nanos };
}
Expand Down
2 changes: 1 addition & 1 deletion dashboard/apps/web/littlehorse-public-api/task_run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ export type Exact<P, I extends P> = P extends Builtin ? P

function toTimestamp(dateStr: string): Timestamp {
const date = new globalThis.Date(dateStr);
const seconds = date.getTime() / 1_000;
const seconds = Math.trunc(date.getTime() / 1_000);
const nanos = (date.getTime() % 1_000) * 1_000_000;
return { seconds, nanos };
}
Expand Down
2 changes: 1 addition & 1 deletion dashboard/apps/web/littlehorse-public-api/user_tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ export type Exact<P, I extends P> = P extends Builtin ? P

function toTimestamp(dateStr: string): Timestamp {
const date = new globalThis.Date(dateStr);
const seconds = date.getTime() / 1_000;
const seconds = Math.trunc(date.getTime() / 1_000);
const nanos = (date.getTime() % 1_000) * 1_000_000;
return { seconds, nanos };
}
Expand Down
2 changes: 1 addition & 1 deletion dashboard/apps/web/littlehorse-public-api/variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export type Exact<P, I extends P> = P extends Builtin ? P

function toTimestamp(dateStr: string): Timestamp {
const date = new globalThis.Date(dateStr);
const seconds = date.getTime() / 1_000;
const seconds = Math.trunc(date.getTime() / 1_000);
const nanos = (date.getTime() % 1_000) * 1_000_000;
return { seconds, nanos };
}
Expand Down
2 changes: 1 addition & 1 deletion dashboard/apps/web/littlehorse-public-api/wf_run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ export type Exact<P, I extends P> = P extends Builtin ? P

function toTimestamp(dateStr: string): Timestamp {
const date = new globalThis.Date(dateStr);
const seconds = date.getTime() / 1_000;
const seconds = Math.trunc(date.getTime() / 1_000);
const nanos = (date.getTime() % 1_000) * 1_000_000;
return { seconds, nanos };
}
Expand Down
2 changes: 1 addition & 1 deletion dashboard/apps/web/littlehorse-public-api/wf_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3371,7 +3371,7 @@ export type Exact<P, I extends P> = P extends Builtin ? P

function toTimestamp(dateStr: string): Timestamp {
const date = new globalThis.Date(dateStr);
const seconds = date.getTime() / 1_000;
const seconds = Math.trunc(date.getTime() / 1_000);
const nanos = (date.getTime() % 1_000) * 1_000_000;
return { seconds, nanos };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private String hostToString(LHHostInfo host) {

private RegisterTaskWorkerRequest register(String clientId) {
return RegisterTaskWorkerRequest.newBuilder()
.setClientId(clientId)
.setTaskWorkerId(clientId)
.setTaskDefId(LHLibUtil.taskDefId(taskDefName))
.setListenerName(config.getConnectListener())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private String hostToString(LHHostInfo host) {

private RegisterTaskWorkerRequest register(String clientId) {
return RegisterTaskWorkerRequest.newBuilder()
.setClientId(clientId)
.setTaskWorkerId(clientId)
.setTaskDefId(LHLibUtil.taskDefId(taskDefName))
.setListenerName(config.getConnectListener())
.build();
Expand Down
2 changes: 1 addition & 1 deletion schemas/internal/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ message LHTimerPb {
}

message TaskWorkerMetadata {
string client_id = 1;
string task_worker_id = 1;
google.protobuf.Timestamp latest_heartbeat = 2;
repeated LHHostInfo hosts = 3;
}
Expand Down
2 changes: 1 addition & 1 deletion schemas/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ message ExternalEventList {
// Used by the Task Worker SDK; generally, you shouldn't have to touch this manually.
message RegisterTaskWorkerRequest {
// Is the ID of the Task Worker.
string client_id = 1;
string task_worker_id = 1;

// The TaskDef the worker wants to poll for.
TaskDefId task_def_id = 2;
Expand Down
36 changes: 18 additions & 18 deletions sdk-go/common/lh_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const (
API_HOST_KEY = "LHC_API_HOST"
API_PORT_KEY = "LHC_API_PORT"
API_PROTOCOL_KEY = "LHC_API_PROTOCOL"
CLIENT_ID_KEY = "LHC_CLIENT_ID"

TENANT_ID = "LHC_TENANT_ID"

Expand All @@ -35,6 +34,7 @@ const (
NUM_WORKER_THREADS_KEY = "LHW_NUM_WORKER_THREADS"
TASK_WORKER_VERSION_KEY = "LHW_TASK_WORKER_VERSION"
SERVER_CONNECT_LISTENER_KEY = "LHW_SERVER_CONNECT_LISTENER"
TASK_WORKER_ID_KEY = "LHW_TASK_WORKER_ID"

OAUTH_CLIENT_ID_KEY = "LHC_OAUTH_CLIENT_ID"
OAUTH_CLIENT_SECRET_KEY = "LHC_OAUTH_CLIENT_SECRET"
Expand All @@ -54,14 +54,14 @@ const (
)

type LHConfig struct {
ApiHost string
ApiProtocol string
ApiPort string
ClientId string
CertFile *string
KeyFile *string
CaCert *string
TenantId *string
ApiHost string
ApiProtocol string
ApiPort string
TaskWorkerId string
CertFile *string
KeyFile *string
CaCert *string
TenantId *string

NumWorkerThreads int32
TaskWorkerVersion string
Expand Down Expand Up @@ -145,10 +145,10 @@ func NewConfigFromEnv() *LHConfig {
}

return &LHConfig{
ApiHost: getEnvOrDefault(API_HOST_KEY, "localhost"),
ApiProtocol: getEnvOrDefault(API_PROTOCOL_KEY, DEFAULT_PROTOCOL),
ApiPort: getEnvOrDefault(API_PORT_KEY, "2023"),
ClientId: getEnvOrDefault(CLIENT_ID_KEY, "client-"+generateRandomClientId()),
ApiHost: getEnvOrDefault(API_HOST_KEY, "localhost"),
ApiProtocol: getEnvOrDefault(API_PROTOCOL_KEY, DEFAULT_PROTOCOL),
ApiPort: getEnvOrDefault(API_PORT_KEY, "2023"),
TaskWorkerId: getEnvOrDefault(TASK_WORKER_ID_KEY, "worker-"+generateRandomWorkerId()),

CertFile: stringPtr(os.Getenv(CERT_FILE_KEY)),
KeyFile: stringPtr(os.Getenv(KEY_FILE_KEY)),
Expand Down Expand Up @@ -183,10 +183,10 @@ func NewConfigFromProps(filePath string) (*LHConfig, error) {
}

return &LHConfig{
ApiHost: p.GetString(API_HOST_KEY, "localhost"),
ApiProtocol: p.GetString(API_PROTOCOL_KEY, DEFAULT_PROTOCOL),
ApiPort: p.GetString(API_PORT_KEY, "2023"),
ClientId: p.GetString(CLIENT_ID_KEY, "client-"+generateRandomClientId()),
ApiHost: p.GetString(API_HOST_KEY, "localhost"),
ApiProtocol: p.GetString(API_PROTOCOL_KEY, DEFAULT_PROTOCOL),
ApiPort: p.GetString(API_PORT_KEY, "2023"),
TaskWorkerId: p.GetString(TASK_WORKER_ID_KEY, "worker-"+generateRandomWorkerId()),

CertFile: stringPtr(p.GetString(CERT_FILE_KEY, "")),
KeyFile: stringPtr(p.GetString(KEY_FILE_KEY, "")),
Expand Down Expand Up @@ -214,7 +214,7 @@ func NewConfigFromProps(filePath string) (*LHConfig, error) {
}, nil
}

func generateRandomClientId() string {
func generateRandomWorkerId() string {
uuid := uuid.NewString()
return strings.ReplaceAll(uuid, "-", "")
}
Expand Down
Loading

0 comments on commit 4e56bd1

Please sign in to comment.