Skip to content

Commit 9196d16

Browse files
Changed reporting to a single table (#223)
1 parent 3db5e74 commit 9196d16

File tree

6 files changed

+48
-38
lines changed

6 files changed

+48
-38
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.203
1+
VERSION=v0.0.204
22

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

cmd/commands/runtime.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
175175
installationOpts.RuntimeName = args[0]
176176
}
177177

178-
createAnalyticsReporter(cmd.Context())
178+
createAnalyticsReporter(cmd.Context(), reporter.InstallFlow)
179179

180180
if err := runtimeInstallCommandPreRunHandler(cmd, &installationOpts); err != nil {
181181
return fmt.Errorf("Pre installation error: %w", err)
@@ -798,7 +798,7 @@ func NewRuntimeUninstallCommand() *cobra.Command {
798798
var err error
799799
ctx := cmd.Context()
800800

801-
createAnalyticsReporter(ctx)
801+
createAnalyticsReporter(ctx, reporter.UninstallFlow)
802802

803803
err = getKubeContextNameFromUserSelect(cmd, &kubeContextName)
804804
if err != nil {
@@ -1562,15 +1562,15 @@ func postInstallationHandler(ctx context.Context, opts *RuntimeInstallOptions, e
15621562
printSummaryToUser()
15631563
}
15641564

1565-
func handleCliStep(event reporter.CliEventType, message string, err error) {
1565+
func handleCliStep(step reporter.CliStep, message string, err error) {
15661566
r := reporter.G()
15671567
status := reporter.SUCCESS
15681568
if err != nil {
15691569
status = reporter.FAILURE
15701570
}
15711571

15721572
r.ReportStep(reporter.CliStepData{
1573-
Event: event,
1573+
Step: step,
15741574
Status: status,
15751575
Description: message,
15761576
Err: err,
@@ -1601,12 +1601,12 @@ func printSummaryToUser() {
16011601
summaryArr = []summaryLog{}
16021602
}
16031603

1604-
func createAnalyticsReporter(ctx context.Context) {
1604+
func createAnalyticsReporter(ctx context.Context, flow reporter.FlowType) {
16051605
user, err := cfConfig.GetCurrentContext().GetUser(ctx)
16061606
// If error, it will default to noop reporter
16071607
if err != nil {
16081608
log.G().Debug("Failed to get user from context")
16091609
return
16101610
}
1611-
reporter.Init(user)
1611+
reporter.Init(user, flow)
16121612
}

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.203/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.204/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.203/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.204/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.203
8+
version: 0.0.204
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

pkg/reporter/reporter.go

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,19 @@ type (
3131
}
3232

3333
CliStepData struct {
34-
Event CliEventType
34+
Step CliStep
3535
Status CliStepStatus
3636
Description string
3737
Err error
3838
}
3939

40-
CliEventType string
40+
CliStep string
4141
CliStepStatus string
42+
FlowType string
4243

4344
segmentAnalyticsReporter struct {
4445
client analytics.Client
46+
flowType FlowType
4547
flowId string
4648
userId string
4749
userName string
@@ -53,41 +55,46 @@ type (
5355
)
5456

5557
const (
58+
cliEvent string = "cli-runtime-operations"
59+
5660
// Install
57-
InstallStepPreChecks CliEventType = "install.pre-installation-checks"
58-
InstallStepDownloadRuntimeDefinitions CliEventType = "install.download-runtime-definitions"
59-
InstallStepGetServerAddress CliEventType = "install.get-server-address"
60-
InstallStepCreateRuntimeOnPlatform CliEventType = "install.create-runtime-on-platform"
61-
InstallStepBootstrapRepo CliEventType = "install.bootstrap-repo"
62-
InstallStepCreateProject CliEventType = "install.create-project"
63-
InstallStepCreateConfigMap CliEventType = "install.create-codefresh-cm"
64-
InstallStepCreateComponent CliEventType = "install.create-component"
65-
InstallStepInstallComponenets CliEventType = "install.install-components"
66-
InstallStepCreateGitsource CliEventType = "install.create-gitsource"
67-
InstallStepCreateMarketplaceGitsource CliEventType = "install.create-marketplace-gitsource"
68-
InstallStepCompleteRuntimeInstallation CliEventType = "install.complete-runtime-installation"
69-
InstallStepCreateDefaultGitIntegration CliEventType = "install.create-default-git-integration"
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"
7074

7175
// Uninstall
72-
UninstallStepCheckRuntimeExists CliEventType = "uninstall.check-runtime-exists"
73-
UninstallStepUninstallRepo CliEventType = "uninstall.uninstall-repo"
74-
UninstallStepDeleteRuntimeFromPlatform CliEventType = "uninstall.delete-runtime-from-platform"
75-
UninstallStepCompleteRuntimeUninstallation CliEventType = "uninstall.complete-runtime-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"
7680

7781
// General
78-
SIGNAL_TERMINATION CliEventType = "signal-termination"
82+
SIGNAL_TERMINATION CliStep = "signal-termination"
7983

8084
SUCCESS CliStepStatus = "SUCCESS"
8185
FAILURE CliStepStatus = "FAILURE"
8286
CANCELED CliStepStatus = "CANCELED"
87+
88+
InstallFlow FlowType = "installation"
89+
UninstallFlow FlowType = "uninstallation"
8390
)
8491

8592
// G returns the global reporter
8693
func G() AnalyticsReporter {
8794
return ar
8895
}
8996

90-
func Init(user *codefresh.User) {
97+
func Init(user *codefresh.User, flow FlowType) {
9198
writeKey := store.Get().SegmentWriteKey
9299
if writeKey == "" {
93100
log.G().Debug("No segment write key was provided. Using the noop reporter.")
@@ -99,29 +106,32 @@ func Init(user *codefresh.User) {
99106
ar = &segmentAnalyticsReporter{
100107
client: analytics.New(writeKey),
101108
flowId: uuid.New().String(),
109+
flowType: flow,
102110
userId: user.ID,
103111
userName: user.Name,
104112
accountId: account.ID,
105113
accountName: account.Name,
106114
}
107115
}
108116

109-
func (r *segmentAnalyticsReporter) ReportStep(step CliStepData) {
117+
func (r *segmentAnalyticsReporter) ReportStep(data CliStepData) {
110118
properties := analytics.NewProperties().
111119
Set("accountId", r.accountId).
112120
Set("accountName", r.accountName).
113121
Set("userName", r.userName).
114122
Set("flowId", r.flowId).
115-
Set("description", step.Description).
116-
Set("status", step.Status)
123+
Set("flowType", r.flowType).
124+
Set("description", data.Description).
125+
Set("step", data.Step).
126+
Set("status", data.Status)
117127

118-
if step.Err != nil {
119-
properties = properties.Set("error", step.Err.Error())
128+
if data.Err != nil {
129+
properties = properties.Set("error", data.Err.Error())
120130
}
121131

122132
err := r.client.Enqueue(analytics.Track{
123133
UserId: r.userId,
124-
Event: string(step.Event),
134+
Event: cliEvent,
125135
Properties: properties,
126136
})
127137

pkg/util/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func ContextWithCancelOnSignals(ctx context.Context, sigs ...os.Signal) context.
5555
s := <-sig
5656
cancels++
5757
reporter.G().ReportStep(reporter.CliStepData{
58-
Event: reporter.SIGNAL_TERMINATION,
58+
Step: reporter.SIGNAL_TERMINATION,
5959
Status: reporter.CANCELED,
6060
Description: "Cancelled by an external signal",
6161
Err: nil,

0 commit comments

Comments
 (0)