Skip to content

Commit 08eee77

Browse files
authored
Add config path to FileOverview (#1220)
1 parent 5ea63ea commit 08eee77

File tree

11 files changed

+49
-11
lines changed

11 files changed

+49
-11
lines changed

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

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

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

Lines changed: 2 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/files.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ message FileOverview {
120120
repeated File files = 1;
121121
// The configuration version of the current set of files
122122
ConfigVersion config_version = 2;
123+
// The config file path of an instance
124+
string config_path = 3;
123125
}
124126

125127
// Represents meta data about a file

docs/proto/protos.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ Represents a collection of files
416416
| ----- | ---- | ----- | ----------- |
417417
| files | [File](#mpi-v1-File) | repeated | A list of files |
418418
| config_version | [ConfigVersion](#mpi-v1-ConfigVersion) | | The configuration version of the current set of files |
419+
| config_path | [string](#string) | | The config file path of an instance |
419420

420421

421422

internal/datasource/config/nginx_config_parser.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,22 @@ func (ncp *NginxConfigParser) Parse(ctx context.Context, instance *mpi.Instance)
9999
return nil, err
100100
}
101101

102-
return ncp.createNginxConfigContext(ctx, instance, payload)
102+
return ncp.createNginxConfigContext(ctx, instance, payload, configPath)
103103
}
104104

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

114115
nginxConfigContext := &model.NginxConfigContext{
115116
InstanceID: instance.GetInstanceMeta().GetInstanceId(),
117+
ConfigPath: configPath,
116118
PlusAPI: &model.APIDetails{
117119
URL: "",
118120
Listen: "",

internal/datasource/nginx/process.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"bytes"
1111
"context"
1212
"fmt"
13+
"log/slog"
1314
"regexp"
1415
"strings"
1516

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

4041
confPath := ConfPathFromCommand(proc.Cmd)
4142

42-
var nginxInfo *model.ProcessInfo
43+
nginxInfo := &model.ProcessInfo{}
4344

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

49-
nginxInfo = ParseNginxVersionCommandOutput(ctx, outputBuffer)
50+
if outputBuffer == nil {
51+
slog.WarnContext(ctx, "Unable to get NGINX version output")
52+
} else {
53+
nginxInfo = ParseNginxVersionCommandOutput(ctx, outputBuffer)
54+
}
5055

5156
nginxInfo.ExePath = exePath
5257
nginxInfo.ProcessID = proc.PID

internal/file/file_manager_service.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ type (
5858

5959
fileServiceOperatorInterface interface {
6060
File(ctx context.Context, file *mpi.File, fileActions map[string]*model.FileCache) error
61-
UpdateOverview(ctx context.Context, instanceID string, filesToUpdate []*mpi.File, iteration int) error
61+
UpdateOverview(ctx context.Context, instanceID string, filesToUpdate []*mpi.File, configPath string,
62+
iteration int) error
6263
ChunkedFile(ctx context.Context, file *mpi.File) error
6364
IsConnected() bool
6465
UpdateFile(
@@ -233,7 +234,8 @@ func (fms *FileManagerService) ConfigUpdate(ctx context.Context,
233234
}
234235

235236
slog.InfoContext(ctx, "Updating overview after nginx config update")
236-
err := fms.fileServiceOperator.UpdateOverview(ctx, nginxConfigContext.InstanceID, nginxConfigContext.Files, 0)
237+
err := fms.fileServiceOperator.UpdateOverview(ctx, nginxConfigContext.InstanceID,
238+
nginxConfigContext.Files, nginxConfigContext.ConfigPath, 0)
237239
if err != nil {
238240
slog.ErrorContext(
239241
ctx,

internal/file/file_service_operator.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ func (fso *FileServiceOperator) UpdateOverview(
104104
ctx context.Context,
105105
instanceID string,
106106
filesToUpdate []*mpi.File,
107+
configPath string,
107108
iteration int,
108109
) error {
109110
correlationID := logger.CorrelationID(ctx)
@@ -127,6 +128,7 @@ func (fso *FileServiceOperator) UpdateOverview(
127128
InstanceId: instanceID,
128129
Version: files.GenerateConfigVersion(filesToUpdate),
129130
},
131+
ConfigPath: configPath,
130132
},
131133
}
132134

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

180182
if len(delta) != 0 {
181-
return fso.updateFiles(ctx, delta, instanceID, iteration)
183+
return fso.updateFiles(ctx, delta, instanceID, configPath, iteration)
182184
}
183185

184186
return err
@@ -254,6 +256,7 @@ func (fso *FileServiceOperator) updateFiles(
254256
ctx context.Context,
255257
delta map[string]*mpi.File,
256258
instanceID string,
259+
configPath string,
257260
iteration int,
258261
) error {
259262
diffFiles := slices.Collect(maps.Values(delta))
@@ -268,7 +271,7 @@ func (fso *FileServiceOperator) updateFiles(
268271
iteration++
269272
slog.InfoContext(ctx, "Updating file overview after file updates", "attempt_number", iteration)
270273

271-
return fso.UpdateOverview(ctx, instanceID, diffFiles, iteration)
274+
return fso.UpdateOverview(ctx, instanceID, diffFiles, configPath, iteration)
272275
}
273276

274277
func (fso *FileServiceOperator) sendUpdateFileRequest(

internal/file/file_service_operator_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestFileServiceOperator_UpdateOverview(t *testing.T) {
5353
{
5454
FileMeta: fileMeta,
5555
},
56-
}, 0)
56+
}, filePath, 0)
5757

5858
require.NoError(t, err)
5959
assert.Equal(t, 2, fakeFileServiceClient.UpdateOverviewCallCount())
@@ -91,7 +91,7 @@ func TestFileServiceOperator_UpdateOverview_MaxIterations(t *testing.T) {
9191
{
9292
FileMeta: fileMeta,
9393
},
94-
}, 0)
94+
}, filePath, 0)
9595

9696
require.Error(t, err)
9797
assert.Equal(t, "too many UpdateOverview attempts", err.Error())

internal/model/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type NginxConfigContext struct {
1515
StubStatus *APIDetails
1616
PlusAPI *APIDetails
1717
InstanceID string
18+
ConfigPath string
1819
Files []*v1.File
1920
AccessLogs []*AccessLog
2021
ErrorLogs []*ErrorLog
@@ -97,6 +98,9 @@ func (ncc *NginxConfigContext) Equal(otherNginxConfigContext *NginxConfigContext
9798
}
9899
}
99100

101+
if ncc.ConfigPath != otherNginxConfigContext.ConfigPath {
102+
return false
103+
}
100104
if ncc.InstanceID != otherNginxConfigContext.InstanceID {
101105
return false
102106
}

0 commit comments

Comments
 (0)