@@ -2,7 +2,10 @@ package main
22
33import (
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 )
0 commit comments