@@ -14,13 +14,15 @@ import (
1414 sdkGRPC "github.com/nginx/agent/sdk/v2/grpc"
1515 "github.com/nginx/agent/v2/src/core"
1616 "github.com/nginx/agent/v2/src/core/config"
17+ "go.uber.org/atomic"
1718
1819 "github.com/google/uuid"
1920 log "github.com/sirupsen/logrus"
2021)
2122
2223type Features struct {
2324 commander client.Commander
25+ metricReporter client.MetricReporter
2426 pipeline core.MessagePipeInterface
2527 conf * config.Config
2628 env core.Environment
@@ -33,6 +35,7 @@ type Features struct {
3335
3436func NewFeatures (
3537 commander client.Commander ,
38+ metricReporter client.MetricReporter ,
3639 conf * config.Config ,
3740 env core.Environment ,
3841 binary core.NginxBinary ,
@@ -42,6 +45,7 @@ func NewFeatures(
4245) * Features {
4346 return & Features {
4447 commander : commander ,
48+ metricReporter : metricReporter ,
4549 conf : conf ,
4650 env : env ,
4751 binary : binary ,
@@ -94,6 +98,7 @@ func (f *Features) Init(pipeline core.MessagePipeInterface) {
9498
9599func (f * Features ) Close () {
96100 log .Info ("Features is wrapping up" )
101+ log .Info ("Features is closed" )
97102}
98103
99104func (f * Features ) Info () * core.Info {
@@ -135,7 +140,7 @@ func (f *Features) Process(msg *core.Message) {
135140
136141func (f * Features ) enableMetricsFeature (_ string ) []core.Plugin {
137142 if ! f .pipeline .IsPluginAlreadyRegistered (agent_config .FeatureMetrics ) {
138- log .Debugf ("Enabling metrics feature" )
143+ log .Debug ("Enabling metrics feature" )
139144 conf , err := config .GetConfig (f .conf .ClientID )
140145 if err != nil {
141146 log .Warnf ("Unable to get agent config, %v" , err )
@@ -144,7 +149,7 @@ func (f *Features) enableMetricsFeature(_ string) []core.Plugin {
144149
145150 metrics := NewMetrics (f .conf , f .env , f .binary , f .processes )
146151 metricsThrottle := NewMetricsThrottle (f .conf , f .env )
147- metricsSender := NewMetricsSender (f .commander )
152+ metricsSender := NewMetricsSender (f .metricReporter , atomic . NewBool ( true ) )
148153
149154 return []core.Plugin {metrics , metricsThrottle , metricsSender }
150155 }
@@ -154,7 +159,7 @@ func (f *Features) enableMetricsFeature(_ string) []core.Plugin {
154159func (f * Features ) enableMetricsCollectionFeature (_ string ) []core.Plugin {
155160 if ! f .pipeline .IsPluginAlreadyRegistered (agent_config .FeatureMetrics ) &&
156161 ! f .pipeline .IsPluginAlreadyRegistered (agent_config .FeatureMetricsCollection ) {
157- log .Debugf ("Enabling metrics-collection feature" )
162+ log .Debug ("Enabling metrics-collection feature" )
158163 conf , err := config .GetConfig (f .conf .ClientID )
159164 if err != nil {
160165 log .Warnf ("Unable to get agent config, %v" , err )
@@ -171,7 +176,7 @@ func (f *Features) enableMetricsCollectionFeature(_ string) []core.Plugin {
171176func (f * Features ) enableMetricsThrottleFeature (_ string ) []core.Plugin {
172177 if ! f .pipeline .IsPluginAlreadyRegistered (agent_config .FeatureMetrics ) &&
173178 ! f .pipeline .IsPluginAlreadyRegistered (agent_config .FeatureMetricsThrottle ) {
174- log .Debugf ("Enabling metrics-throttle feature" )
179+ log .Debug ("Enabling metrics-throttle feature" )
175180 conf , err := config .GetConfig (f .conf .ClientID )
176181 if err != nil {
177182 log .Warnf ("Unable to get agent config, %v" , err )
@@ -188,14 +193,14 @@ func (f *Features) enableMetricsThrottleFeature(_ string) []core.Plugin {
188193func (f * Features ) enableMetricsSenderFeature (_ string ) []core.Plugin {
189194 if ! f .pipeline .IsPluginAlreadyRegistered (agent_config .FeatureMetrics ) &&
190195 ! f .pipeline .IsPluginAlreadyRegistered (agent_config .FeatureMetricsSender ) {
191- log .Debugf ("Enabling metrics-sender feature" )
196+ log .Debug ("Enabling metrics-sender feature" )
192197 conf , err := config .GetConfig (f .conf .ClientID )
193198 if err != nil {
194199 log .Warnf ("Unable to get agent config, %v" , err )
195200 }
196201 f .conf = conf
197202
198- metricsSender := NewMetricsSender (f .commander )
203+ metricsSender := NewMetricsSender (f .metricReporter , atomic . NewBool ( true ) )
199204
200205 return []core.Plugin {metricsSender }
201206 }
@@ -204,8 +209,8 @@ func (f *Features) enableMetricsSenderFeature(_ string) []core.Plugin {
204209
205210func (f * Features ) enableAgentAPIFeature (_ string ) []core.Plugin {
206211 if ! f .pipeline .IsPluginAlreadyRegistered (agent_config .FeatureAgentAPI ) {
212+ log .Debug ("Enabling agent-api feature" )
207213 conf , err := config .GetConfig (f .conf .ClientID )
208- log .Debugf ("Enabling agent-api feature" )
209214 if err != nil {
210215 log .Warnf ("Unable to get agent config, %v" , err )
211216 }
@@ -220,7 +225,7 @@ func (f *Features) enableAgentAPIFeature(_ string) []core.Plugin {
220225
221226func (f * Features ) enableRegistrationFeature (_ string ) []core.Plugin {
222227 if ! f .pipeline .IsPluginAlreadyRegistered (agent_config .FeatureRegistration ) {
223- log .Debugf ("Enabling registration feature" )
228+ log .Debug ("Enabling registration feature" )
224229 conf , err := config .GetConfig (f .conf .ClientID )
225230 if err != nil {
226231 log .Warnf ("Unable to get agent config, %v" , err )
@@ -236,7 +241,7 @@ func (f *Features) enableRegistrationFeature(_ string) []core.Plugin {
236241
237242func (f * Features ) enableDataPlaneStatusFeature (_ string ) []core.Plugin {
238243 if ! f .pipeline .IsPluginAlreadyRegistered (agent_config .FeatureDataPlaneStatus ) {
239- log .Debugf ("Enabling dataplane-status feature" )
244+ log .Debug ("Enabling dataplane-status feature" )
240245 conf , err := config .GetConfig (f .conf .ClientID )
241246 if err != nil {
242247 log .Warnf ("Unable to get agent config, %v" , err )
@@ -252,7 +257,7 @@ func (f *Features) enableDataPlaneStatusFeature(_ string) []core.Plugin {
252257
253258func (f * Features ) enableProcessWatcherFeature (_ string ) []core.Plugin {
254259 if ! f .pipeline .IsPluginAlreadyRegistered (agent_config .FeatureProcessWatcher ) {
255- log .Debugf ("Enabling process-watcher feature" )
260+ log .Debug ("Enabling process-watcher feature" )
256261 conf , err := config .GetConfig (f .conf .ClientID )
257262 if err != nil {
258263 log .Warnf ("Unable to get agent config, %v" , err )
@@ -268,23 +273,23 @@ func (f *Features) enableProcessWatcherFeature(_ string) []core.Plugin {
268273
269274func (f * Features ) enableActivityEventsFeature (_ string ) []core.Plugin {
270275 if ! f .pipeline .IsPluginAlreadyRegistered (agent_config .FeatureActivityEvents ) {
271- log .Debugf ("Enabling activity-events feature" )
276+ log .Debug ("Enabling activity-events feature" )
272277 conf , err := config .GetConfig (f .conf .ClientID )
273278 if err != nil {
274279 log .Warnf ("Unable to get agent config, %v" , err )
275280 }
276281 f .conf = conf
277282
278- events := NewEvents (f .conf , f .env , sdkGRPC .NewMessageMeta (uuid .NewString ()), f .binary , f .agentEventsMeta )
283+ eventsPlugin := NewEvents (f .conf , f .env , sdkGRPC .NewMessageMeta (uuid .NewString ()), f .binary , f .agentEventsMeta )
279284
280- return []core.Plugin {events }
285+ return []core.Plugin {eventsPlugin }
281286 }
282287 return []core.Plugin {}
283288}
284289
285290func (f * Features ) enableFileWatcherFeature (_ string ) []core.Plugin {
286291 if ! f .pipeline .IsPluginAlreadyRegistered (agent_config .FeatureFileWatcher ) {
287- log .Debugf ("Enabling file-watcher feature" )
292+ log .Debug ("Enabling file-watcher feature" )
288293 conf , err := config .GetConfig (f .conf .ClientID )
289294 if err != nil {
290295 log .Warnf ("Unable to get agent config, %v" , err )
@@ -303,7 +308,7 @@ func (f *Features) enableNginxCountingFeature(_ string) []core.Plugin {
303308 countingPlugins := []core.Plugin {}
304309 if len (f .conf .Nginx .NginxCountingSocket ) > 0 {
305310 if ! f .pipeline .IsPluginAlreadyRegistered (agent_config .FeatureNginxCounting ) {
306- log .Debugf ("Enabling nginx-counting feature" )
311+ log .Debug ("Enabling nginx-counting feature" )
307312 conf , err := config .GetConfig (f .conf .ClientID )
308313 if err != nil {
309314 log .Warnf ("Unable to get agent config, %v" , err )
0 commit comments