Skip to content

Allow multiple management planes #1124

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

Open
wants to merge 10 commits into
base: add-auxiliary-command-server-proto
Choose a base branch
from

Conversation

aphralG
Copy link
Contributor

@aphralG aphralG commented Jun 12, 2025

Proposed changes

Add Auxiliary Command Server block to agent config.
Modified Command plugin to take a command server type so two can be created one for each Management plane
Added CommandServerType to context for management plane sepcific messages "command" or "auxiliary"

auxiliary_command:
    server: 
        host: "second.management.plane"
        port: 9999
    auth: 
        token: "1234"
        tokenpath: "path/to/my_token"
    tls: 
        cert: "some.cert"
        key: "some.key"
        ca: "some.ca"
        skip_verify: false
        server_name: "server-name"

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING document
  • I have run make install-tools and have attached any dependency changes to this pull request
  • If applicable, I have added tests that prove my fix is effective or that my feature works
  • If applicable, I have checked that any relevant tests pass after adding my changes
  • If applicable, I have updated any relevant documentation (README.md)
  • If applicable, I have tested my cross-platform changes on Ubuntu 22, Redhat 8, SUSE 15 and FreeBSD 13

@aphralG aphralG self-assigned this Jun 12, 2025
@aphralG aphralG requested a review from a team as a code owner June 12, 2025 15:43
@github-actions github-actions bot added the chore Pull requests for routine tasks label Jun 12, 2025
conn grpc.GrpcConnectionInterface
commandService commandService
subscribeChannel chan *mpi.ManagementPlaneRequest
commandServerType string
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could this be an enum?


cp.messagePipe = messagePipe
cp.commandService = NewCommandService(cp.conn.CommandServiceClient(), cp.config, cp.subscribeChannel)

go cp.monitorSubscribeChannel(ctx)
newCtx := context.WithValue(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you create the new context at the start of the function? Just so it can be used for the debug message above as well.

@@ -33,6 +34,7 @@ var (
}

CorrelationIDContextKey = contextKey(CorrelationIDKey)
ServerTypeContextKey = contextKey(ServerTypeKey)
)

type (
Copy link
Collaborator

Choose a reason for hiding this comment

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

On line 77 can you add ServerTypeContextKey to the list pf handlers so that the server type gets automatically added to the log messages?

slog.DebugContext(ctx, "Command plugin received unknown topic", "topic", msg.Topic)
}
} else {
slog.Info("Sever type is not right ignoring message", "command_server_type",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you remove this info log as it will spam the log file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ya this was supposed to be removed was just using for testing

@@ -226,12 +248,24 @@ func (cp *CommandPlugin) monitorSubscribeChannel(ctx context.Context) {
slog.InfoContext(ctx, "Received management plane config upload request")
cp.handleConfigUploadRequest(newCtx, message)
case *mpi.ManagementPlaneRequest_ConfigApplyRequest:
if cp.commandServerType != "command" {
slog.WarnContext(newCtx, "Auxiliary command server can not perform config apply",
"command_server_type", cp.commandServerType)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Think you need to send a failure response back to the management plane here as well

slog.InfoContext(ctx, "Received management plane config apply request")
cp.handleConfigApplyRequest(newCtx, message)
case *mpi.ManagementPlaneRequest_HealthRequest:
slog.InfoContext(ctx, "Received management plane health request")
cp.handleHealthRequest(newCtx)
case *mpi.ManagementPlaneRequest_ActionRequest:
if cp.commandServerType != "command" {
slog.WarnContext(newCtx, "Auxiliary command server can not perform api action",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as comment above

@@ -261,6 +261,7 @@ func (cs *CommandService) UpdateClient(ctx context.Context, client mpi.CommandSe
cs.subscribeClientMutex.Unlock()

cs.isConnected.Store(false)
// Will this have the sever type ?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you remove comment?

// Followup PR to add read plugin eventually
}
} else {
slog.InfoContext(ctx, "Agent is not connected to an auxiliary management plane. "+
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if this log message will cause confusion to the end user. Maybe we should just have a debug message for when an auxiliary command server isn'r configured

@@ -336,3 +395,7 @@ func (cp *CommandPlugin) createDataPlaneResponse(correlationID string, status mp
},
}
}

func (s ServerType) 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.

Can you move this to the top near the ServerType declaration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved all the SeverType code into the model package in server.go

@@ -59,6 +60,26 @@ func addCommandAndFilePlugins(ctx context.Context, plugins []bus.Plugin, agentCo
return plugins
}

func addAuxiliaryCommandAndFilePlugins(ctx context.Context, plugins []bus.Plugin,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be addAuxiliaryCommandPlugin?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, the read only file plugin is added to this function in the next PR

@dhurley dhurley added the v3.x Issues and Pull Requests related to the major version v3 label Jun 19, 2025
@aphralG aphralG requested review from dhurley and sean-breen June 23, 2025 10:21

return nil
}

func (cp *CommandPlugin) Close(ctx context.Context) error {
slog.InfoContext(ctx, "Closing command plugin")
slog.InfoContext(ctx, "Closing command plugin", "command_server_type", cp.commandServerType.String())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you update the context with the server type since the context is also being passed to other functions?

ctx,
logger.ServerTypeContextKey, slog.Any(logger.ServerTypeKey, cp.commandServerType.String()),
)
slog.DebugContext(newCtx, "Starting command plugin", "command_server_type", cp.commandServerType.String())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
slog.DebugContext(newCtx, "Starting command plugin", "command_server_type", cp.commandServerType.String())
slog.DebugContext(newCtx, "Starting command plugin")

Server type is already being added by the logger

cp.processDataPlaneResponse(ctx, msg)
default:
slog.DebugContext(ctx, "Command plugin received unknown topic", "topic", msg.Topic)
slog.DebugContext(ctx, "Processing command", "command_server_type", logger.ServerType(ctx))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
slog.DebugContext(ctx, "Processing command", "command_server_type", logger.ServerType(ctx))
slog.DebugContext(ctx, "Processing command")

Comment on lines 186 to 187
slog.ErrorContext(ctx, "Unable to update data plane health", "error", err,
"command_server_type", cp.commandServerType.String())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
slog.ErrorContext(ctx, "Unable to update data plane health", "error", err,
"command_server_type", cp.commandServerType.String())
slog.ErrorContext(ctx, "Unable to update data plane health", "error", err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

slog.DebugContext(ctx, "Command plugin received unknown topic", "topic", msg.Topic)
slog.DebugContext(ctx, "Processing command")

if logger.ServerType(ctx) == cp.commandServerType.String() || logger.ServerType(ctx) == "" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If logger.ServerType(ctx) == "" then we should create a new context with the serverType.

Message: message,
Error: "Can not perform write action as auxiliary command server",
},
InstanceId: request.GetActionRequest().GetInstanceId(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

The instance ID is got in a different way if its a config apply request

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Pull requests for routine tasks v3.x Issues and Pull Requests related to the major version v3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants