Skip to content
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
15 changes: 13 additions & 2 deletions api/grpc/mpi/v1/files.pb.go

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

2 changes: 2 additions & 0 deletions api/grpc/mpi/v1/files.pb.validate.go

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

2 changes: 2 additions & 0 deletions api/grpc/mpi/v1/files.proto
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ message FileOverview {
repeated File files = 1;
// The configuration version of the current set of files
ConfigVersion config_version = 2;
// The config file path of an instance
string config_path = 3;
}

// Represents meta data about a file
Expand Down
1 change: 1 addition & 0 deletions docs/proto/protos.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ Represents a collection of files
| ----- | ---- | ----- | ----------- |
| files | [File](#mpi-v1-File) | repeated | A list of files |
| config_version | [ConfigVersion](#mpi-v1-ConfigVersion) | | The configuration version of the current set of files |
| config_path | [string](#string) | | The config file path of an instance |



Expand Down
4 changes: 3 additions & 1 deletion internal/datasource/config/nginx_config_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,22 @@ func (ncp *NginxConfigParser) Parse(ctx context.Context, instance *mpi.Instance)
return nil, err
}

return ncp.createNginxConfigContext(ctx, instance, payload)
return ncp.createNginxConfigContext(ctx, instance, payload, configPath)
}

//nolint:gocognit,gocyclo,revive,cyclop // cognitive complexity is 51
func (ncp *NginxConfigParser) createNginxConfigContext(
ctx context.Context,
instance *mpi.Instance,
payload *crossplane.Payload,
configPath string,
) (*model.NginxConfigContext, error) {
napSyslogServersFound := make(map[string]bool)
napEnabled := false

nginxConfigContext := &model.NginxConfigContext{
InstanceID: instance.GetInstanceMeta().GetInstanceId(),
ConfigPath: configPath,
PlusAPI: &model.APIDetails{
URL: "",
Listen: "",
Expand Down
9 changes: 7 additions & 2 deletions internal/datasource/nginx/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"bytes"
"context"
"fmt"
"log/slog"
"regexp"
"strings"

Expand Down Expand Up @@ -39,14 +40,18 @@ func ProcessInfo(ctx context.Context, proc *nginxprocess.Process,

confPath := ConfPathFromCommand(proc.Cmd)

var nginxInfo *model.ProcessInfo
nginxInfo := &model.ProcessInfo{}

outputBuffer, err := executer.RunCmd(ctx, exePath, "-V")
if err != nil {
return nil, err
}

nginxInfo = ParseNginxVersionCommandOutput(ctx, outputBuffer)
if outputBuffer == nil {
slog.WarnContext(ctx, "Unable to get NGINX version output")
} else {
nginxInfo = ParseNginxVersionCommandOutput(ctx, outputBuffer)
}

nginxInfo.ExePath = exePath
nginxInfo.ProcessID = proc.PID
Expand Down
6 changes: 4 additions & 2 deletions internal/file/file_manager_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ type (

fileServiceOperatorInterface interface {
File(ctx context.Context, file *mpi.File, fileActions map[string]*model.FileCache) error
UpdateOverview(ctx context.Context, instanceID string, filesToUpdate []*mpi.File, iteration int) error
UpdateOverview(ctx context.Context, instanceID string, filesToUpdate []*mpi.File, configPath string,
iteration int) error
ChunkedFile(ctx context.Context, file *mpi.File) error
IsConnected() bool
UpdateFile(
Expand Down Expand Up @@ -233,7 +234,8 @@ func (fms *FileManagerService) ConfigUpdate(ctx context.Context,
}

slog.InfoContext(ctx, "Updating overview after nginx config update")
err := fms.fileServiceOperator.UpdateOverview(ctx, nginxConfigContext.InstanceID, nginxConfigContext.Files, 0)
err := fms.fileServiceOperator.UpdateOverview(ctx, nginxConfigContext.InstanceID,
nginxConfigContext.Files, nginxConfigContext.ConfigPath, 0)
if err != nil {
slog.ErrorContext(
ctx,
Expand Down
7 changes: 5 additions & 2 deletions internal/file/file_service_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func (fso *FileServiceOperator) UpdateOverview(
ctx context.Context,
instanceID string,
filesToUpdate []*mpi.File,
configPath string,
iteration int,
) error {
correlationID := logger.CorrelationID(ctx)
Expand All @@ -127,6 +128,7 @@ func (fso *FileServiceOperator) UpdateOverview(
InstanceId: instanceID,
Version: files.GenerateConfigVersion(filesToUpdate),
},
ConfigPath: configPath,
},
}

Expand Down Expand Up @@ -178,7 +180,7 @@ func (fso *FileServiceOperator) UpdateOverview(
delta := files.ConvertToMapOfFiles(response.GetOverview().GetFiles())

if len(delta) != 0 {
return fso.updateFiles(ctx, delta, instanceID, iteration)
return fso.updateFiles(ctx, delta, instanceID, configPath, iteration)
}

return err
Expand Down Expand Up @@ -254,6 +256,7 @@ func (fso *FileServiceOperator) updateFiles(
ctx context.Context,
delta map[string]*mpi.File,
instanceID string,
configPath string,
iteration int,
) error {
diffFiles := slices.Collect(maps.Values(delta))
Expand All @@ -268,7 +271,7 @@ func (fso *FileServiceOperator) updateFiles(
iteration++
slog.InfoContext(ctx, "Updating file overview after file updates", "attempt_number", iteration)

return fso.UpdateOverview(ctx, instanceID, diffFiles, iteration)
return fso.UpdateOverview(ctx, instanceID, diffFiles, configPath, iteration)
}

func (fso *FileServiceOperator) sendUpdateFileRequest(
Expand Down
4 changes: 2 additions & 2 deletions internal/file/file_service_operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestFileServiceOperator_UpdateOverview(t *testing.T) {
{
FileMeta: fileMeta,
},
}, 0)
}, filePath, 0)

require.NoError(t, err)
assert.Equal(t, 2, fakeFileServiceClient.UpdateOverviewCallCount())
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestFileServiceOperator_UpdateOverview_MaxIterations(t *testing.T) {
{
FileMeta: fileMeta,
},
}, 0)
}, filePath, 0)

require.Error(t, err)
assert.Equal(t, "too many UpdateOverview attempts", err.Error())
Expand Down
4 changes: 4 additions & 0 deletions internal/model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type NginxConfigContext struct {
StubStatus *APIDetails
PlusAPI *APIDetails
InstanceID string
ConfigPath string
Files []*v1.File
AccessLogs []*AccessLog
ErrorLogs []*ErrorLog
Expand Down Expand Up @@ -97,6 +98,9 @@ func (ncc *NginxConfigContext) Equal(otherNginxConfigContext *NginxConfigContext
}
}

if ncc.ConfigPath != otherNginxConfigContext.ConfigPath {
return false
}
if ncc.InstanceID != otherNginxConfigContext.InstanceID {
return false
}
Expand Down
6 changes: 6 additions & 0 deletions internal/resource/nginx_instance_operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,14 @@ func TestInstanceOperator_Reload(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
versionOut := `nginx version: nginx/1.25.3
built by clang 14.0.0 (clang-1400.0.29.202)
built with OpenSSL 1.1.1s 1 Nov 2022 (running with OpenSSL 1.1.1t 7 Feb 2023)
TLS SNI support enabled
configure arguments: ` + ossConfigArgs
mockExec := &execfakes.FakeExecInterface{}
mockExec.KillProcessReturns(test.err)
mockExec.RunCmdReturns(bytes.NewBufferString(versionOut), nil)

instance := protos.NginxOssInstance([]string{})

Expand Down