Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add refresh flag to support java agent reloading #528

Merged
merged 1 commit into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions cli/cmd/exp.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ func (ec *baseExpCommandService) registerActionCommand(target, scope string, act
}

flags := addTimeoutFlag(actionCommandSpec.Flags())
flags = addOverrideFlag(flags)
ec.bindFlagsFunc(command.ActionFlags, command.command, flags)
// set matcher flags
ec.bindFlagsFunc(command.MatcherFlags, command.command, actionCommandSpec.Matchers())
Expand Down Expand Up @@ -313,28 +312,6 @@ func addTimeoutFlag(flags []spec.ExpFlagSpec) []spec.ExpFlagSpec {
return flags
}

func addOverrideFlag(flags []spec.ExpFlagSpec) []spec.ExpFlagSpec {
contains := false
for _, flag := range flags {
if flag.FlagName() == "override" {
contains = true
break
}
}
if !contains {
// set action flags, always add timeout param
flags = append(flags,
&spec.ExpFlag{
Name: "override",
Desc: "only for java now, uninstall java agent",
NoArgs: true,
Required: false,
},
)
}
return flags
}

// checkError for db operation
func checkError(err error) {
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions exec/jvm/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func (e *Executor) Exec(uid string, ctx context.Context, model *spec.ExpModel) *
// 1. check parameters
processName := model.ActionFlags["process"]
processId := model.ActionFlags["pid"]
override := model.ActionFlags["override"] == "true"
// refresh flag is used to reload java agent
refresh := model.ActionFlags["refresh"] == "true"

// 2. get record from db by processname|processId
suid, isDestroy := spec.IsDestroy(ctx)
Expand Down Expand Up @@ -118,7 +119,7 @@ func (e *Executor) Exec(uid string, ctx context.Context, model *spec.ExpModel) *
fmt.Sprintf(spec.ResponseErr[spec.ParameterLess].ErrInfo, "process&pid"))
}
}
if override {
if refresh {
// Uninstall java agent
logrus.Info("Uninstall java agent")
response := Revoke(uid, record, processName, processId)
Expand All @@ -134,14 +135,13 @@ func (e *Executor) Exec(uid string, ctx context.Context, model *spec.ExpModel) *
}

// Install java agent
if port == "" || override {
if port == "" || refresh {
logrus.Info("Install java agent")
response, newPort := Prepare(uid, processName, processId)
if !response.Success {
return response
}
port = newPort
delete(model.ActionFlags, "override")
}
}

Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ github.com/chaosblade-io/chaosblade-exec-os v1.2.0 h1:GPv6JC/jh7NosY8cIUBF1P3chO
github.com/chaosblade-io/chaosblade-exec-os v1.2.0/go.mod h1:NPmsiENi1L3l+wKvLDib/s395YkAXaEqwrVIWZUomDM=
github.com/chaosblade-io/chaosblade-operator v1.2.0 h1:FdnPA/1dYxY36GeqEJb9rTo86F4jANw30b2SDaEBj6c=
github.com/chaosblade-io/chaosblade-operator v1.2.0/go.mod h1:WUUCxvx+PR9Yu1kuI+j6wyurcolcoT2iCLsqqvM3oIA=
github.com/chaosblade-io/chaosblade-operator v1.3.0-dev h1:GLzsygO/aIdyOyRvw6Rvw+YL000PRLmio6uddVz042w=
github.com/chaosblade-io/chaosblade-operator v1.3.0-dev/go.mod h1:LoAaSdtyx1HIaUlUbIh7GW4ze5v86pLT0Embh6d40HA=
github.com/chaosblade-io/chaosblade-spec-go v1.0.1-0.20210531022335-b8bb425f7cb9/go.mod h1:xUF+8r54FphQjBR8fVPnweVqzu7EitE15UsnZ57O5gk=
github.com/chaosblade-io/chaosblade-spec-go v1.2.0 h1:f1AAqUqrWMPPOYu6JacpUQCVlxe6oFKMhfe0ZMivRQI=
Expand Down