Skip to content

Commit 4f432a6

Browse files
feat: add participant attributes for agent load test (#757)
1 parent 8f12b43 commit 4f432a6

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ lk perf agent-load-test \
425425
--agent-name test-agent \
426426
--echo-speech-delay 10s \
427427
--duration 5m
428+
--attribute key1=value1
428429
```
429430

430431
The above simulates 5 concurrent rooms, where each room has:

cmd/lk/perf.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ package main
22

33
import (
44
"context"
5+
"encoding/json"
56
"log"
7+
"maps"
8+
"os"
69
"time"
710

811
"github.com/go-logr/logr"
@@ -107,6 +110,15 @@ var (
107110
Usage: "`TIME` duration to run, 1m, 1h (by default will run until canceled)",
108111
Value: 0,
109112
},
113+
&cli.StringSliceFlag{
114+
Name: "attribute",
115+
Usage: "set attributes in key=value format, can be used multiple times",
116+
},
117+
&cli.StringFlag{
118+
Name: "attribute-file",
119+
Usage: "read attributes from a `JSON` file",
120+
TakesFile: true,
121+
},
110122
},
111123
},
112124
},
@@ -236,6 +248,33 @@ func agentLoadTest(ctx context.Context, cmd *cli.Command) error {
236248
}
237249
_ = raiseULimit()
238250

251+
participantAttributes, err := parseKeyValuePairs(cmd, "attribute")
252+
if err != nil {
253+
log.Printf("failed to parse participant attributes: %v", err)
254+
return err
255+
}
256+
257+
// Read attributes from JSON file if specified
258+
if attrFile := cmd.String("attribute-file"); attrFile != "" {
259+
fileData, err := os.ReadFile(attrFile)
260+
if err != nil {
261+
log.Printf("failed to read attribute file: %v", err)
262+
return err
263+
}
264+
265+
var fileAttrs map[string]string
266+
if err := json.Unmarshal(fileData, &fileAttrs); err != nil {
267+
log.Printf("failed to parse attribute file as JSON: %v", err)
268+
return err
269+
}
270+
271+
// Add attributes from file to the existing ones
272+
if participantAttributes == nil {
273+
participantAttributes = make(map[string]string)
274+
}
275+
maps.Copy(participantAttributes, fileAttrs)
276+
}
277+
239278
params := loadtester.AgentLoadTestParams{
240279
URL: pc.URL,
241280
APIKey: pc.APIKey,
@@ -244,6 +283,7 @@ func agentLoadTest(ctx context.Context, cmd *cli.Command) error {
244283
AgentName: cmd.String("agent-name"),
245284
EchoSpeechDelay: cmd.Duration("echo-speech-delay"),
246285
Duration: cmd.Duration("duration"),
286+
ParticipantAttributes: participantAttributes,
247287
}
248288

249289
test := loadtester.NewAgentLoadTest(params)

pkg/loadtester/agentloadtest.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type AgentLoadTestParams struct {
2828
URL string
2929
APIKey string
3030
APISecret string
31+
ParticipantAttributes map[string]string
3132
}
3233

3334
type AgentLoadTest struct {

pkg/loadtester/agentloadtester.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ func (r *LoadTestRoom) start(roomName string) error {
176176
APISecret: r.params.APISecret,
177177
RoomName: roomName,
178178
ParticipantIdentity: identity,
179+
ParticipantAttributes: r.params.ParticipantAttributes,
179180
})
180181
if err == nil {
181182
break

0 commit comments

Comments
 (0)