Skip to content

Commit

Permalink
fix(daemon) add time saved metric to Go daemon (#5148)
Browse files Browse the repository at this point in the history
### Description

A port of the changes to the Rust daemon in #4952

### Testing Instructions

Followed same testing protocol as described in initial PR.

Co-authored-by: Chris Olszewski <Chris Olszewski>
  • Loading branch information
chris-olszewski authored May 31, 2023
1 parent e8b81cb commit ab89e56
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cli/internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type Server struct {
repoRoot turbopath.AbsoluteSystemPath
closerMu sync.Mutex
closer *closer
timeSavedMu sync.Mutex
timesSaved map[string]uint64
}

// GRPCServer is the interface that the turbo server needs to the underlying
Expand Down Expand Up @@ -82,6 +84,7 @@ func New(serverName string, logger hclog.Logger, repoRoot turbopath.AbsoluteSyst
started: time.Now(),
logFilePath: logFilePath,
repoRoot: repoRoot,
timesSaved: map[string]uint64{},
}
server.watcher.AddClient(cookieJar)
server.watcher.AddClient(globWatcher)
Expand Down Expand Up @@ -137,6 +140,9 @@ func (s *Server) Register(grpcServer GRPCServer) {

// NotifyOutputsWritten implements the NotifyOutputsWritten rpc from turbo.proto
func (s *Server) NotifyOutputsWritten(ctx context.Context, req *turbodprotocol.NotifyOutputsWrittenRequest) (*turbodprotocol.NotifyOutputsWrittenResponse, error) {
s.timeSavedMu.Lock()
s.timesSaved[req.Hash] = req.TimeSaved
s.timeSavedMu.Unlock()
outputs := fs.TaskOutputs{
Inclusions: req.OutputGlobs,
Exclusions: req.OutputExclusionGlobs,
Expand All @@ -151,13 +157,17 @@ func (s *Server) NotifyOutputsWritten(ctx context.Context, req *turbodprotocol.N

// GetChangedOutputs implements the GetChangedOutputs rpc from turbo.proto
func (s *Server) GetChangedOutputs(ctx context.Context, req *turbodprotocol.GetChangedOutputsRequest) (*turbodprotocol.GetChangedOutputsResponse, error) {
s.timeSavedMu.Lock()
timeSaved := s.timesSaved[req.Hash]
s.timeSavedMu.Unlock()

changedGlobs, err := s.globWatcher.GetChangedGlobs(req.Hash, req.OutputGlobs)
if err != nil {
return nil, err
}
return &turbodprotocol.GetChangedOutputsResponse{
ChangedOutputGlobs: changedGlobs,
TimeSaved: timeSaved,
}, nil
}

Expand Down

0 comments on commit ab89e56

Please sign in to comment.