Skip to content

Commit 49245ca

Browse files
Added upgrade events to reporter (#224)
* Added upgrade events * fix * Added abrupt cancellation * Changed event name * Added support for more events * bump * small fix * report finish
1 parent ecc4159 commit 49245ca

File tree

7 files changed

+307
-140
lines changed

7 files changed

+307
-140
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.206
1+
VERSION=v0.0.207
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/runtime.go

Lines changed: 204 additions & 103 deletions
Large diffs are not rendered by default.

cmd/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ func main() {
4242
// configure autopilot logger
4343
apu.ConfigureLoggerOrDie(c)
4444

45-
if err := c.ExecuteContext(ctx); err != nil {
46-
reporter.G().Close()
45+
err := c.ExecuteContext(ctx)
46+
reporter.G().Close("", err)
47+
if err != nil {
4748
log.G(ctx).Fatal(err)
4849
}
4950
}

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cf version
2323

2424
```bash
2525
# download and extract the binary
26-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.206/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.207/cf-linux-amd64.tar.gz | tar zx
2727

2828
# move the binary to your $PATH
2929
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -36,7 +36,7 @@ cf version
3636

3737
```bash
3838
# download and extract the binary
39-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.206/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.207/cf-darwin-amd64.tar.gz | tar zx
4040

4141
# move the binary to your $PATH
4242
mv ./cf-darwin-amd64 /usr/local/bin/cf

manifests/runtime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: '{{ namespace }}'
66
spec:
77
defVersion: 1.0.0
8-
version: 0.0.206
8+
version: 0.0.207
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

pkg/reporter/reporter.go

Lines changed: 85 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var ar AnalyticsReporter = &noopAnalyticsReporter{}
2727
type (
2828
AnalyticsReporter interface {
2929
ReportStep(CliStepData)
30-
Close()
30+
Close(step CliStepStatus, err error)
3131
}
3232

3333
CliStepData struct {
@@ -55,38 +55,83 @@ type (
5555
)
5656

5757
const (
58-
cliEvent string = "cli-runtime-operations"
58+
cliEvent string = "csdp-cli"
5959

6060
// Install
61-
InstallStepPreChecks CliStep = "install.pre-installation-checks"
62-
InstallStepDownloadRuntimeDefinitions CliStep = "install.download-runtime-definitions"
63-
InstallStepGetServerAddress CliStep = "install.get-server-address"
64-
InstallStepCreateRuntimeOnPlatform CliStep = "install.create-runtime-on-platform"
65-
InstallStepBootstrapRepo CliStep = "install.bootstrap-repo"
66-
InstallStepCreateProject CliStep = "install.create-project"
67-
InstallStepCreateConfigMap CliStep = "install.create-codefresh-cm"
68-
InstallStepCreateComponent CliStep = "install.create-component"
69-
InstallStepInstallComponenets CliStep = "install.install-components"
70-
InstallStepCreateGitsource CliStep = "install.create-gitsource"
71-
InstallStepCreateMarketplaceGitsource CliStep = "install.create-marketplace-gitsource"
72-
InstallStepCompleteRuntimeInstallation CliStep = "install.complete-runtime-installation"
73-
InstallStepCreateDefaultGitIntegration CliStep = "install.create-default-git-integration"
61+
InstallPhasePreCheckStart CliStep = "install.pre-check.phase.start"
62+
InstallStepPreCheckValidateRuntimeVersion CliStep = "install.pre-check.step.validate-runtime-version"
63+
InstallStepPreCheckGetRuntimeName CliStep = "install.pre-check.step.get-runtime-name"
64+
InstallStepPreCheckRuntimeNameValidation CliStep = "install.pre-check.step.runtime-name-validation"
65+
InstallStepPreCheckGetKubeContext CliStep = "install.pre-check.step.get-kube-context"
66+
InstallStepPreCheckEnsureRuntimeRepo CliStep = "install.pre-check.step.ensure-runtime-repo"
67+
InstallStepPreCheckEnsureGitToken CliStep = "install.pre-check.step.ensure-git-token"
68+
InstallStepPreCheckEnsureIngressHost CliStep = "install.pre-check.step.ensure-ingress-host"
69+
InstallStepPreCheckShouldInstallDemoResources CliStep = "install.pre-check.step.should-install-demo-resources"
70+
InstallPhasePreCheckFinish CliStep = "install.pre-check.phase.finish"
71+
InstallPhaseRunPreCheckStart CliStep = "install.run.pre-check.phase.start"
72+
InstallStepRunPreCheckDownloadRuntimeDefinition CliStep = "install.run.pre-check.step.download-runtime-definition"
73+
InstallStepRunPreCheckEnsureCliVersion CliStep = "install.run.pre-check.step.ensure-cli-version"
74+
InstallStepRunPreCheckRuntimeCollision CliStep = "install.run.pre-check.step.runtime-collision"
75+
InstallStepRunPreCheckExisitingRuntimes CliStep = "install.run.pre-check.step.existing-runtimes"
76+
InstallStepRunPreCheckValidateClusterRequirements CliStep = "install.run.pre-check.step.validate-cluster-requirements"
77+
InstallPhaseRunPreCheckFinish CliStep = "install.run.pre-check.phase.finish"
78+
InstallPhaseStart CliStep = "install.run.phase.start"
79+
InstallStepDownloadRuntimeDefinition CliStep = "install.run.step.download-runtime-definition"
80+
InstallStepGetServerAddress CliStep = "install.run.step.get-server-address"
81+
InstallStepCreateRuntimeOnPlatform CliStep = "install.run.step.create-runtime-on-platform"
82+
InstallStepBootstrapRepo CliStep = "install.run.step.bootstrap-repo"
83+
InstallStepCreateProject CliStep = "install.run.step.create-project"
84+
InstallStepCreateConfigMap CliStep = "install.run.step.create-codefresh-cm"
85+
InstallStepCreateComponent CliStep = "install.run.step.create-component"
86+
InstallStepInstallComponenets CliStep = "install.run.step.install-components"
87+
InstallStepCreateGitsource CliStep = "install.run.step.create-gitsource"
88+
InstallStepCreateMarketplaceGitsource CliStep = "install.run.step.create-marketplace-gitsource"
89+
InstallStepCompleteRuntimeInstallation CliStep = "install.run.step.complete-runtime-installation"
90+
InstallStepCreateDefaultGitIntegration CliStep = "install.run.step.create-default-git-integration"
91+
InstallPhaseFinish CliStep = "install.run.phase.finish"
7492

7593
// Uninstall
76-
UninstallStepCheckRuntimeExists CliStep = "uninstall.check-runtime-exists"
77-
UninstallStepUninstallRepo CliStep = "uninstall.uninstall-repo"
78-
UninstallStepDeleteRuntimeFromPlatform CliStep = "uninstall.delete-runtime-from-platform"
79-
UninstallStepCompleteRuntimeUninstallation CliStep = "uninstall.complete-runtime-uninstall"
94+
UninstallPhasePreCheckStart CliStep = "uninstall.pre-check.phase.start"
95+
UninstallStepPreCheckGetKubeContext CliStep = "uninstall.pre-check.step.get-kube-context"
96+
UninstallStepPreCheckEnsureRuntimeName CliStep = "uninstall.pre-check.step.ensure-runtime-name"
97+
UninstallStepPreCheckRuntimeNameValidation CliStep = "uninstall.pre-check.step.runtime-name-validation"
98+
UninstallStepPreCheckEnsureRuntimeRepo CliStep = "uninstall.pre-check.step.ensure-runtime-repo"
99+
UninstallStepPreCheckEnsureGitToken CliStep = "uninstall.pre-check.step.ensure-git-token"
100+
UninstallPhasePreCheckFinish CliStep = "uninstall.pre-check.phase.finish"
101+
UninstallPhaseStart CliStep = "uninstall.run.phase.start"
102+
UninstallStepCheckRuntimeExists CliStep = "uninstall.run.step.check-runtime-exists"
103+
UninstallStepUninstallRepo CliStep = "uninstall.run.step.uninstall-repo"
104+
UninstallStepDeleteRuntimeFromPlatform CliStep = "uninstall.run.step.delete-runtime-from-platform"
105+
UninstallPhaseFinish CliStep = "uninstall.run.phase.finish"
106+
107+
// Upgrade
108+
UpgradePhasePreCheckStart CliStep = "upgrade.pre-check.phase.start"
109+
UpgradeStepPreCheckEnsureRuntimeName CliStep = "upgrade.pre-check.step.ensure-runtime-name"
110+
UpgradeStepPreCheckEnsureRuntimeRepo CliStep = "upgrade.pre-check.step.ensure-runtime-repo"
111+
UpgradeStepPreCheckEnsureGitToken CliStep = "upgrade.pre-check.step.ensure-git-token"
112+
UpgradePhasePreCheckFinish CliStep = "upgrade.pre-check.phase.finish"
113+
UpgradePhaseStart CliStep = "upgrade.run.phase.start"
114+
UpgradeStepDownloadRuntimeDefinition CliStep = "upgrade.run.step.download-runtime-definition"
115+
UpgradeStepRunPreCheckEnsureCliVersion CliStep = "upgrade.run.step.ensure-cli-version"
116+
UpgradeStepGetRepo CliStep = "upgrade.run.step.get-repo"
117+
UpgradeStepLoadRuntimeDefinition CliStep = "upgrade.run.step.load-runtime-definition"
118+
UpgradeStepUpgradeRuntime CliStep = "upgrade.run.step.upgrade-runtime"
119+
UpgradeStepPushRuntimeDefinition CliStep = "upgrade.run.step.push-runtime-definition"
120+
UpgradeStepCreateApp CliStep = "upgrade.run.step.create-app"
121+
UpgradePhaseFinish CliStep = "upgrade.run.phase.finish"
80122

81123
// General
82124
SIGNAL_TERMINATION CliStep = "signal-termination"
125+
FINISH CliStep = "run.finish"
83126

84-
SUCCESS CliStepStatus = "SUCCESS"
85-
FAILURE CliStepStatus = "FAILURE"
86-
CANCELED CliStepStatus = "CANCELED"
127+
SUCCESS CliStepStatus = "SUCCESS"
128+
FAILURE CliStepStatus = "FAILURE"
129+
CANCELED CliStepStatus = "CANCELED"
130+
ABRUPTLY_CANCELED CliStepStatus = "ABRUPTLY_CANCELED"
87131

88132
InstallFlow FlowType = "installation"
89133
UninstallFlow FlowType = "uninstallation"
134+
UpgradeFlow FlowType = "upgrade"
90135
)
91136

92137
// G returns the global reporter
@@ -140,7 +185,23 @@ func (r *segmentAnalyticsReporter) ReportStep(data CliStepData) {
140185
}
141186
}
142187

143-
func (r *segmentAnalyticsReporter) Close() {
188+
func (r *segmentAnalyticsReporter) Close(status CliStepStatus, err error) {
189+
if status == "" {
190+
status = SUCCESS
191+
if err != nil {
192+
status = FAILURE
193+
}
194+
}
195+
196+
log.G().Infof("Closing with status %s", status)
197+
198+
r.ReportStep(CliStepData{
199+
Step: FINISH,
200+
Status: status,
201+
Description: "Finished",
202+
Err: err,
203+
})
204+
144205
if err := r.client.Close(); err != nil {
145206
log.G().Debugf("Failed to close segment client: %w", err)
146207
}
@@ -150,5 +211,5 @@ func (r *noopAnalyticsReporter) ReportStep(_ CliStepData) {
150211
// If no segmentWriteKey is provided this reporter will be used instead.
151212
}
152213

153-
func (r *noopAnalyticsReporter) Close() {
214+
func (r *noopAnalyticsReporter) Close(_ CliStepStatus, _ error) {
154215
}

pkg/util/util.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,12 @@ func ContextWithCancelOnSignals(ctx context.Context, sigs ...os.Signal) context.
5454
for {
5555
s := <-sig
5656
cancels++
57-
reporter.G().ReportStep(reporter.CliStepData{
58-
Step: reporter.SIGNAL_TERMINATION,
59-
Status: reporter.CANCELED,
60-
Description: "Cancelled by an external signal",
61-
Err: nil,
62-
})
6357
if cancels == 1 {
6458
log.G(ctx).Printf("got signal: %s", s)
59+
reportCancel(reporter.CANCELED)
6560
cancel()
6661
} else {
67-
reporter.G().Close()
62+
reporter.G().Close(reporter.ABRUPTLY_CANCELED, nil)
6863
log.G(ctx).Printf("forcing exit")
6964
os.Exit(1)
7065
}
@@ -179,3 +174,12 @@ func CurrentServer() (string, error) {
179174
func DecorateErrorWithDocsLink(err error) error {
180175
return fmt.Errorf("%s\nfor more information: %s", err.Error(), store.Get().DocsLink)
181176
}
177+
178+
func reportCancel(status reporter.CliStepStatus) {
179+
reporter.G().ReportStep(reporter.CliStepData{
180+
Step: reporter.SIGNAL_TERMINATION,
181+
Status: status,
182+
Description: "Cancelled by an external signal",
183+
Err: nil,
184+
})
185+
}

0 commit comments

Comments
 (0)