Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdecde5c

Browse files
committed
Fix agent queue with loads of logs
1 parent379f1f4 commitdecde5c

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

‎agent/agent.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,13 @@ func (a *agent) runScript(ctx context.Context, lifecycle, script string) error {
666666
varflushLogsTimer*time.Timer
667667
varlogMutex sync.Mutex
668668
varlogsSendingbool
669+
deferfunc() {
670+
logMutex.Lock()
671+
ifflushLogsTimer!=nil {
672+
flushLogsTimer.Stop()
673+
}
674+
logMutex.Unlock()
675+
}()
669676

670677
// sendLogs function uploads the queued logs to the server
671678
sendLogs:=func() {
@@ -708,6 +715,7 @@ func (a *agent) runScript(ctx context.Context, lifecycle, script string) error {
708715
// Reset logsSending flag
709716
logMutex.Lock()
710717
logsSending=false
718+
flushLogsTimer.Reset(100*time.Millisecond)
711719
logMutex.Unlock()
712720
}
713721
// queueLog function appends a log to the queue and triggers sendLogs if necessary
@@ -720,8 +728,10 @@ func (a *agent) runScript(ctx context.Context, lifecycle, script string) error {
720728

721729
// If there are more than 100 logs, send them immediately
722730
iflen(queuedLogs)>100 {
731+
// Don't early return after this, because we still want
732+
// to reset the timer just in case logs come in while
733+
// we're sending.
723734
gosendLogs()
724-
return
725735
}
726736
// Reset or set the flushLogsTimer to trigger sendLogs after 100 milliseconds
727737
ifflushLogsTimer!=nil {

‎cli/agent.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ func workspaceAgent() *cobra.Command {
117117
client:=agentsdk.New(coderURL)
118118
client.SDK.Logger=logger
119119
// Set a reasonable timeout so requests can't hang forever!
120-
client.SDK.HTTPClient.Timeout=10*time.Second
120+
// The timeout needs to be reasonably long, because requests
121+
// with large payloads can take a bit. e.g. startup scripts
122+
// may take a while to insert.
123+
client.SDK.HTTPClient.Timeout=30*time.Second
121124

122125
// Enable pprof handler
123126
// This prevents the pprof import from being accidentally deleted.

‎site/src/components/Resources/AgentRow.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,17 @@ export const AgentRow: FC<AgentRowProps> = ({
9797
returnlogs
9898
},[logsMachine.context.startupLogs,agent.startup_logs_overflowed])
9999
const[bottomOfLogs,setBottomOfLogs]=useState(true)
100+
// This is a layout effect to remove flicker when we're scrolling to the bottom.
100101
useLayoutEffect(()=>{
102+
// If we're currently watching the bottom, we always want to stay at the bottom.
101103
if(bottomOfLogs&&logListRef.current){
102104
logListRef.current.scrollToItem(startupLogs.length-1,"end")
103105
}
104106
},[showStartupLogs,startupLogs,logListRef,bottomOfLogs])
107+
108+
// This is a bit of a hack on the react-window API to get the scroll position.
109+
// If we're scrolled to the bottom, we want to keep the list scrolled to the bottom.
110+
// This makes it feel similar to a terminal that auto-scrolls downwards!
105111
consthandleLogScroll=useCallback(
106112
(props:ListOnScrollProps)=>{
107113
if(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp