Skip to content

Commit c2b2966

Browse files
authored
Added API Action Request (#951)
* add api action request
1 parent 6a82a2e commit c2b2966

File tree

15 files changed

+2141
-294
lines changed

15 files changed

+2141
-294
lines changed

api/grpc/mpi/v1/command.pb.go

Lines changed: 544 additions & 269 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/grpc/mpi/v1/command.pb.validate.go

Lines changed: 477 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/grpc/mpi/v1/command.proto

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,37 @@ message ConfigUploadRequest {
191191
}
192192

193193
// Perform an associated API action on an instance
194-
message APIActionRequest {}
194+
message APIActionRequest {
195+
// the identifier associated with the instance
196+
string instance_id = 1;
197+
// types of API actions possible
198+
oneof action {
199+
NGINXPlusAction nginx_plus_action = 2;
200+
}
201+
}
202+
203+
// Perform an action using the NGINX Plus API on an instance
204+
message NGINXPlusAction {
205+
// types of actions possible with NGINX Plus API
206+
oneof action {
207+
UpdateHTTPUpstreamServers update_http_upstream_servers = 2;
208+
GetHTTPUpstreamServers get_http_upstream_servers = 3;
209+
}
210+
}
211+
212+
// Update HTTP Upstream Servers for an instance
213+
message UpdateHTTPUpstreamServers {
214+
// the name of the upstream to update
215+
string http_upstream_name = 1;
216+
// a list of upstream servers
217+
repeated google.protobuf.Struct servers = 2;
218+
}
219+
220+
// Get HTTP Upstream Servers for an instance
221+
message GetHTTPUpstreamServers {
222+
// the name of the upstream
223+
string http_upstream_name = 1;
224+
}
195225

196226
// Request an update on a particular command
197227
message CommandStatusRequest {}

docs/proto/protos.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
- [CreateConnectionResponse](#mpi-v1-CreateConnectionResponse)
5252
- [DataPlaneResponse](#mpi-v1-DataPlaneResponse)
5353
- [FileServer](#mpi-v1-FileServer)
54+
- [GetHTTPUpstreamServers](#mpi-v1-GetHTTPUpstreamServers)
5455
- [HealthRequest](#mpi-v1-HealthRequest)
5556
- [HostInfo](#mpi-v1-HostInfo)
5657
- [Instance](#mpi-v1-Instance)
@@ -62,6 +63,7 @@
6263
- [InstanceRuntime](#mpi-v1-InstanceRuntime)
6364
- [ManagementPlaneRequest](#mpi-v1-ManagementPlaneRequest)
6465
- [MetricsServer](#mpi-v1-MetricsServer)
66+
- [NGINXPlusAction](#mpi-v1-NGINXPlusAction)
6567
- [NGINXPlusRuntimeInfo](#mpi-v1-NGINXPlusRuntimeInfo)
6668
- [NGINXRuntimeInfo](#mpi-v1-NGINXRuntimeInfo)
6769
- [ReleaseInfo](#mpi-v1-ReleaseInfo)
@@ -71,6 +73,7 @@
7173
- [UpdateDataPlaneHealthResponse](#mpi-v1-UpdateDataPlaneHealthResponse)
7274
- [UpdateDataPlaneStatusRequest](#mpi-v1-UpdateDataPlaneStatusRequest)
7375
- [UpdateDataPlaneStatusResponse](#mpi-v1-UpdateDataPlaneStatusResponse)
76+
- [UpdateHTTPUpstreamServers](#mpi-v1-UpdateHTTPUpstreamServers)
7477

7578
- [InstanceHealth.InstanceHealthStatus](#mpi-v1-InstanceHealth-InstanceHealthStatus)
7679
- [InstanceMeta.InstanceType](#mpi-v1-InstanceMeta-InstanceType)
@@ -601,6 +604,12 @@ and recommendations outlined in https://static.sched.com/hosted_files/kccncna17/
601604
Perform an associated API action on an instance
602605

603606

607+
| Field | Type | Label | Description |
608+
| ----- | ---- | ----- | ----------- |
609+
| instance_id | [string](#string) | | the identifier associated with the instance |
610+
| nginx_plus_action | [NGINXPlusAction](#mpi-v1-NGINXPlusAction) | | |
611+
612+
604613

605614

606615

@@ -773,6 +782,21 @@ The file settings associated with file server for configurations
773782

774783

775784

785+
<a name="mpi-v1-GetHTTPUpstreamServers"></a>
786+
787+
### GetHTTPUpstreamServers
788+
Get HTTP Upstream Servers for an instance
789+
790+
791+
| Field | Type | Label | Description |
792+
| ----- | ---- | ----- | ----------- |
793+
| http_upstream_name | [string](#string) | | the name of the upstream |
794+
795+
796+
797+
798+
799+
776800
<a name="mpi-v1-HealthRequest"></a>
777801

778802
### HealthRequest
@@ -943,6 +967,22 @@ The metrics settings associated with origins (sources) of the metrics and destin
943967

944968

945969

970+
<a name="mpi-v1-NGINXPlusAction"></a>
971+
972+
### NGINXPlusAction
973+
Perform an action using the NGINX Plus API on an instance
974+
975+
976+
| Field | Type | Label | Description |
977+
| ----- | ---- | ----- | ----------- |
978+
| update_http_upstream_servers | [UpdateHTTPUpstreamServers](#mpi-v1-UpdateHTTPUpstreamServers) | | |
979+
| get_http_upstream_servers | [GetHTTPUpstreamServers](#mpi-v1-GetHTTPUpstreamServers) | | |
980+
981+
982+
983+
984+
985+
946986
<a name="mpi-v1-NGINXPlusRuntimeInfo"></a>
947987

948988
### NGINXPlusRuntimeInfo
@@ -1080,6 +1120,22 @@ Respond to a UpdateDataPlaneStatusRequest - intentionally empty
10801120

10811121

10821122

1123+
1124+
<a name="mpi-v1-UpdateHTTPUpstreamServers"></a>
1125+
1126+
### UpdateHTTPUpstreamServers
1127+
Update HTTP Upstream Servers for an instance
1128+
1129+
1130+
| Field | Type | Label | Description |
1131+
| ----- | ---- | ----- | ----------- |
1132+
| http_upstream_name | [string](#string) | | the name of the upstream to update |
1133+
| servers | [google.protobuf.Struct](#google-protobuf-Struct) | repeated | a list of upstream servers |
1134+
1135+
1136+
1137+
1138+
10831139

10841140

10851141

internal/bus/topics.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ const (
2323
RollbackWriteTopic = "rollback-write"
2424
DataPlaneHealthRequestTopic = "data-plane-health-request"
2525
DataPlaneHealthResponseTopic = "data-plane-health-response"
26+
APIActionRequestTopic = "api-action-request"
2627
)

internal/command/command_plugin.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,40 @@ func (cp *CommandPlugin) monitorSubscribeChannel(ctx context.Context) {
182182
cp.handleConfigApplyRequest(newCtx, message)
183183
case *mpi.ManagementPlaneRequest_HealthRequest:
184184
cp.handleHealthRequest(newCtx)
185+
case *mpi.ManagementPlaneRequest_ActionRequest:
186+
cp.handleAPIActionRequest(newCtx, message)
185187
default:
186188
slog.DebugContext(newCtx, "Management plane request not implemented yet")
187189
}
188190
}
189191
}
190192
}
191193

194+
func (cp *CommandPlugin) handleAPIActionRequest(ctx context.Context, message *mpi.ManagementPlaneRequest) {
195+
if cp.config.IsFeatureEnabled(pkgConfig.FeatureAPIAction) {
196+
cp.messagePipe.Process(ctx, &bus.Message{Topic: bus.APIActionRequestTopic, Data: message})
197+
} else {
198+
slog.WarnContext(
199+
ctx,
200+
"API Action Request feature disabled. Unable to process API action request",
201+
"request", message,
202+
)
203+
204+
err := cp.commandService.SendDataPlaneResponse(ctx, &mpi.DataPlaneResponse{
205+
MessageMeta: message.GetMessageMeta(),
206+
CommandResponse: &mpi.CommandResponse{
207+
Status: mpi.CommandResponse_COMMAND_STATUS_FAILURE,
208+
Message: "API action failed",
209+
Error: "API action feature is disabled",
210+
},
211+
InstanceId: message.GetActionRequest().GetInstanceId(),
212+
})
213+
if err != nil {
214+
slog.ErrorContext(ctx, "Unable to send data plane response", "error", err)
215+
}
216+
}
217+
}
218+
192219
func (cp *CommandPlugin) handleConfigApplyRequest(newCtx context.Context, message *mpi.ManagementPlaneRequest) {
193220
if cp.config.IsFeatureEnabled(pkgConfig.FeatureConfiguration) {
194221
cp.messagePipe.Process(newCtx, &bus.Message{Topic: bus.ConfigApplyRequestTopic, Data: message})
@@ -206,7 +233,7 @@ func (cp *CommandPlugin) handleConfigApplyRequest(newCtx context.Context, messag
206233
Message: "Config apply failed",
207234
Error: "Configuration feature is disabled",
208235
},
209-
InstanceId: message.GetConfigUploadRequest().GetOverview().GetConfigVersion().GetInstanceId(),
236+
InstanceId: message.GetConfigApplyRequest().GetOverview().GetConfigVersion().GetInstanceId(),
210237
})
211238
if err != nil {
212239
slog.ErrorContext(newCtx, "Unable to send data plane response", "error", err)

0 commit comments

Comments
 (0)