Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions internal/collector/nginxplusreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type APIDetails struct {
}

// Validate checks if the receiver configuration is valid
// nolint: ireturn
func (cfg *Config) Validate() error {
if cfg.APIDetails.URL == "" {
return errors.New("endpoint cannot be empty for nginxplusreceiver")
Expand Down
23 changes: 19 additions & 4 deletions internal/collector/otel_collector_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ var (
initMutex = &sync.Mutex{}
)

var pluginLogOrigin = slog.String("log_origin", "otel_collector_plugin.go")

// NewCollector is the constructor for the Collector plugin.
func New(conf *config.Config) (*Collector, error) {
initMutex.Lock()
Expand Down Expand Up @@ -262,7 +264,7 @@ func (oc *Collector) handleNginxConfigUpdate(ctx context.Context, msg *bus.Messa
return
}

reloadCollector := oc.checkForNewReceivers(nginxConfigContext)
reloadCollector := oc.checkForNewReceivers(ctx, nginxConfigContext)

if reloadCollector {
slog.InfoContext(ctx, "Reloading OTel collector config")
Expand Down Expand Up @@ -392,7 +394,7 @@ func (oc *Collector) restartCollector(ctx context.Context) {
}
}

func (oc *Collector) checkForNewReceivers(nginxConfigContext *model.NginxConfigContext) bool {
func (oc *Collector) checkForNewReceivers(ctx context.Context, nginxConfigContext *model.NginxConfigContext) bool {
nginxReceiverFound, reloadCollector := oc.updateExistingNginxPlusReceiver(nginxConfigContext)

if !nginxReceiverFound && nginxConfigContext.PlusAPI.URL != "" {
Expand All @@ -407,10 +409,20 @@ func (oc *Collector) checkForNewReceivers(nginxConfigContext *model.NginxConfigC
},
},
)
slog.DebugContext(
ctx,
"NGINX Plus API found, NGINX Plus receiver enabled to scrape metrics",
pluginLogOrigin,
)

reloadCollector = true
} else if nginxConfigContext.PlusAPI.URL == "" {
reloadCollector = oc.addNginxOssReceiver(nginxConfigContext)
slog.WarnContext(
ctx,
"NGINX Plus API is not configured, searching for stub status endpoint",
pluginLogOrigin,
)
reloadCollector = oc.addNginxOssReceiver(ctx, nginxConfigContext)
}

if oc.config.IsFeatureEnabled(pkgConfig.FeatureLogsNap) {
Expand All @@ -425,7 +437,7 @@ func (oc *Collector) checkForNewReceivers(nginxConfigContext *model.NginxConfigC
return reloadCollector
}

func (oc *Collector) addNginxOssReceiver(nginxConfigContext *model.NginxConfigContext) bool {
func (oc *Collector) addNginxOssReceiver(ctx context.Context, nginxConfigContext *model.NginxConfigContext) bool {
nginxReceiverFound, reloadCollector := oc.updateExistingNginxOSSReceiver(nginxConfigContext)

if !nginxReceiverFound && nginxConfigContext.StubStatus.URL != "" {
Expand All @@ -441,8 +453,11 @@ func (oc *Collector) addNginxOssReceiver(nginxConfigContext *model.NginxConfigCo
AccessLogs: toConfigAccessLog(nginxConfigContext.AccessLogs),
},
)
slog.DebugContext(ctx, "Stub status endpoint found, OSS receiver enabled to scrape metrics", pluginLogOrigin)

reloadCollector = true
} else if nginxConfigContext.StubStatus.URL == "" {
slog.WarnContext(ctx, "Stub status endpoint not found, NGINX metrics not available", pluginLogOrigin)
}

return reloadCollector
Expand Down