diff --git a/api/grpc/mpi/v1/command.pb.go b/api/grpc/mpi/v1/command.pb.go index 2435a10191..5a12edcf0c 100644 --- a/api/grpc/mpi/v1/command.pb.go +++ b/api/grpc/mpi/v1/command.pb.go @@ -8,7 +8,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.33.0 +// protoc-gen-go v1.34.0 // protoc (unknown) // source: mpi/v1/command.proto diff --git a/api/grpc/mpi/v1/common.pb.go b/api/grpc/mpi/v1/common.pb.go index 10916dbeec..9c5b88ed08 100644 --- a/api/grpc/mpi/v1/common.pb.go +++ b/api/grpc/mpi/v1/common.pb.go @@ -5,7 +5,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.33.0 +// protoc-gen-go v1.34.0 // protoc (unknown) // source: mpi/v1/common.proto diff --git a/api/grpc/mpi/v1/files.pb.go b/api/grpc/mpi/v1/files.pb.go index 9902394151..dd34874539 100644 --- a/api/grpc/mpi/v1/files.pb.go +++ b/api/grpc/mpi/v1/files.pb.go @@ -5,7 +5,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.33.0 +// protoc-gen-go v1.34.0 // protoc (unknown) // source: mpi/v1/files.proto diff --git a/internal/service/instance/nginx_instance_service.go b/internal/service/instance/nginx_instance_service.go index 50828af279..df6c804003 100644 --- a/internal/service/instance/nginx_instance_service.go +++ b/internal/service/instance/nginx_instance_service.go @@ -37,6 +37,7 @@ type Info struct { ConfigureArgs map[string]interface{} ExePath string LoadableModules []string + DynamicModules []string } type Nginx struct { @@ -47,6 +48,11 @@ type NginxParameters struct { executer exec.ExecInterface } +const ( + withWithPrefix = "with-" + withModuleSuffix = "module" +) + func NewNginx(parameters NginxParameters) *Nginx { if parameters.executer == nil { parameters.executer = &exec.Exec{} @@ -116,6 +122,8 @@ func (n *Nginx) getInfo(ctx context.Context, nginxProcess *model.Process) (*Info loadableModules := getLoadableModules(nginxInfo) nginxInfo.LoadableModules = loadableModules + nginxInfo.DynamicModules = getDynamicModules(nginxInfo) + return nginxInfo, err } @@ -135,7 +143,7 @@ func convertInfoToProcess(nginxInfo Info) *v1.Instance { AccessLogs: []string{}, ErrorLogs: []string{}, LoadableModules: nginxInfo.LoadableModules, - DynamicModules: []string{}, + DynamicModules: nginxInfo.DynamicModules, }, }, } @@ -150,7 +158,7 @@ func convertInfoToProcess(nginxInfo Info) *v1.Instance { AccessLogs: []string{}, ErrorLogs: []string{}, LoadableModules: nginxInfo.LoadableModules, - DynamicModules: []string{}, + DynamicModules: nginxInfo.DynamicModules, PlusApi: "", }, }, @@ -297,6 +305,17 @@ func getLoadableModules(nginxInfo *Info) (modules []string) { return modules } +func getDynamicModules(nginxInfo *Info) (modules []string) { + configArgs := nginxInfo.ConfigureArgs + for arg := range configArgs { + if strings.HasPrefix(arg, withWithPrefix) && strings.HasSuffix(arg, withModuleSuffix) { + modules = append(modules, strings.TrimPrefix(arg, withWithPrefix)) + } + } + + return modules +} + // readDirectory returns a list of all files in the directory which match the extension func readDirectory(dir, extension string) (files []string, err error) { dirInfo, err := os.ReadDir(dir) diff --git a/internal/service/instance/nginx_instance_service_test.go b/internal/service/instance/nginx_instance_service_test.go index bde4bac1ec..99c3356b2a 100644 --- a/internal/service/instance/nginx_instance_service_test.go +++ b/internal/service/instance/nginx_instance_service_test.go @@ -9,9 +9,8 @@ import ( "bytes" "context" "fmt" - "log/slog" - "path" "path/filepath" + "sort" "strings" "testing" @@ -78,17 +77,21 @@ func TestGetInstances(t *testing.T) { ctx := context.Background() tempDir := t.TempDir() modulePath := tempDir + "/usr/lib/nginx/modules" + noModulesPath := t.TempDir() + "/usr/lib/nginx/modules" helpers.CreateDirWithErrorCheck(t, modulePath) defer helpers.RemoveFileWithErrorCheck(t, modulePath) + helpers.CreateDirWithErrorCheck(t, noModulesPath) + defer helpers.RemoveFileWithErrorCheck(t, noModulesPath) + testModule := helpers.CreateFileWithErrorCheck(t, modulePath, "test.so") defer helpers.RemoveFileWithErrorCheck(t, testModule.Name()) plusArgs := fmt.Sprintf(plusConfigArgs, modulePath) ossArgs := fmt.Sprintf(ossConfigArgs, modulePath) - noModuleArgs := path.Join(ossConfigArgs, t.TempDir()+"/usr/lib/nginx/modules") - slog.Info("", "", noModuleArgs) + noModuleArgs := fmt.Sprintf(ossConfigArgs, noModulesPath) + expectedModules := strings.ReplaceAll(filepath.Base(testModule.Name()), ".so", "") processes := []*model.Process{ @@ -165,6 +168,13 @@ func TestGetInstances(t *testing.T) { n := NewNginx(NginxParameters{executer: mockExec}) result := n.GetInstances(ctx, processes) + for _, instance := range result { + if instance.GetInstanceRuntime().GetNginxRuntimeInfo() != nil { + sort.Strings(instance.GetInstanceRuntime().GetNginxRuntimeInfo().GetDynamicModules()) + } else { + sort.Strings(instance.GetInstanceRuntime().GetNginxPlusRuntimeInfo().GetDynamicModules()) + } + } assert.Equal(tt, test.expected, result) }) } @@ -255,6 +265,8 @@ func TestGetInfo(t *testing.T) { "with-stream_ssl_preread_module": true, }, LoadableModules: []string{expectedModules}, + DynamicModules: protos.GetNginxOssInstance([]string{}).GetInstanceRuntime().GetNginxRuntimeInfo(). + GetDynamicModules(), }, }, { @@ -328,6 +340,8 @@ func TestGetInfo(t *testing.T) { "with-threads": true, }, LoadableModules: []string{expectedModules}, + DynamicModules: protos.GetNginxPlusInstance([]string{}).GetInstanceRuntime().GetNginxPlusRuntimeInfo(). + GetDynamicModules(), }, }, } @@ -339,6 +353,7 @@ func TestGetInfo(t *testing.T) { n := NewNginx(NginxParameters{executer: mockExec}) result, err := n.getInfo(ctx, test.process) + sort.Strings(result.DynamicModules) assert.Equal(tt, test.expected, result) require.NoError(tt, err) diff --git a/test/protos/instances.go b/test/protos/instances.go index f935e6182b..7d3d779965 100644 --- a/test/protos/instances.go +++ b/test/protos/instances.go @@ -37,7 +37,14 @@ func GetNginxOssInstance(expectedModules []string) *v1.Instance { AccessLogs: []string{}, ErrorLogs: []string{}, LoadableModules: expectedModules, - DynamicModules: []string{}, + DynamicModules: []string{ + "http_addition_module", "http_auth_request_module", "http_dav_module", + "http_degradation_module", "http_flv_module", "http_gunzip_module", "http_gzip_static_module", + "http_mp4_module", "http_random_index_module", "http_realip_module", "http_secure_link_module", + "http_slice_module", "http_ssl_module", "http_stub_status_module", "http_sub_module", + "http_v2_module", "mail_ssl_module", "stream_realip_module", "stream_ssl_module", + "stream_ssl_preread_module", + }, }, }, }, @@ -61,8 +68,18 @@ func GetNginxPlusInstance(expectedModules []string) *v1.Instance { AccessLogs: []string{}, ErrorLogs: []string{}, LoadableModules: expectedModules, - DynamicModules: []string{}, - PlusApi: "", + DynamicModules: []string{ + "http_addition_module", "http_auth_jwt_module", "http_auth_request_module", "http_dav_module", + "http_f4f_module", "http_flv_module", "http_gunzip_module", "http_gzip_static_module", + "http_hls_module", "http_mp4_module", "http_proxy_protocol_vendor_module", + "http_random_index_module", "http_realip_module", "http_secure_link_module", + "http_session_log_module", "http_slice_module", "http_ssl_module", "http_stub_status_module", + "http_sub_module", "http_v2_module", "http_v3_module", "mail_ssl_module", + "stream_mqtt_filter_module", "stream_mqtt_preread_module", + "stream_proxy_protocol_vendor_module", "stream_realip_module", "stream_ssl_module", + "stream_ssl_preread_module", + }, + PlusApi: "", }, }, },