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
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
13 changes: 9 additions & 4 deletions internal/collector/otel_collector_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,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, nginx config updated")
Expand Down Expand Up @@ -394,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 @@ -410,10 +410,12 @@ func (oc *Collector) checkForNewReceivers(nginxConfigContext *model.NginxConfigC
CollectionInterval: defaultCollectionInterval,
},
)
slog.DebugContext(ctx, "NGINX Plus API found, NGINX Plus receiver enabled to scrape metrics")

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")
reloadCollector = oc.addNginxOssReceiver(ctx, nginxConfigContext)
}

if oc.config.IsFeatureEnabled(pkgConfig.FeatureLogsNap) {
Expand All @@ -428,7 +430,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 @@ -445,8 +447,11 @@ func (oc *Collector) addNginxOssReceiver(nginxConfigContext *model.NginxConfigCo
CollectionInterval: defaultCollectionInterval,
},
)
slog.DebugContext(ctx, "Stub status endpoint found, OSS receiver enabled to scrape metrics")

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

return reloadCollector
Expand Down