Skip to content

[supervisor] increase default workspace image cache duration and do p… #18951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions components/supervisor/pkg/supervisor/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,15 @@ type InfoService struct {
defaultWorkspaceImage string
}

var infoCacheDuration = 5 * time.Second
var infoCacheDuration = 30 * time.Second

func NewInfoService(cfg *Config, cstate ContentState, gitpodService serverapi.APIInterface) *InfoService {
svc := &InfoService{cfg: cfg, ContentState: cstate, GitpodService: gitpodService}
// it makes no sense to handle cancel here, just ignore the warning (find no way now to disable it)
ctx, _ := context.WithTimeout(context.Background(), 15*time.Second)
go svc.getDefaultWorkspaceImage(ctx)
return svc
}

// RegisterGRPC registers the gRPC info service.
func (is *InfoService) RegisterGRPC(srv *grpc.Server) {
Expand All @@ -675,11 +683,10 @@ func (is *InfoService) getDefaultWorkspaceImage(ctx context.Context) string {
is.cacheMu.RUnlock()

is.cacheMu.Lock()
defer is.cacheMu.Unlock()
defer func() {
is.cacheTimestamp = time.Now()
is.cacheMu.Unlock()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous one is ok, change it so that we don't need to consider defer order when reading the code.

}()

if time.Since(is.cacheTimestamp) < infoCacheDuration {
return is.defaultWorkspaceImage
}
Expand All @@ -691,6 +698,8 @@ func (is *InfoService) getDefaultWorkspaceImage(ctx context.Context) string {
wsImage, err := is.GitpodService.GetDefaultWorkspaceImage(ctx)
if err == nil {
is.defaultWorkspaceImage = wsImage
} else {
log.WithError(err).Error("failed to get default workspace image")
}
return is.defaultWorkspaceImage
}
Expand Down
2 changes: 1 addition & 1 deletion components/supervisor/pkg/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func Run(options ...RunOption) {
termMuxSrv,
RegistrableTokenService{Service: tokenService},
notificationService,
&InfoService{cfg: cfg, ContentState: cstate, GitpodService: gitpodService},
NewInfoService(cfg, cstate, gitpodService),
&ControlService{portsManager: portMgmt},
&portService{portsManager: portMgmt},
}
Expand Down