Skip to content

Commit 975cdd3

Browse files
committed
Make config path optional and make metrics optional in OTel collector
1 parent 2307225 commit 975cdd3

14 files changed

+166
-149
lines changed

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

Lines changed: 133 additions & 131 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: 4 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/command.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ message InstanceRuntime {
277277
// the binary path location
278278
string binary_path = 2 [(buf.validate.field).string.prefix = "/"];
279279
// the config path location
280-
string config_path = 3 [(buf.validate.field).string.prefix = "/"];
280+
optional string config_path = 3 [(buf.validate.field).string.prefix = "/"];
281281
// more detailed runtime objects
282282
oneof details {
283283
// NGINX runtime configuration settings like stub_status, usually read from the NGINX config or NGINX process

docs/proto/protos.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ Meta-information relating to the reported instance
927927
| ----- | ---- | ----- | ----------- |
928928
| process_id | [int32](#int32) | | the process identifier |
929929
| binary_path | [string](#string) | | the binary path location |
930-
| config_path | [string](#string) | | the config path location |
930+
| config_path | [string](#string) | optional | the config path location |
931931
| nginx_runtime_info | [NGINXRuntimeInfo](#mpi-v1-NGINXRuntimeInfo) | | NGINX runtime configuration settings like stub_status, usually read from the NGINX config or NGINX process |
932932
| nginx_plus_runtime_info | [NGINXPlusRuntimeInfo](#mpi-v1-NGINXPlusRuntimeInfo) | | NGINX Plus runtime configuration settings like api value, usually read from the NGINX config, NGINX process or NGINX Plus API |
933933
| nginx_app_protect_runtime_info | [NGINXAppProtectRuntimeInfo](#mpi-v1-NGINXAppProtectRuntimeInfo) | | NGINX App Protect runtime information |

internal/collector/otelcol.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ service:
214214
{{- end}}
215215
{{- end}}
216216
pipelines:
217+
{{- if or (ne .Receivers.HostMetrics nil) (gt (len .Receivers.OtlpReceivers) 0) (gt (len .Receivers.NginxReceivers) 0) (gt (len .Receivers.NginxPlusReceivers) 0) }}
217218
metrics:
218219
receivers:
219220
{{- if ne .Receivers.HostMetrics nil }}
@@ -252,6 +253,7 @@ service:
252253
{{- if ne .Exporters.Debug nil }}
253254
- debug
254255
{{- end }}
256+
{{- end }}
255257
{{- if ne .Receivers.TcplogReceivers nil }}
256258
logs:
257259
receivers:

internal/resource/resource_plugin_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ import (
3737
func TestResource_Process(t *testing.T) {
3838
ctx := context.Background()
3939

40+
configPath := protos.GetNginxOssInstance([]string{}).GetInstanceRuntime().GetConfigPath()
41+
4042
updatedInstance := &mpi.Instance{
4143
InstanceConfig: protos.GetNginxOssInstance([]string{}).GetInstanceConfig(),
4244
InstanceMeta: protos.GetNginxOssInstance([]string{}).GetInstanceMeta(),
4345
InstanceRuntime: &mpi.InstanceRuntime{
4446
ProcessId: 56789,
4547
BinaryPath: protos.GetNginxOssInstance([]string{}).GetInstanceRuntime().GetBinaryPath(),
46-
ConfigPath: protos.GetNginxOssInstance([]string{}).GetInstanceRuntime().GetConfigPath(),
48+
ConfigPath: &configPath,
4749
Details: protos.GetNginxOssInstance([]string{}).GetInstanceRuntime().GetDetails(),
4850
},
4951
}

internal/resource/resource_service_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,15 @@ func TestResourceService_AddInstance(t *testing.T) {
6868

6969
func TestResourceService_UpdateInstance(t *testing.T) {
7070
ctx := context.Background()
71+
configPath := protos.GetNginxOssInstance([]string{}).GetInstanceRuntime().GetConfigPath()
7172

7273
updatedInstance := &v1.Instance{
7374
InstanceConfig: protos.GetNginxOssInstance([]string{}).GetInstanceConfig(),
7475
InstanceMeta: protos.GetNginxOssInstance([]string{}).GetInstanceMeta(),
7576
InstanceRuntime: &v1.InstanceRuntime{
7677
ProcessId: 56789,
7778
BinaryPath: protos.GetNginxOssInstance([]string{}).GetInstanceRuntime().GetBinaryPath(),
78-
ConfigPath: protos.GetNginxOssInstance([]string{}).GetInstanceRuntime().GetConfigPath(),
79+
ConfigPath: &configPath,
7980
Details: protos.GetNginxOssInstance([]string{}).GetInstanceRuntime().GetDetails(),
8081
},
8182
}

internal/watcher/instance/instance_watcher_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func (iw *InstanceWatcherService) agentInstance(ctx context.Context) *mpi.Instan
308308
InstanceRuntime: &mpi.InstanceRuntime{
309309
ProcessId: iw.executer.ProcessID(),
310310
BinaryPath: processPath,
311-
ConfigPath: iw.agentConfig.Path,
311+
ConfigPath: &iw.agentConfig.Path,
312312
Details: nil,
313313
},
314314
}

internal/watcher/instance/nginx_app_protect_process_parser.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ func (n NginxAppProtectProcessParser) Parse(ctx context.Context, processes []*mo
5151
if process.Name == processName {
5252
instanceID := n.instanceID(process)
5353

54+
binaryPath := process.Exe
55+
if binaryPath == "" {
56+
binaryPath = strings.Split(process.Cmd, " ")[0]
57+
}
58+
5459
instanceMap[instanceID] = &mpi.Instance{
5560
InstanceMeta: &mpi.InstanceMeta{
5661
InstanceId: instanceID,
@@ -60,8 +65,7 @@ func (n NginxAppProtectProcessParser) Parse(ctx context.Context, processes []*mo
6065
InstanceConfig: &mpi.InstanceConfig{},
6166
InstanceRuntime: &mpi.InstanceRuntime{
6267
ProcessId: process.PID,
63-
BinaryPath: process.Exe,
64-
ConfigPath: "",
68+
BinaryPath: binaryPath,
6569
Details: &mpi.InstanceRuntime_NginxAppProtectRuntimeInfo{
6670
NginxAppProtectRuntimeInfo: &mpi.NGINXAppProtectRuntimeInfo{
6771
Release: n.release(ctx),

internal/watcher/instance/nginx_app_protect_process_parser_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ func TestNginxAppProtectProcessParser_Parse(t *testing.T) {
3131
InstanceRuntime: &mpi.InstanceRuntime{
3232
ProcessId: 1111,
3333
BinaryPath: "/usr/share/ts/bin/bd-socket-plugin",
34-
ConfigPath: "",
3534
Details: &mpi.InstanceRuntime_NginxAppProtectRuntimeInfo{
3635
NginxAppProtectRuntimeInfo: &mpi.NGINXAppProtectRuntimeInfo{
3736
Release: "4.11.0",

0 commit comments

Comments
 (0)