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

Agent startup #108

Merged
merged 3 commits into from
Nov 16, 2022
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
32 changes: 27 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ func main() {
sdkGRPC.InitMeta(loadedConfig.ClientID, loadedConfig.CloudAccountID)

controller, commander, reporter := createGrpcClients(ctx, loadedConfig)
if err := controller.Connect(); err != nil {
log.Warnf("Unable to connect to control plane: %v", err)
return

if controller != nil {
if err := controller.Connect(); err != nil {
log.Warnf("Unable to connect to control plane: %v", err)
return
}
}

binary := core.NewNginxBinary(env, loadedConfig)
Expand Down Expand Up @@ -131,7 +134,16 @@ func handleSignals(
}()
}

func connectionUnavilable(loadedConfig *config.Config) bool {
return loadedConfig.Server.Host == "" || loadedConfig.Server.GrpcPort == 0
}

func createGrpcClients(ctx context.Context, loadedConfig *config.Config) (client.Controller, client.Commander, client.MetricReporter) {
if connectionUnavilable(loadedConfig) {
log.Infof("GRPC clients not created")
return nil, nil, nil
oliveromahony marked this conversation as resolved.
Show resolved Hide resolved
}

grpcDialOptions := setDialOptions(loadedConfig)
secureMetricsDialOpts, err := sdkGRPC.SecureDialOptions(
loadedConfig.TLS.Enable,
Expand Down Expand Up @@ -175,11 +187,21 @@ func createGrpcClients(ctx context.Context, loadedConfig *config.Config) (client
func loadPlugins(commander client.Commander, binary *core.NginxBinaryType, env *core.EnvironmentType, reporter client.MetricReporter, loadedConfig *config.Config) []core.Plugin {
var corePlugins []core.Plugin

if commander != nil {
corePlugins = append(corePlugins,
plugins.NewCommander(commander, loadedConfig),
)
}

if reporter != nil {
corePlugins = append(corePlugins,
plugins.NewMetricsSender(reporter),
)
}

corePlugins = append(corePlugins,
plugins.NewConfigReader(loadedConfig),
plugins.NewNginx(commander, binary, env, loadedConfig),
plugins.NewCommander(commander, loadedConfig),
plugins.NewMetricsSender(reporter),
plugins.NewOneTimeRegistration(loadedConfig, binary, env, sdkGRPC.NewMessageMeta(uuid.NewString()), version),
plugins.NewMetrics(loadedConfig, env, binary),
plugins.NewMetricsThrottle(loadedConfig, env),
Expand Down
4 changes: 0 additions & 4 deletions src/core/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ var (
Path: "/var/log/nginx-agent",
},
Server: Server{
Host: "127.0.0.1",
GrpcPort: 443,
Command: "",
Metrics: "",
// token needs to be validated on the server side - can be overridden by the config value or the cli / environment variable
Expand Down Expand Up @@ -200,12 +198,10 @@ var (
&StringFlag{
Name: ServerHost,
Usage: "The IP address of the server host. IPv4 addresses and hostnames are supported.",
DefaultValue: Defaults.Server.Host,
},
&IntFlag{
Name: ServerGrpcport,
Usage: "The desired GRPC port to use for nginx-agent traffic.",
DefaultValue: Defaults.Server.GrpcPort,
},
&StringFlag{
Name: ServerToken,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.