From 603b677f790572d14d4e2fbb6b7ed7e55daefc43 Mon Sep 17 00:00:00 2001 From: Paul Wells Date: Sat, 5 Oct 2024 05:06:43 -0700 Subject: [PATCH] update agent job count type (#835) * udpate agent job count type * generated protobuf * move object slice * license * errs --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- livekit/livekit_agent.pb.go | 6 +++--- logger/objectslice.go | 34 ++++++++++++++++++++++++++++++++++ logger/proto.go | 13 +++++++++---- logger/zaputil/slice.go | 16 ---------------- protobufs/livekit_agent.proto | 4 ++-- 5 files changed, 48 insertions(+), 25 deletions(-) create mode 100644 logger/objectslice.go delete mode 100644 logger/zaputil/slice.go diff --git a/livekit/livekit_agent.pb.go b/livekit/livekit_agent.pb.go index c0b788e..9903105 100644 --- a/livekit/livekit_agent.pb.go +++ b/livekit/livekit_agent.pb.go @@ -1242,7 +1242,7 @@ type UpdateWorkerStatus struct { Status *WorkerStatus `protobuf:"varint,1,opt,name=status,proto3,enum=livekit.WorkerStatus,oneof" json:"status,omitempty"` // optional string metadata = 2 [deprecated=true]; Load float32 `protobuf:"fixed32,3,opt,name=load,proto3" json:"load,omitempty"` - JobCount int32 `protobuf:"varint,4,opt,name=job_count,json=jobCount,proto3" json:"job_count,omitempty"` + JobCount uint32 `protobuf:"varint,4,opt,name=job_count,json=jobCount,proto3" json:"job_count,omitempty"` } func (x *UpdateWorkerStatus) Reset() { @@ -1291,7 +1291,7 @@ func (x *UpdateWorkerStatus) GetLoad() float32 { return 0 } -func (x *UpdateWorkerStatus) GetJobCount() int32 { +func (x *UpdateWorkerStatus) GetJobCount() uint32 { if x != nil { return x.JobCount } @@ -1590,7 +1590,7 @@ var file_livekit_agent_proto_rawDesc = []byte{ 0x6f, 0x72, 0x6b, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x48, 0x00, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x88, 0x01, 0x01, 0x12, 0x12, 0x0a, 0x04, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x02, 0x52, 0x04, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x1b, 0x0a, 0x09, - 0x6a, 0x6f, 0x62, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x6a, 0x6f, 0x62, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6a, 0x6f, 0x62, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x64, 0x0a, 0x0d, 0x4a, 0x6f, 0x62, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x1e, 0x0a, 0x03, 0x6a, 0x6f, 0x62, 0x18, 0x01, 0x20, 0x01, diff --git a/logger/objectslice.go b/logger/objectslice.go new file mode 100644 index 0000000..cb5d903 --- /dev/null +++ b/logger/objectslice.go @@ -0,0 +1,34 @@ +// Copyright 2023 LiveKit, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package logger + +import ( + "go.uber.org/multierr" + "go.uber.org/zap/zapcore" +) + +func ObjectSlice[T zapcore.ObjectMarshaler](s []T) zapcore.ArrayMarshaler { + return objectSlice[T](s) +} + +type objectSlice[T zapcore.ObjectMarshaler] []T + +func (a objectSlice[T]) MarshalLogArray(e zapcore.ArrayEncoder) error { + var err error + for _, o := range a { + err = multierr.Append(err, e.AppendObject(o)) + } + return err +} diff --git a/logger/proto.go b/logger/proto.go index a95fa86..83b00a6 100644 --- a/logger/proto.go +++ b/logger/proto.go @@ -97,7 +97,7 @@ func (p protoListMarshaller) MarshalLogArray(e zapcore.ArrayEncoder) error { case protoreflect.BoolKind: e.AppendBool(v.Bool()) case protoreflect.EnumKind: - e.AppendInt32(int32(v.Enum())) + e.AppendString(marshalProtoEnum(p.f, v)) case protoreflect.Int32Kind, protoreflect.Int64Kind, protoreflect.Sint32Kind, protoreflect.Sint64Kind, protoreflect.Sfixed32Kind, protoreflect.Sfixed64Kind: e.AppendInt64(v.Int()) case protoreflect.Uint32Kind, protoreflect.Uint64Kind, protoreflect.Fixed32Kind, protoreflect.Fixed64Kind: @@ -122,9 +122,7 @@ func marshalProtoField(k string, f protoreflect.FieldDescriptor, v protoreflect. e.AddBool(k, b) } case protoreflect.EnumKind: - if n := v.Enum(); n != 0 { - e.AddInt32(k, int32(n)) - } + e.AddString(k, marshalProtoEnum(f, v)) case protoreflect.Int32Kind, protoreflect.Int64Kind, protoreflect.Sint32Kind, protoreflect.Sint64Kind, protoreflect.Sfixed32Kind, protoreflect.Sfixed64Kind: if n := v.Int(); n != 0 { e.AddInt64(k, n) @@ -152,6 +150,13 @@ func marshalProtoField(k string, f protoreflect.FieldDescriptor, v protoreflect. } } +func marshalProtoEnum(f protoreflect.FieldDescriptor, v protoreflect.Value) string { + if e := f.Enum().Values().ByNumber(v.Enum()); e != nil { + return string(e.Name()) + } + return fmt.Sprintf("", v.Enum()) +} + func marshalProtoBytes(b []byte) string { n := len(b) if n > 64 { diff --git a/logger/zaputil/slice.go b/logger/zaputil/slice.go deleted file mode 100644 index 388e4a6..0000000 --- a/logger/zaputil/slice.go +++ /dev/null @@ -1,16 +0,0 @@ -package zaputil - -import "go.uber.org/zap/zapcore" - -func ObjectSlice[T zapcore.ObjectMarshaler](s []T) zapcore.ArrayMarshaler { - return objectSlice[T](s) -} - -type objectSlice[T zapcore.ObjectMarshaler] []T - -func (a objectSlice[T]) MarshalLogArray(e zapcore.ArrayEncoder) error { - for _, o := range a { - e.AppendObject(o) - } - return nil -} diff --git a/protobufs/livekit_agent.proto b/protobufs/livekit_agent.proto index f55db35..e8f2c42 100644 --- a/protobufs/livekit_agent.proto +++ b/protobufs/livekit_agent.proto @@ -39,7 +39,7 @@ message JobState { int64 started_at = 3; int64 ended_at = 4; int64 updated_at = 5; - string participant_identity = 6; + string participant_identity = 6; } // from Worker to Server @@ -163,7 +163,7 @@ message UpdateWorkerStatus { optional WorkerStatus status = 1; // optional string metadata = 2 [deprecated=true]; float load = 3; - int32 job_count = 4; + uint32 job_count = 4; } message JobAssignment {