Skip to content

Commit eca73fd

Browse files
author
Bogdan Tsechoev
committed
Merge branch '605-idle-clone-detection' into 'dle-4-0'
fix: logs location for idle clone detection (#605) See merge request postgres-ai/database-lab!1012
2 parents 92c5579 + 8d8c4ff commit eca73fd

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

engine/internal/cloning/base.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,8 @@ func (c *Base) isIdleClone(wrapper *CloneWrapper) (bool, error) {
767767
return false, errors.New("failed to get clone session")
768768
}
769769

770-
if _, err := c.provision.LastSessionActivity(session, wrapper.Clone.Branch, wrapper.Clone.ID, minimumTime); err != nil {
770+
if _, err := c.provision.LastSessionActivity(session, wrapper.Clone.Branch, wrapper.Clone.ID, wrapper.Clone.Revision,
771+
minimumTime); err != nil {
771772
if err == pglog.ErrNotFound {
772773
log.Dbg(fmt.Sprintf("Not found recent activity for session: %q. Clone name: %q",
773774
session.ID, wrapper.Clone.ID))

engine/internal/observer/observer.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func NewObserver(dockerClient *client.Client, cfg *Config, pm *pool.Manager) *Ob
8080
// GetCloneLog gets clone logs.
8181
// TODO (akartasov): Split log to chunks.
8282
func (o *Observer) GetCloneLog(ctx context.Context, obsClone *ObservingClone) ([]byte, error) {
83-
fileSelector := pglog.NewSelector(obsClone.pool.ClonePath(obsClone.branch, obsClone.cloneID))
83+
fileSelector := pglog.NewSelector(obsClone.pool.ClonePath(obsClone.branch, obsClone.cloneID, obsClone.revision))
8484
fileSelector.SetMinimumTime(obsClone.session.StartedAt)
8585

8686
if err := fileSelector.DiscoverLogDir(); err != nil {
@@ -187,12 +187,13 @@ func (o *Observer) maskLogs(entry []string, maskedFieldIndexes []int) {
187187
}
188188

189189
// AddObservingClone adds a new observing session to storage.
190-
func (o *Observer) AddObservingClone(cloneID, branch string, port uint, session *ObservingClone) {
190+
func (o *Observer) AddObservingClone(cloneID, branch string, revision int, port uint, session *ObservingClone) {
191191
o.sessionMu.Lock()
192192
defer o.sessionMu.Unlock()
193193
session.pool = o.pm.First().Pool()
194194
session.cloneID = cloneID
195195
session.branch = branch
196+
session.revision = revision
196197
session.port = port
197198

198199
o.storage[cloneID] = session

engine/internal/observer/observing_clone.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type ObservingClone struct {
4444
pool *resources.Pool
4545
cloneID string
4646
branch string
47+
revision int
4748
port uint
4849
superUserDB *pgx.Conn
4950

@@ -480,7 +481,7 @@ func (c *ObservingClone) currentArtifactsSessionPath() string {
480481
}
481482

482483
func (c *ObservingClone) artifactsSessionPath(sessionID uint64) string {
483-
return path.Join(c.pool.ObserverDir(c.branch, c.cloneID), c.cloneID, strconv.FormatUint(sessionID, 10))
484+
return path.Join(c.pool.ObserverDir(c.branch, c.cloneID, c.revision), c.cloneID, strconv.FormatUint(sessionID, 10))
484485
}
485486

486487
// CheckPerformanceRequirements checks monitoring data and returns an error if any of performance requires was not satisfied.

engine/internal/provision/mode_local.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,8 @@ func (p *Provisioner) getProvisionHosts() string {
660660
}
661661

662662
// LastSessionActivity returns the time of the last session activity.
663-
func (p *Provisioner) LastSessionActivity(session *resources.Session, branch, cloneID string, minimumTime time.Time) (*time.Time, error) {
663+
func (p *Provisioner) LastSessionActivity(session *resources.Session, branch, cloneID string, revision int,
664+
minimumTime time.Time) (*time.Time, error) {
664665
fsm, err := p.pm.GetFSManager(session.Pool)
665666
if err != nil {
666667
return nil, errors.Wrap(err, "failed to find filesystem manager")
@@ -669,7 +670,7 @@ func (p *Provisioner) LastSessionActivity(session *resources.Session, branch, cl
669670
ctx, cancel := context.WithCancel(p.ctx)
670671
defer cancel()
671672

672-
clonePath := fsm.Pool().ClonePath(branch, cloneID)
673+
clonePath := fsm.Pool().ClonePath(branch, cloneID, revision)
673674
fileSelector := pglog.NewSelector(clonePath)
674675

675676
if err := fileSelector.DiscoverLogDir(); err != nil {

engine/internal/provision/resources/pool.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ func (p *Pool) SocketDir() string {
6565
}
6666

6767
// ObserverDir returns a path to the observer directory of the storage pool.
68-
func (p *Pool) ObserverDir(branch, name string) string {
69-
return path.Join(p.ClonePath(branch, name), p.ObserverSubDir)
68+
func (p *Pool) ObserverDir(branch, name string, revision int) string {
69+
return path.Join(p.ClonePath(branch, name, revision), p.ObserverSubDir)
7070
}
7171

7272
// ClonesDir returns a path to the clones directory of the storage pool.
@@ -75,8 +75,8 @@ func (p *Pool) ClonesDir(branch string) string {
7575
}
7676

7777
// ClonePath returns a path to the data clone directory.
78-
func (p *Pool) ClonePath(branchName, name string) string {
79-
return path.Join(p.MountDir, p.PoolDirName, branching.BranchDir, branchName, name, p.DataSubDir)
78+
func (p *Pool) ClonePath(branchName, name string, revision int) string {
79+
return path.Join(p.MountDir, p.PoolDirName, branching.BranchDir, branchName, name, branching.RevisionSegment(revision), p.DataSubDir)
8080
}
8181

8282
// CloneLocation returns a path to the initialized clone directory.

engine/internal/srv/routes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ func (s *Server) startObservation(w http.ResponseWriter, r *http.Request) {
743743
return
744744
}
745745

746-
s.Observer.AddObservingClone(clone.ID, clone.Branch, uint(port), observingClone)
746+
s.Observer.AddObservingClone(clone.ID, clone.Branch, clone.Revision, uint(port), observingClone)
747747

748748
// Start session on the Platform.
749749
platformRequest := platform.StartObservationRequest{

0 commit comments

Comments
 (0)