Skip to content

Commit

Permalink
feat: 新增riak监控、在riak部署与扩缩容的flow与dbactor中补充监控内容的功能 #600
Browse files Browse the repository at this point in the history
  • Loading branch information
fanfanyangyang committed Sep 13, 2023
1 parent bb54e36 commit 3d0ffc1
Show file tree
Hide file tree
Showing 60 changed files with 3,263 additions and 28 deletions.
1 change: 1 addition & 0 deletions dbm-services/go.work
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ go 1.19

use (
riak/db-tools/dbactuator
riak/db-tools/riak-monitor
bigdata/db-tools/dbactuator
common/db-config
common/db-resource
Expand Down
168 changes: 167 additions & 1 deletion dbm-services/go.work.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dbm-services/riak/db-tools/dbactuator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/spf13/cobra v1.7.0
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v2 v2.4.0
)

require (
Expand Down
2 changes: 2 additions & 0 deletions dbm-services/riak/db-tools/dbactuator/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func NewRiakCommand() *cobra.Command {
NewUninstallCommand(),
NewStopCommand(),
NewStartCommand(),
NewDeployMonitorCommand(),
NewStartMonitorCommand(),
NewStopMonitorCommand(),
},
},
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package riakcmd

import (
"fmt"

"dbm-services/common/go-pubpkg/logger"
"dbm-services/riak/db-tools/dbactuator/internal/subcmd"
"dbm-services/riak/db-tools/dbactuator/pkg/components/riak"
"dbm-services/riak/db-tools/dbactuator/pkg/util"

"github.com/spf13/cobra"
)

// DeployMonitorAct 部署riak监控dbactor参数
type DeployMonitorAct struct {
*subcmd.BaseOptions
Payload riak.DeployMonitorComp
}

// NewDeployMonitorCommand riak搬迁数据进度
func NewDeployMonitorCommand() *cobra.Command {
act := DeployMonitorAct{
BaseOptions: subcmd.GBaseOptions,
}
cmd := &cobra.Command{
Use: "deploy-monitor",
Short: "部署监控",
Example: fmt.Sprintf("dbactuator riak deploy-monitor %s", subcmd.CmdBaseExampleStr),
Run: func(cmd *cobra.Command, args []string) {
util.CheckErr(act.Validator())
util.CheckErr(act.Init())
util.CheckErr(act.Run())
},
}
return cmd
}

// Validator TODO
func (d *DeployMonitorAct) Validator() error {
return d.BaseOptions.Validate()
}

// Init 反序列化并检查
func (d *DeployMonitorAct) Init() error {
if err := d.DeserializeAndValidate(&d.Payload); err != nil {
logger.Error("DeserializeAndValidate err %s", err.Error())
return err
}
return nil
}

// Run 运行
func (d *DeployMonitorAct) Run() error {
steps := subcmd.Steps{
{
FunName: "解压crond和monitor介质",
Func: d.Payload.DeployBinary,
},
// riak使用mysql-crond实现定时功能
// 生成mysql-crond与riak-monitor的配置文件,部分根据template生成
// 部分直接生成yaml
{
FunName: "生成crond的runtime.yaml文件",
Func: d.Payload.GenerateCrondConfigYaml,
},
{
FunName: "生成monitor的runtime.yaml文件",
Func: d.Payload.GenerateMonitorConfigYaml,
},
{
FunName: "生成crond的jobs-config.yaml文件",
Func: d.Payload.GenerateJobsConfigYaml,
},
{
FunName: "生成monitor的items-config.yaml文件",
Func: d.Payload.GenerateItemsConfigYaml,
},
// 前台预执行便于发现执行报错,然后后台正式执行
{
FunName: "部署监控",
Func: d.Payload.DeployMonitor,
},
}
// 部署失败
if err := steps.Run(); err != nil {
return err
}
// 部署成功
logger.Info("deploy monitor success")
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package riakcmd

import (
"fmt"

"dbm-services/common/go-pubpkg/logger"
"dbm-services/riak/db-tools/dbactuator/internal/subcmd"
"dbm-services/riak/db-tools/dbactuator/pkg/components/riak"
"dbm-services/riak/db-tools/dbactuator/pkg/util"

"github.com/spf13/cobra"
)

// StartMonitorAct 启动监控riak dbactor参数
type StartMonitorAct struct {
*subcmd.BaseOptions
Payload riak.StartMonitorComp
}

// NewStartMonitorCommand riak搬迁数据进度
func NewStartMonitorCommand() *cobra.Command {
act := StartMonitorAct{
BaseOptions: subcmd.GBaseOptions,
}
cmd := &cobra.Command{
Use: "start-monitor",
Short: "启动监控",
Example: fmt.Sprintf("dbactuator riak start-monitor %s", subcmd.CmdBaseExampleStr),
Run: func(cmd *cobra.Command, args []string) {
util.CheckErr(act.Validator())
util.CheckErr(act.Init())
util.CheckErr(act.Run())
},
}
return cmd
}

// Validator TODO
func (d *StartMonitorAct) Validator() error {
return d.BaseOptions.Validate()
}

// Init 反序列化并检查
func (d *StartMonitorAct) Init() error {
if err := d.DeserializeAndValidate(&d.Payload); err != nil {
logger.Error("DeserializeAndValidate err %s", err.Error())
return err
}
return nil
}

// Run 运行
func (d *StartMonitorAct) Run() error {
steps := subcmd.Steps{
{
FunName: "启动监控",
Func: d.Payload.StartMonitor,
},
}
if err := steps.Run(); err != nil {
return err
}
logger.Info("start monitor success")
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package riakcmd

import (
"fmt"

"dbm-services/common/go-pubpkg/logger"
"dbm-services/riak/db-tools/dbactuator/internal/subcmd"
"dbm-services/riak/db-tools/dbactuator/pkg/components/riak"
"dbm-services/riak/db-tools/dbactuator/pkg/util"

"github.com/spf13/cobra"
)

// StopMonitorAct 关闭监控riak dbactor参数
type StopMonitorAct struct {
*subcmd.BaseOptions
Payload riak.StopMonitorComp
}

// NewStopMonitorCommand riak关闭监控
func NewStopMonitorCommand() *cobra.Command {
act := StopMonitorAct{
BaseOptions: subcmd.GBaseOptions,
}
cmd := &cobra.Command{
Use: "stop-monitor",
Short: "关闭监控",
Example: fmt.Sprintf("dbactuator riak stop-monitor %s", subcmd.CmdBaseExampleStr),
Run: func(cmd *cobra.Command, args []string) {
util.CheckErr(act.Validator())
util.CheckErr(act.Init())
util.CheckErr(act.Run())
},
}
return cmd
}

// Validator TODO
func (d *StopMonitorAct) Validator() error {
return d.BaseOptions.Validate()
}

// Init 反序列化并检查
func (d *StopMonitorAct) Init() error {
if err := d.DeserializeAndValidate(&d.Payload); err != nil {
logger.Error("DeserializeAndValidate err %s", err.Error())
return err
}
return nil
}

// Run 运行
func (d *StopMonitorAct) Run() error {
steps := subcmd.Steps{
{
FunName: "关闭监控",
Func: d.Payload.StopMonitor,
},
}
if err := steps.Run(); err != nil {
return err
}
logger.Info("stop monitor success")
return nil
}
Loading

0 comments on commit 3d0ffc1

Please sign in to comment.