Skip to content

Commit 641bae4

Browse files
add recording store request header (livekit#1197)
* add recording store request header * generated protobuf * wip * tidy * generated protobuf --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent b89809f commit 641bae4

File tree

5 files changed

+130
-22
lines changed

5 files changed

+130
-22
lines changed

auth/grants.go

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,14 @@ func checkOutputForCredentials(output any) error {
162162
}
163163

164164
type ClaimGrants struct {
165-
Identity string `json:"identity,omitempty"`
166-
Name string `json:"name,omitempty"`
167-
Kind string `json:"kind,omitempty"`
168-
Video *VideoGrant `json:"video,omitempty"`
169-
SIP *SIPGrant `json:"sip,omitempty"`
170-
Agent *AgentGrant `json:"agent,omitempty"`
171-
Inference *InferenceGrant `json:"inference,omitempty"`
165+
Identity string `json:"identity,omitempty"`
166+
Name string `json:"name,omitempty"`
167+
Kind string `json:"kind,omitempty"`
168+
Video *VideoGrant `json:"video,omitempty"`
169+
SIP *SIPGrant `json:"sip,omitempty"`
170+
Agent *AgentGrant `json:"agent,omitempty"`
171+
Inference *InferenceGrant `json:"inference,omitempty"`
172+
Observability *ObservabilityGrant `json:"observability,omitempty"`
172173
// Room configuration to use if this participant initiates the room
173174
RoomConfig *RoomConfiguration `json:"roomConfig,omitempty"`
174175
// Cloud-only, config preset to use
@@ -206,6 +207,7 @@ func (c *ClaimGrants) Clone() *ClaimGrants {
206207
clone.SIP = c.SIP.Clone()
207208
clone.Agent = c.Agent.Clone()
208209
clone.Inference = c.Inference.Clone()
210+
clone.Observability = c.Observability.Clone()
209211
clone.Attributes = maps.Clone(c.Attributes)
210212
clone.RoomConfig = c.RoomConfig.Clone()
211213

@@ -223,6 +225,7 @@ func (c *ClaimGrants) MarshalLogObject(e zapcore.ObjectEncoder) error {
223225
e.AddObject("SIP", c.SIP)
224226
e.AddObject("Agent", c.Agent)
225227
e.AddObject("Inference", c.Inference)
228+
e.AddObject("Observability", c.Observability)
226229
e.AddObject("RoomConfig", logger.Proto((*livekit.RoomConfiguration)(c.RoomConfig)))
227230
e.AddString("RoomPreset", c.RoomPreset)
228231
return nil
@@ -560,7 +563,7 @@ func (s *AgentGrant) MarshalLogObject(e zapcore.ObjectEncoder) error {
560563
// ------------------------------------------------------------------
561564

562565
type InferenceGrant struct {
563-
// Admin grants to all inference features (LLM, STT, TTS)
566+
// Perform grants to all inference features (LLM, STT, TTS)
564567
Perform bool `json:"perform,omitempty"`
565568
}
566569

@@ -585,6 +588,32 @@ func (s *InferenceGrant) MarshalLogObject(e zapcore.ObjectEncoder) error {
585588

586589
// ------------------------------------------------------------------
587590

591+
type ObservabilityGrant struct {
592+
// Write grants to publish observability data
593+
Write bool `json:"write,omitempty"`
594+
}
595+
596+
func (s *ObservabilityGrant) Clone() *ObservabilityGrant {
597+
if s == nil {
598+
return nil
599+
}
600+
601+
clone := *s
602+
603+
return &clone
604+
}
605+
606+
func (s *ObservabilityGrant) MarshalLogObject(e zapcore.ObjectEncoder) error {
607+
if s == nil {
608+
return nil
609+
}
610+
611+
e.AddBool("Write", s.Write)
612+
return nil
613+
}
614+
615+
// ------------------------------------------------------------------
616+
588617
func sourceToString(source livekit.TrackSource) string {
589618
return strings.ToLower(source.String())
590619
}

livekit/livekit_metrics.pb.go

Lines changed: 71 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protobufs/livekit_metrics.proto

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ message MetricsBatch {
5353
// This is useful for storing participant identities, track names, etc.
5454
// There is also a predefined list of labels that can be used to reference common metrics.
5555
// They have reserved indices from 0 to (METRIC_LABEL_PREDEFINED_MAX_VALUE - 1).
56-
// Indexes pointing at str_data should start from METRIC_LABEL_PREDEFINED_MAX_VALUE,
56+
// Indexes pointing at str_data should start from METRIC_LABEL_PREDEFINED_MAX_VALUE,
5757
// such that str_data[0] == index of METRIC_LABEL_PREDEFINED_MAX_VALUE.
5858
repeated string str_data = 3;
5959
repeated TimeSeriesMetric time_series = 4;
@@ -87,3 +87,8 @@ message EventMetric {
8787
string metadata = 8;
8888
uint32 rid = 9; // index into 'str_data'
8989
}
90+
91+
message MetricsRecordingHeader {
92+
string room_id = 1;
93+
optional bool enable_user_data_training = 2;
94+
}

utils/guid/id.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
mrand "math/rand/v2"
2323
"os"
24+
"regexp"
2425
"sync"
2526
"unsafe"
2627

@@ -199,3 +200,9 @@ func Unmarshal[T livekit.Guid](b livekit.GuidBlock) T {
199200
}
200201
return T(unsafe.String(unsafe.SliceData(id), len(id)))
201202
}
203+
204+
var validIDPattern = regexp.MustCompile(`^([a-zA-Z0-9]{1,16}_){1,2}[a-zA-Z0-9]{0,12}$`)
205+
206+
func IsValidID[T ~string](id T) bool {
207+
return validIDPattern.MatchString(string(id))
208+
}

utils/guid/id_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,12 @@ func BenchmarkNew(b *testing.B) {
5555
_ = guid
5656
})
5757
}
58+
59+
func TestIsValidID(t *testing.T) {
60+
require.True(t, IsValidID("A_SFo4igEG5Dg5"))
61+
require.True(t, IsValidID("NM_OJOHANNESBURG1A_K6SMQw2ZCZyB"))
62+
require.False(t, IsValidID("A_A_A_SFo4igEG5Dg5"))
63+
require.False(t, IsValidID("_A_SFo4igEG5Dg5"))
64+
require.False(t, IsValidID("_SFo4igEG5Dg5"))
65+
require.False(t, IsValidID("SFo4igEG5Dg5"))
66+
}

0 commit comments

Comments
 (0)