Skip to content

Commit

Permalink
feat: Add optimized message field to recipe and status events (#1666)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avinash-Sanpala authored Nov 11, 2024
1 parent 9ed354d commit 54582d1
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
go-version:
- 1.21.x
- 1.22.x
platform:
- ubuntu-latest
- macos-latest
Expand All @@ -25,7 +25,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x

- name: Compile
run: make compile-only
2 changes: 1 addition & 1 deletion .github/workflows/e2e-dp-eu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x

- name: Add GOBIN to PATH
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-dp-us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x

- name: Add GOBIN to PATH
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-eu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x

- name: Add GOBIN to PATH
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x

- name: Add GOBIN to PATH
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x

- name: Add GOBIN to PATH
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x

- name: Add GOBIN to PATH
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x

- name: Add GOBIN to PATH
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x

- name: Add GOBIN to PATH
run: echo "$(go env GOPATH)/bin"
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x

- name: Add GOBIN to PATH
run: echo "$(go env GOPATH)/bin"
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/newrelic/newrelic-cli

go 1.21
go 1.22

toolchain go1.22.9

require (
github.com/AlecAivazis/survey/v2 v2.3.7
Expand All @@ -16,7 +18,7 @@ require (
github.com/jedib0t/go-pretty/v6 v6.4.4
github.com/joshdk/go-junit v0.0.0-20210226021600-6145f504ca0d
github.com/mitchellh/go-homedir v1.1.0
github.com/newrelic/newrelic-client-go/v2 v2.48.2
github.com/newrelic/newrelic-client-go/v2 v2.51.4-0.20241111153946-a221c9e3bd63
github.com/pkg/errors v0.9.1
github.com/shirou/gopsutil/v3 v3.23.9
github.com/sirupsen/logrus v1.9.3
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGg
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/newrelic-forks/task/v3 v3.11.0 h1:8Gwo33tMTqQkWlekCChbCZqf0nrXI85UqVeIgXk73L0=
github.com/newrelic-forks/task/v3 v3.11.0/go.mod h1:rzfFpA7kl0CsL44ZQd2F2Hic5xOb2m03N6Y2lUjdNo4=
github.com/newrelic/newrelic-client-go/v2 v2.48.2 h1:Pd8/ADdidF/dISMCy9B2UHvcD11lnj4Use6j++OOEf4=
github.com/newrelic/newrelic-client-go/v2 v2.48.2/go.mod h1:pDFY24/6iIMEbPIdowTRrRn9YYwkXc3j+B+XpTb4oF4=
github.com/newrelic/newrelic-client-go/v2 v2.51.3 h1:Bu/cUs6nfMjQMPBcxxHt4Xm30tKDT7ttYy/XRDsWP6Y=
github.com/newrelic/newrelic-client-go/v2 v2.51.3/go.mod h1:+RRjI3nDGWT3kLm9Oi3QxpBm70uu8q1upEHBVWCZFpo=
github.com/newrelic/newrelic-client-go/v2 v2.51.4-0.20241111153946-a221c9e3bd63 h1:r2s0IZ9RuyIopiMZAkx5FgXttYzE3Rv6L34RVxwpgKg=
github.com/newrelic/newrelic-client-go/v2 v2.51.4-0.20241111153946-a221c9e3bd63/go.mod h1:+RRjI3nDGWT3kLm9Oi3QxpBm70uu8q1upEHBVWCZFpo=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
12 changes: 7 additions & 5 deletions internal/install/execution/install_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ var RecipeStatusTypes = struct {
}

type StatusError struct {
Message string `json:"message"`
Details string `json:"details"`
TaskPath []string `json:"taskPath"`
Message string `json:"message"`
Details string `json:"details"`
TaskPath []string `json:"taskPath"`
OptimizedMessage string `json:"optimizedMessage"`
}

var StatusIconMap = map[RecipeStatusType]string{
Expand Down Expand Up @@ -379,8 +380,9 @@ func (s *InstallStatus) withRecipeEvent(e RecipeStatusEvent, rs RecipeStatusType
s.withSuccessLinkConfig(e.Recipe.SuccessLinkConfig)

statusError := StatusError{
Message: e.Msg,
TaskPath: e.TaskPath,
Message: e.Msg,
TaskPath: e.TaskPath,
OptimizedMessage: e.OptimizedMessage,
}

s.Error = statusError
Expand Down
6 changes: 4 additions & 2 deletions internal/install/execution/install_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ func TestStatusWithRecipeEvent_ErrorMessages(t *testing.T) {
s := NewInstallStatus(types.InstallerContext{}, []StatusSubscriber{}, slg)
r := types.OpenInstallationRecipe{Name: "testRecipe"}
e := RecipeStatusEvent{
Recipe: r,
Msg: "thing failed for a reason",
Recipe: r,
Msg: "thing failed for a reason",
OptimizedMessage: "clean error message",
}

s.Timestamp = 0
Expand All @@ -50,6 +51,7 @@ func TestStatusWithRecipeEvent_ErrorMessages(t *testing.T) {
require.NotEmpty(t, s.Timestamp)
require.Equal(t, s.Statuses[0].Error, s.Error)
require.Equal(t, e.Msg, s.Error.Message)
require.Equal(t, e.OptimizedMessage, s.Error.OptimizedMessage)
}

func TestExecutionStatusWithRecipeEvent_RecipeExists(t *testing.T) {
Expand Down
15 changes: 9 additions & 6 deletions internal/install/execution/installevents_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ func (r InstallEventsReporter) createMultipleRecipeInstallEvents(status *Install
CliVersion: status.CLIVersion,
Complete: status.Complete,
Error: installevents.InstallationStatusErrorInput{
Details: ss.Error.Details,
Message: ss.Error.Message,
Details: ss.Error.Details,
Message: ss.Error.Message,
OptimizedMessage: ss.Error.OptimizedMessage,
},
Status: installevents.InstallationRecipeStatusType(ss.Status),
Name: ss.Name,
Expand Down Expand Up @@ -161,8 +162,9 @@ func buildInstallStatus(state installevents.InstallationInstallStateType, status
CliVersion: status.CLIVersion,
DeployedBy: status.DeployedBy,
Error: installevents.InstallationStatusErrorInput{
Details: status.Error.Details,
Message: status.Error.Message,
Details: status.Error.Details,
Message: status.Error.Message,
OptimizedMessage: status.Error.OptimizedMessage,
},
HostName: status.DiscoveryManifest.Hostname,
KernelArch: status.DiscoveryManifest.KernelArch,
Expand Down Expand Up @@ -192,8 +194,9 @@ func buildRecipeStatus(status *InstallStatus, event *RecipeStatusEvent, statusTy
CliVersion: status.CLIVersion,
Complete: status.Complete,
Error: installevents.InstallationStatusErrorInput{
Details: status.Error.Details,
Message: status.Error.Message,
Details: status.Error.Details,
Message: status.Error.Message,
OptimizedMessage: status.Error.OptimizedMessage,
},
HostName: status.DiscoveryManifest.Hostname,
KernelArch: status.DiscoveryManifest.KernelArch,
Expand Down
1 change: 1 addition & 0 deletions internal/install/execution/status_subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type RecipeStatusEvent struct {
EntityGUID string
ValidationDurationMs int64
Metadata map[string]string
OptimizedMessage string
}

func NewRecipeStatusEvent(recipe *types.OpenInstallationRecipe) RecipeStatusEvent {
Expand Down
17 changes: 10 additions & 7 deletions internal/install/recipe_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,10 @@ func (i *RecipeInstall) executeAndValidate(ctx context.Context, m *types.Discove

if e, ok := err.(*types.UnsupportedOperatingSystemError); ok {
i.status.RecipeUnsupported(execution.RecipeStatusEvent{
Recipe: *r,
Msg: e.Error(),
Metadata: i.recipeExecutor.GetOutput().Metadata(),
Recipe: *r,
Msg: e.Error(),
Metadata: i.recipeExecutor.GetOutput().Metadata(),
OptimizedMessage: e.Error(),
})

return "", err
Expand All @@ -610,9 +611,10 @@ func (i *RecipeInstall) executeAndValidate(ctx context.Context, m *types.Discove
i.askToReRunInDebugMode()

se := execution.RecipeStatusEvent{
Recipe: *r,
Msg: msg,
Metadata: i.recipeExecutor.GetOutput().Metadata(),
Recipe: *r,
Msg: msg,
Metadata: i.recipeExecutor.GetOutput().Metadata(),
OptimizedMessage: err.Error(),
}

if e, ok := err.(types.GoTaskError); ok {
Expand Down Expand Up @@ -666,6 +668,7 @@ func (i *RecipeInstall) executeAndValidate(ctx context.Context, m *types.Discove
Msg: validationErr.Error(),
ValidationDurationMs: validationDurationMs,
Metadata: i.recipeExecutor.GetOutput().Metadata(),
OptimizedMessage: err.Error(),
})

return "", validationErr
Expand Down Expand Up @@ -785,7 +788,7 @@ func (i *RecipeInstall) validateRecipeViaAllMethods(ctx context.Context, r *type
return "", fmt.Errorf("no validation was successful. most recent validation error: %w", err)
}
case <-timeoutCtx.Done():
return "", fmt.Errorf("timed out waiting for validation to succeed")
return "", fmt.Errorf("installation validation timed out after %v. please retry the process\n", validationTimeout)
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion tools/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/newrelic/newrelic-cli/tools

go 1.21
go 1.22

toolchain go1.22.9

require (
github.com/caarlos0/svu v1.9.0
Expand Down

0 comments on commit 54582d1

Please sign in to comment.