@@ -117,7 +117,7 @@ func NewRouter(appContext *Context, partitionSelector kafkabase.PartitionSelecto
117117 })
118118
119119 httpClient := & http.Client {
120- Timeout : time .Duration (appContext .config .DeviceFunctionsTimeoutMs ) * time .Millisecond ,
120+ Timeout : time .Duration (int64 ( float64 ( appContext .config .DeviceFunctionsTimeoutMs ) * 1.1 ) ) * time .Millisecond ,
121121 }
122122
123123 var dataHosts []string
@@ -494,7 +494,7 @@ func (r *Router) processSyncDestination(message *IngestMessage, stream *StreamWi
494494 // Use functions server (new format with execLog)
495495 fsURL := getFunctionsServerURL (r .config .FunctionsServerURLTemplate , stream .Stream .WorkspaceId , classes )
496496 endpointURL := fsURL + "/multi"
497- r .callFunctionsEndpoint (functionDestinations , endpointURL , messageBytes , functionsResults )
497+ r .callFunctionsEndpoint (stream , functionDestinations , endpointURL , messageBytes , functionsResults )
498498 } else {
499499 // Use rotor (legacy format)
500500 endpointURL := r .config .RotorURL + "/func/multi"
@@ -606,19 +606,23 @@ type ConnectionChainResult struct {
606606
607607// callFunctionsEndpoint sends a request to functions endpoint and expects new format with execLog
608608// Response format: map[connectionId]{ events: [], execLog: [] }
609- func (r * Router ) callFunctionsEndpoint (destinations []* ShortDestinationConfig , baseURL string , messageBytes []byte , functionsResults map [string ]any ) {
609+ func (r * Router ) callFunctionsEndpoint (stream * StreamWithDestinations , destinations []* ShortDestinationConfig , baseURL string , messageBytes []byte , functionsResults map [string ]any ) {
610610 if len (destinations ) == 0 {
611611 return
612612 }
613613
614614 ids := utils .ArrayMap (destinations , func (d * ShortDestinationConfig ) string { return d .ConnectionId })
615615 var err error
616616 defer func () {
617- for _ , id := range ids {
618- if err != nil {
617+ if err != nil {
618+ obj := map [string ]any {"body" : string (messageBytes ), "error" : "Functions server " , "status" : "FS_ERROR" }
619+ r .eventsLogService .PostAsync (& eventslog.ActorEvent {EventType : eventslog .EventTypeIncoming , Level : eventslog .LevelError , ActorId : stream .Stream .Id , Event : obj })
620+ for _ , id := range ids {
619621 DeviceFunctions (id , "error" ).Inc ()
620622 DeviceFunctions ("total" , "error" ).Inc ()
621- } else {
623+ }
624+ } else {
625+ for _ , id := range ids {
622626 DeviceFunctions (id , "success" ).Inc ()
623627 DeviceFunctions ("total" , "success" ).Inc ()
624628 }
@@ -641,19 +645,22 @@ func (r *Router) callFunctionsEndpoint(destinations []*ShortDestinationConfig, b
641645 res , err := r .httpClient .Do (req )
642646 if err != nil {
643647 r .Errorf ("failed to send functions request for connections: %s: %v" , ids , err )
648+ err = fmt .Errorf ("functions request error: %v" , err )
644649 return
645650 }
646651 defer res .Body .Close ()
647652
648653 body , err := io .ReadAll (res .Body )
649654 if res .StatusCode != 200 || err != nil {
650655 r .Errorf ("Failed to send functions request for connections: %s: status: %v body: %s" , ids , res .StatusCode , string (body ))
656+ err = fmt .Errorf ("functions response error: status %d err: %v" , res .StatusCode , err )
651657 return
652658 }
653659 var result map [string ]ConnectionChainResult
654660 err = jsoniter .Unmarshal (body , & result )
655661 if err != nil {
656662 r .Errorf ("Failed to unmarshal functions response for connections: %s: %v" , ids , err )
663+ err = fmt .Errorf ("functions response error: %v" , err )
657664 return
658665 }
659666
0 commit comments