Skip to content

Commit

Permalink
feat: configurable controller endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: xiayu.lyt <xiayu.lyt@alibaba-inc.com>
  • Loading branch information
Lyt99 committed Jan 3, 2025
1 parent 05c2d69 commit 7c55732
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions pkg/exporter/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type InspServerConfig struct {

Address string `yaml:"address" mapstructure:"address" json:"address"`
EnableController bool `yaml:"enableController" mapstructure:"enableController" json:"enableController"`
ControllerAddr string `yaml:"controllerAddr" mapstructure:"controllerAddr" json:"controllerAddr"`
MetricsConfig MetricsConfig `yaml:"metrics" mapstructure:"metrics" json:"metrics"`
EventConfig EventConfig `yaml:"event" mapstructure:"event" json:"event"`
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/exporter/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ var (
defer nettop.StopCache()

if cfg.EnableController {
if err := task_agent.NewTaskAgent().Run(); err != nil {
if cfg.ControllerAddr == "" {
log.Infof("controller address is empty, use dns:controller:10263 as default")
cfg.ControllerAddr = "dns:controller:10263"
}
if err := task_agent.NewTaskAgent(cfg.ControllerAddr).Run(); err != nil {
log.Errorf("failed start agent: %v", err)
return
}
Expand Down
24 changes: 11 additions & 13 deletions pkg/exporter/task-agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package taskagent
import (
"context"
"fmt"
"os"
"time"

"google.golang.org/grpc/codes"
Expand All @@ -17,26 +16,24 @@ import (
"google.golang.org/grpc"
)

var (
//fixme replace to endpoint discovery
controllerAddr = os.Getenv("CONTROLLER_SERVICE_HOST") + ":10263"
//controllerAddr = "127.0.0.1:10263"
)

func NewTaskAgent() *Agent {
return &Agent{NodeName: nettop.GetNodeName()}
func NewTaskAgent(controllerAddr string) *Agent {
return &Agent{
NodeName: nettop.GetNodeName(),
controllerAddr: controllerAddr,
}
}

type Agent struct {
NodeName string
grpcClient rpc.ControllerRegisterServiceClient
ipCacheClient rpc.IPCacheServiceClient
NodeName string
grpcClient rpc.ControllerRegisterServiceClient
ipCacheClient rpc.IPCacheServiceClient
controllerAddr string
}

func (a *Agent) rpcConnect() (*grpc.ClientConn, error) {
var opts []grpc.CallOption
opts = append(opts, grpc.MaxCallSendMsgSize(102*1024*1024))
return grpc.Dial(controllerAddr, grpc.WithDefaultCallOptions(opts...),
return grpc.Dial(a.controllerAddr, grpc.WithDefaultCallOptions(opts...),
grpc.WithTransportCredentials(insecure.NewCredentials()))
}

Expand All @@ -48,6 +45,7 @@ func retry(msg string, maxAttempts int, work func() error) error {
if err == nil {
return nil
}
log.Errorf("retry %s error: %s", msg, err)
attempts++
if maxAttempts > 0 && attempts >= maxAttempts {
return fmt.Errorf("failed %s after %d attempts", msg, attempts)
Expand Down

0 comments on commit 7c55732

Please sign in to comment.