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

bs target #2976

Merged
merged 1 commit into from
Jan 5, 2024
Merged

bs target #2976

merged 1 commit into from
Jan 5, 2024

Conversation

wsehjk
Copy link
Contributor

@wsehjk wsehjk commented Dec 22, 2023

What problem does this PR solve?

Issue Number: #2564

Problem Summary:

What is changed and how it works?

What's Changed:
add target/target.go,
How it Works:
this command is dependent on two command: curve bs status cluster and curve bs status client
Side effects(Breaking backward compatibility? Performance regression?):
No side effects found
command output:

[
  {
    "label": {
      "job": "etcd"
    },
    "targets": [
      "172.21.0.13:23790",
      "172.21.0.13:23791",
      "172.21.0.13:23792"
    ]
  },
  {
    "label": {
      "job": "mds"
    },
    "targets": [
      "172.21.0.13:6700",
      "172.21.0.13:6701",
      "172.21.0.13:6702"
    ]
  },
  {
    "label": {
      "job": "chunkserver"
    },
    "targets": [
      "172.21.0.13:8200",
      "172.21.0.13:8202",
      "172.21.0.13:8201"
    ]
  },
  {
    "label": {
      "job": "snapshotcloneserver"
    },
    "targets": [
      "172.21.0.13:5550",
      "172.21.0.13:5551",
      "172.21.0.13:5552"
    ]
  },
  {
    "label": {
      "job": "client"
    },
    "targets": [
      "172.21.0.13:9000"
    ]
  }
]

Check List

  • Relevant documentation/comments is changed or added
  • I acknowledge that all my contributions will be made under the project's license

Comment on lines 506 to 511
ErrTargetClient = func() *CmdError {
return NewInternalCmdError(82, "get client target error: %s")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate

)

const (
targetexample = "$curve bs target"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe curve bs export target is more meaningful.

Comment on lines 85 to 96
clusterCommand := cluster.NewStatusClusterCommand()
// cluster command no output
clusterCommand.Cmd.SetArgs([]string{
fmt.Sprintf("--%s", config.FORMAT), config.FORMAT_NOOUT,})
clusterCommand.Cmd.SilenceErrors = true
err := clusterCommand.Cmd.Execute()
if err != nil {
retErr := cmderror.ErrTargetCluster()
retErr.Format(err.Error())
return retErr.ToError()
}
clusterResult := clusterCommand.Result.(map[string]interface{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use a function in cluster.go to handle. Like other command.

Comment on lines 98 to 101
tcmd.Result = append(tcmd.Result.([]ResultStruct), ExtractClusterResult(clusterResult, "etcd"))
tcmd.Result = append(tcmd.Result.([]ResultStruct), ExtractClusterResult(clusterResult, "mds"))
tcmd.Result = append(tcmd.Result.([]ResultStruct), ExtractClusterResult(clusterResult, "chunkserver"))
tcmd.Result = append(tcmd.Result.([]ResultStruct), ExtractClusterResult(clusterResult, "snapshot"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can unmarsal the result using json package?

Comment on lines 116 to 122
clientStruct["label"] = map[string]string{
"job" : "client",
}
clientStruct["targets"] = make([]string, 0)
for _, result := range clientResult {
clientStruct["targets"] = append(clientStruct["targets"].([]string), result["addr"])
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

@caoxianfei1
Copy link
Contributor

caoxianfei1 commented Dec 25, 2023

@wsehjk you should squash to one commit and modify the commit message is meaningful.

@caoxianfei1
Copy link
Contributor

cicheck

Copy link
Contributor

@montaguelhz montaguelhz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job

func ExtractClusterResult(clusterResult map[string]interface{}, service string) ResultStruct{
result := ResultStruct{}
arrs := clusterResult[service].([]map[string]string)
result["label"] = map[string]string{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of hardcoding, define the constants in "github.com/opencurve/curve/tools-v2/internal/utils".

)

const (
targetexample = "$curve bs export target"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

targetExample is better

return retErr.ToError()
}
tcmd.Result = []ResultStruct{}
tcmd.Result = append(tcmd.Result.([]ResultStruct), ExtractClusterResult(clusterResult.(map[string]interface{}), "etcd"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

clientCommand.Cmd.SilenceErrors = true
err := clientCommand.Cmd.Execute()

//clientResult := clientCommand.Result.([]map[string]string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary code.

@montaguelhz
Copy link
Contributor

It is better to show the results of your test.

@montaguelhz
Copy link
Contributor

cicheck

export services and clients in the bs cluster

Usage:

Copy link
Contributor

@caoxianfei1 caoxianfei1 Dec 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add specific commands.
curve export or curve export target or curve bs export target?

Copy link
Contributor Author

@wsehjk wsehjk Dec 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake. I have fixed it

@caoxianfei1
Copy link
Contributor

The commit message suggestion:
Feat/tool: support export cluster targets for monitor.

@caoxianfei1
Copy link
Contributor

caoxianfei1 commented Dec 26, 2023

The command can generate a target.json file is better. And the default path is current directory.

@wsehjk
Copy link
Contributor Author

wsehjk commented Dec 27, 2023

cicheck

8 similar comments
@wsehjk
Copy link
Contributor Author

wsehjk commented Dec 28, 2023

cicheck

@wsehjk
Copy link
Contributor Author

wsehjk commented Dec 28, 2023

cicheck

@wsehjk
Copy link
Contributor Author

wsehjk commented Jan 1, 2024

cicheck

@wsehjk
Copy link
Contributor Author

wsehjk commented Jan 2, 2024

cicheck

@montaguelhz
Copy link
Contributor

cicheck

@wsehjk
Copy link
Contributor Author

wsehjk commented Jan 4, 2024

cicheck

@wsehjk
Copy link
Contributor Author

wsehjk commented Jan 4, 2024

cicheck

@wsehjk
Copy link
Contributor Author

wsehjk commented Jan 4, 2024

cicheck

@wsehjk
Copy link
Contributor Author

wsehjk commented Jan 4, 2024

cicheck

2 similar comments
@wsehjk
Copy link
Contributor Author

wsehjk commented Jan 5, 2024

cicheck

@wsehjk
Copy link
Contributor Author

wsehjk commented Jan 5, 2024

cicheck

@caoxianfei1 caoxianfei1 merged commit 88a6091 into opencurve:master Jan 5, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants