Skip to content

Commit 889a9de

Browse files
tturkowskishyim
andauthored
Measure duration time from start till end of setup guide (#1135)
* Measure duration time from start till end of setup guide * feat(setup): track PHP version along with duration in setup guide completion * feat(setup): update tracking duration format to seconds in setup guide completion --------- Co-authored-by: Soner Sayakci <s.sayakci@gmail.com>
1 parent 57ace64 commit 889a9de

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

internal/devtui/model_update.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package devtui
22

33
import (
44
"context"
5+
"strconv"
56
"time"
67

78
"charm.land/bubbles/v2/textinput"
@@ -11,6 +12,7 @@ import (
1112
"github.com/shopware/shopware-cli/internal/envfile"
1213
"github.com/shopware/shopware-cli/internal/executor"
1314
"github.com/shopware/shopware-cli/internal/shop"
15+
"github.com/shopware/shopware-cli/internal/tracking"
1416
)
1517

1618
func (m Model) updateKeyPress(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
@@ -266,7 +268,17 @@ func (m Model) saveSetupGuide() (tea.Model, tea.Cmd) {
266268
m.setupGuide.deploymentHelperAdded = changed
267269

268270
m.setupGuide.step = setupStepDone
269-
return m, nil
271+
duration := time.Since(m.setupGuide.startedAt)
272+
phpVersion := m.setupGuide.phpVersions[m.setupGuide.phpCursor]
273+
return m, func() tea.Msg {
274+
ctx, cancel := context.WithTimeout(context.Background(), 300*time.Millisecond)
275+
defer cancel()
276+
tracking.Track(ctx, "migration_wizard_completed", map[string]string{
277+
"took": strconv.FormatInt(int64(duration.Seconds()), 10),
278+
"php_version": phpVersion,
279+
})
280+
return nil
281+
}
270282
}
271283

272284
// mergeLocalProfilerSecrets copies profiler credential fields from the

internal/devtui/setup_guide.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package devtui
33
import (
44
"path/filepath"
55
"slices"
6+
"time"
67

78
"charm.land/bubbles/v2/textinput"
89
tea "charm.land/bubbletea/v2"
@@ -31,6 +32,7 @@ type setupGuide struct {
3132
password textinput.Model
3233
passwordErr string
3334
credFocus credFocus
35+
startedAt time.Time
3436

3537
err error
3638
}
@@ -149,6 +151,7 @@ func (sg *setupGuide) updateWelcome(msg tea.KeyPressMsg) (setupGuide, tea.Cmd) {
149151
sg.confirmYes = !sg.confirmYes
150152
case keyEnter:
151153
if sg.confirmYes {
154+
sg.startedAt = time.Now()
152155
sg.step = setupStepAdminUser
153156
return sg.focusAdminCred(credFocusUsername)
154157
}

internal/devtui/setup_guide_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"os"
55
"path/filepath"
66
"testing"
7+
"time"
78

89
"charm.land/bubbles/v2/textinput"
910
tea "charm.land/bubbletea/v2"
@@ -407,3 +408,16 @@ func TestSetupGuideStepNumbering(t *testing.T) {
407408
assert.Equal(t, 0, sg.stepNum(setupStepWelcome))
408409
assert.Equal(t, 0, sg.stepNum(setupStepDone))
409410
}
411+
412+
func TestSetupGuideWelcome_EnterSetsStartedAt(t *testing.T) {
413+
sg := newSetupGuide("")
414+
sg.confirmYes = true
415+
416+
before := time.Now()
417+
next, _ := sg.update(tea.KeyPressMsg(tea.Key{Code: tea.KeyEnter}))
418+
after := time.Now()
419+
420+
assert.False(t, next.startedAt.IsZero(), "startedAt should be set after Enter on welcome")
421+
assert.False(t, next.startedAt.Before(before), "startedAt should not be before test start")
422+
assert.False(t, next.startedAt.After(after), "startedAt should not be after test end")
423+
}

0 commit comments

Comments
 (0)