Skip to content

Commit

Permalink
update agent job count type (#835)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
paulwe and github-actions[bot] authored Oct 5, 2024
1 parent 8fd1f55 commit 603b677
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 25 deletions.
6 changes: 3 additions & 3 deletions livekit/livekit_agent.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions logger/objectslice.go
Original file line number Diff line number Diff line change
@@ -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
}
13 changes: 9 additions & 4 deletions logger/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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("<UNDEFINED(%d)>", v.Enum())
}

func marshalProtoBytes(b []byte) string {
n := len(b)
if n > 64 {
Expand Down
16 changes: 0 additions & 16 deletions logger/zaputil/slice.go

This file was deleted.

4 changes: 2 additions & 2 deletions protobufs/livekit_agent.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 603b677

Please sign in to comment.