Skip to content

Commit ec5d537

Browse files
authored
send preflight results event when preflights fail (#1553)
* send preflight results event when failed preflights are bypassed * send preflight failure events whether or not they are bypassed * ? * send json, not go object * better handle 'no baseurl' case * report the entry command (install, run-preflights, etc) along with preflight failure results * mark ignore-host-preflights as hidden in install/run-preflights also add ignore-host-preflights and skip-host-preflights to join/run-preflights
1 parent 8784242 commit ec5d537

File tree

5 files changed

+75
-19
lines changed

5 files changed

+75
-19
lines changed

cmd/installer/cli/install_runpreflights.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/replicatedhq/embedded-cluster/pkg/dryrun"
1616
"github.com/replicatedhq/embedded-cluster/pkg/goods"
1717
"github.com/replicatedhq/embedded-cluster/pkg/helpers"
18+
"github.com/replicatedhq/embedded-cluster/pkg/metrics"
1819
"github.com/replicatedhq/embedded-cluster/pkg/preflights"
1920
"github.com/replicatedhq/embedded-cluster/pkg/prompts"
2021
"github.com/replicatedhq/embedded-cluster/pkg/release"
@@ -48,8 +49,6 @@ func InstallRunPreflightsCmd(ctx context.Context, name string) *cobra.Command {
4849
overrides string
4950
privateCAs []string
5051
configValues string
51-
skipHostPreflights bool
52-
ignoreHostPreflights bool
5352

5453
proxy *ecv1beta1.ProxySpec
5554
)
@@ -155,9 +154,10 @@ func InstallRunPreflightsCmd(ctx context.Context, name string) *cobra.Command {
155154
cmd.Flags().StringSliceVar(&privateCAs, "private-ca", []string{}, "Path to a trusted private CA certificate file")
156155
cmd.Flags().StringVar(&configValues, "config-values", "", "path to a manifest containing config values (must be apiVersion: kots.io/v1beta1, kind: ConfigValues)")
157156

158-
cmd.Flags().BoolVar(&skipHostPreflights, "skip-host-preflights", false, "Skip host preflight checks. This is not recommended and has been deprecated.")
157+
cmd.Flags().Bool("skip-host-preflights", false, "Skip host preflight checks. This is not recommended and has been deprecated.")
159158
cmd.Flags().MarkHidden("skip-host-preflights")
160-
cmd.Flags().BoolVar(&ignoreHostPreflights, "ignore-host-preflights", false, "Run host preflight checks, but prompt the user to continue if they fail instead of exiting.")
159+
cmd.Flags().Bool("ignore-host-preflights", false, "Run host preflight checks, but prompt the user to continue if they fail instead of exiting.")
160+
cmd.Flags().MarkHidden("ignore-host-preflights")
161161

162162
addProxyFlags(cmd)
163163
addCIDRFlags(cmd)
@@ -378,10 +378,10 @@ func RunHostPreflights(cmd *cobra.Command, applier *addons.Applier, replicatedAP
378378
return nil
379379
}
380380

381-
return runHostPreflights(cmd, hpf, proxy, assumeYes)
381+
return runHostPreflights(cmd, hpf, proxy, assumeYes, replicatedAPIURL)
382382
}
383383

384-
func runHostPreflights(cmd *cobra.Command, hpf *v1beta2.HostPreflightSpec, proxy *ecv1beta1.ProxySpec, assumeYes bool) error {
384+
func runHostPreflights(cmd *cobra.Command, hpf *v1beta2.HostPreflightSpec, proxy *ecv1beta1.ProxySpec, assumeYes bool, replicatedAPIURL string) error {
385385
if len(hpf.Collectors) == 0 && len(hpf.Analyzers) == 0 {
386386
return nil
387387
}
@@ -437,9 +437,11 @@ func runHostPreflights(cmd *cobra.Command, hpf *v1beta2.HostPreflightSpec, proxy
437437
}
438438
if ignoreHostPreflightsFlag {
439439
if assumeYes {
440+
metrics.ReportPreflightsFailed(cmd.Context(), replicatedAPIURL, *output, true, cmd.CalledAs())
440441
return nil
441442
}
442443
if prompts.New().Confirm("Are you sure you want to ignore these failures and continue installing?", false) {
444+
metrics.ReportPreflightsFailed(cmd.Context(), replicatedAPIURL, *output, true, cmd.CalledAs())
443445
return nil // user continued after host preflights failed
444446
}
445447
}
@@ -449,7 +451,7 @@ func runHostPreflights(cmd *cobra.Command, hpf *v1beta2.HostPreflightSpec, proxy
449451
} else {
450452
logrus.Info("Please address this issue and try again.")
451453
}
452-
454+
metrics.ReportPreflightsFailed(cmd.Context(), replicatedAPIURL, *output, false, cmd.CalledAs())
453455
return ErrPreflightsHaveFail
454456
}
455457

@@ -465,15 +467,17 @@ func runHostPreflights(cmd *cobra.Command, hpf *v1beta2.HostPreflightSpec, proxy
465467
// so we just print the warnings and continue
466468
pb.Close()
467469
output.PrintTableWithoutInfo()
470+
metrics.ReportPreflightsFailed(cmd.Context(), replicatedAPIURL, *output, true, cmd.CalledAs())
468471
return nil
469472
}
470473
pb.Close()
471474
output.PrintTableWithoutInfo()
472-
if !prompts.New().Confirm("Do you want to continue?", false) {
473-
pb.Close()
474-
return fmt.Errorf("user aborted")
475+
if prompts.New().Confirm("Do you want to continue?", false) {
476+
metrics.ReportPreflightsFailed(cmd.Context(), replicatedAPIURL, *output, true, cmd.CalledAs())
477+
return nil
475478
}
476-
return nil
479+
metrics.ReportPreflightsFailed(cmd.Context(), replicatedAPIURL, *output, false, cmd.CalledAs())
480+
return fmt.Errorf("user aborted")
477481
}
478482

479483
// No failures or warnings

cmd/installer/cli/join_runpreflights.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ import (
2424

2525
func JoinRunPreflightsCmd(ctx context.Context, name string) *cobra.Command {
2626
var (
27-
airgapBundle string
28-
networkInterface string
29-
assumeYes bool
30-
skipHostPreflights bool
31-
ignoreHostPreflights bool
27+
airgapBundle string
28+
networkInterface string
29+
assumeYes bool
3230
)
3331
cmd := &cobra.Command{
3432
Use: "run-preflights",
@@ -135,9 +133,11 @@ func JoinRunPreflightsCmd(ctx context.Context, name string) *cobra.Command {
135133
cmd.Flags().StringVar(&airgapBundle, "airgap-bundle", "", "Path to the air gap bundle. If set, the installation will complete without internet access.")
136134
cmd.Flags().MarkHidden("airgap-bundle")
137135
cmd.Flags().StringVar(&networkInterface, "network-interface", "", "The network interface to use for the cluster")
138-
cmd.Flags().BoolVar(&skipHostPreflights, "skip-host-preflights", false, "Skip host preflight checks. This is not recommended and has been deprecated.")
136+
137+
cmd.Flags().Bool("skip-host-preflights", false, "Skip host preflight checks. This is not recommended and has been deprecated.")
139138
cmd.Flags().MarkHidden("skip-host-preflights")
140-
cmd.Flags().BoolVar(&ignoreHostPreflights, "ignore-host-preflights", false, "Run host preflight checks, but prompt the user to continue if they fail instead of exiting.")
139+
cmd.Flags().Bool("ignore-host-preflights", false, "Run host preflight checks, but prompt the user to continue if they fail instead of exiting.")
140+
cmd.Flags().MarkHidden("ignore-host-preflights")
141141

142142
cmd.Flags().BoolVar(&assumeYes, "yes", false, "Assume yes to all prompts.")
143143
cmd.Flags().SetNormalizeFunc(normalizeNoPromptToYes)

cmd/installer/cli/restore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ func RunHostPreflightsForRestore(cmd *cobra.Command, applier *addons.Applier, pr
720720
return fmt.Errorf("unable to read host preflights: %w", err)
721721
}
722722

723-
return runHostPreflights(cmd, hpf, proxy, assumeYes)
723+
return runHostPreflights(cmd, hpf, proxy, assumeYes, "")
724724
}
725725

726726
// ensureK0sConfigForRestore creates a new k0s.yaml configuration file for restore operations.

pkg/metrics/reporter.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package metrics
22

33
import (
44
"context"
5+
"encoding/json"
56
"os"
67
"strings"
78
"sync"
@@ -12,6 +13,7 @@ import (
1213

1314
"github.com/replicatedhq/embedded-cluster/pkg/helpers"
1415
"github.com/replicatedhq/embedded-cluster/pkg/metrics/types"
16+
"github.com/replicatedhq/embedded-cluster/pkg/preflights"
1517
"github.com/replicatedhq/embedded-cluster/pkg/release"
1618
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
1719
"github.com/replicatedhq/embedded-cluster/pkg/versions"
@@ -163,3 +165,37 @@ func ReportApplyFinished(ctx context.Context, licenseFlag string, license *kotsv
163165
}
164166
ReportInstallationSucceeded(ctx, license)
165167
}
168+
169+
// ReportPreflightsFailed reports that the preflights failed but were bypassed.
170+
func ReportPreflightsFailed(ctx context.Context, url string, output preflights.Output, bypassed bool, entryCommand string) {
171+
if url == "" {
172+
url = BaseURL(nil)
173+
}
174+
175+
hostname, err := os.Hostname()
176+
if err != nil {
177+
logrus.Warnf("unable to get hostname: %s", err)
178+
hostname = "unknown"
179+
}
180+
181+
eventType := "PreflightsFailed"
182+
if bypassed {
183+
eventType = "PreflightsBypassed"
184+
}
185+
186+
outputJSON, err := json.Marshal(output)
187+
if err != nil {
188+
logrus.Warnf("unable to marshal preflight output: %s", err)
189+
return
190+
}
191+
192+
ev := types.PreflightsFailed{
193+
ClusterID: ClusterID(),
194+
Version: versions.Version,
195+
NodeName: hostname,
196+
PreflightOutput: string(outputJSON),
197+
EventType: eventType,
198+
EntryCommand: entryCommand,
199+
}
200+
go Send(ctx, url, ev)
201+
}

pkg/metrics/types/types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,19 @@ type JoinFailed struct {
8282
func (e JoinFailed) Title() string {
8383
return "JoinFailed"
8484
}
85+
86+
// PreflightsFailed event is send back home when the preflights failed but were bypassed.
87+
type PreflightsFailed struct {
88+
ClusterID uuid.UUID `json:"clusterID"`
89+
Version string `json:"version"`
90+
NodeName string `json:"nodeName"`
91+
PreflightOutput string `json:"preflightOutput"`
92+
EventType string `json:"eventType"`
93+
EntryCommand string `json:"entryCommand"`
94+
}
95+
96+
// Title returns the name of the event.
97+
func (e PreflightsFailed) Title() string {
98+
// GenericEvents are added to the events table, but do not update the cluster status
99+
return "GenericEvent"
100+
}

0 commit comments

Comments
 (0)