-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathotel_collector_plugin.go
More file actions
699 lines (591 loc) · 20.1 KB
/
otel_collector_plugin.go
File metadata and controls
699 lines (591 loc) · 20.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
// Copyright (c) F5, Inc.
//
// This source code is licensed under the Apache License, Version 2.0 license found in the
// LICENSE file in the root directory of this source tree.
package collector
import (
"context"
"errors"
"fmt"
"log/slog"
"os"
"strings"
"sync"
"time"
pkgConfig "github.com/nginx/agent/v3/pkg/config"
"github.com/nginx/agent/v3/api/grpc/mpi/v1"
"github.com/nginx/agent/v3/internal/backoff"
"github.com/nginx/agent/v3/internal/bus"
"github.com/nginx/agent/v3/internal/collector/types"
"github.com/nginx/agent/v3/internal/config"
"github.com/nginx/agent/v3/internal/model"
"go.opentelemetry.io/collector/otelcol"
)
const (
maxTimeToWaitForShutdown = 30 * time.Second
defaultCollectionInterval = 1 * time.Minute
filePermission = 0o600
// To conform to the rfc3164 spec the timestamp in the logs need to be formatted correctly.
// Here are some examples of what the timestamp conversions look like.
// Notice how if the day begins with a zero that the zero is replaced with an empty space.
// 2024-11-06T17:19:24+00:00 ---> Nov 6 17:19:24
// 2024-11-16T17:19:24+00:00 ---> Nov 16 17:19:24
timestampConversionExpression = `'EXPR(let timestamp = split(split(body, ">")[1], " ")[0]; ` +
`let newTimestamp = ` +
`timestamp matches "(\\d{4})-(\\d{2})-(0\\d{1})T(\\d{2}):(\\d{2}):(\\d{2})([+-]\\d{2}:\\d{2}|Z)" ` +
`? (let utcTime = ` +
`date(timestamp).UTC(); utcTime.Format("Jan 2 15:04:05")) : date(timestamp).Format("Jan 02 15:04:05"); ` +
`split(body, ">")[0] + ">" + newTimestamp + " " + split(body, " ", 2)[1])'`
)
type (
// Collector The OTel collector plugin start an embedded OTel collector for metrics collection in the OTel format.
Collector struct {
service types.CollectorInterface
cancel context.CancelFunc
config *config.Config
mu *sync.Mutex
stopped bool
}
)
var (
_ bus.Plugin = (*Collector)(nil)
initMutex = &sync.Mutex{}
)
// NewCollector is the constructor for the Collector plugin.
func New(conf *config.Config) (*Collector, error) {
initMutex.Lock()
defer initMutex.Unlock()
if conf == nil {
return nil, errors.New("nil agent config")
}
if conf.Collector == nil {
return nil, errors.New("nil collector config")
}
if conf.Collector.Log != nil && conf.Collector.Log.Path != "" && conf.Collector.Log.Path != "stdout" {
err := os.WriteFile(conf.Collector.Log.Path, []byte{}, filePermission)
if err != nil {
return nil, err
}
}
settings := OTelCollectorSettings(conf)
oTelCollector, err := otelcol.NewCollector(settings)
if err != nil {
return nil, err
}
return &Collector{
config: conf,
service: oTelCollector,
stopped: true,
mu: &sync.Mutex{},
}, nil
}
func (oc *Collector) State() otelcol.State {
oc.mu.Lock()
defer oc.mu.Unlock()
return oc.service.GetState()
}
// Init initializes and starts the plugin
func (oc *Collector) Init(ctx context.Context, mp bus.MessagePipeInterface) error {
slog.InfoContext(ctx, "Starting OTel Collector plugin")
var runCtx context.Context
runCtx, oc.cancel = context.WithCancel(ctx)
if !oc.config.AreReceiversConfigured() {
slog.InfoContext(runCtx, "No receivers configured for OTel Collector. "+
"Waiting to discover a receiver before starting OTel collector.")
return nil
}
err := writeCollectorConfig(oc.config.Collector)
if err != nil {
return fmt.Errorf("write OTel Collector config: %w", err)
}
if oc.config.Collector.Receivers.OtlpReceivers != nil {
oc.processReceivers(ctx, oc.config.Collector.Receivers.OtlpReceivers)
}
if !oc.stopped {
return errors.New("OTel collector already running")
}
slog.InfoContext(ctx, "Starting OTel collector")
bootErr := oc.bootup(runCtx)
if bootErr != nil {
slog.ErrorContext(runCtx, "Unable to start OTel Collector", "error", bootErr)
}
return nil
}
// Info the plugin.
func (oc *Collector) Info() *bus.Info {
return &bus.Info{
Name: "collector",
}
}
// Close the plugin.
func (oc *Collector) Close(ctx context.Context) error {
slog.InfoContext(ctx, "Closing OTel Collector plugin")
if !oc.stopped {
slog.InfoContext(ctx, "Shutting down OTel Collector", "state", oc.service.GetState())
oc.service.Shutdown()
oc.cancel()
settings := *oc.config.Client.Backoff
settings.MaxElapsedTime = maxTimeToWaitForShutdown
err := backoff.WaitUntil(ctx, &settings, func() error {
if oc.service.GetState() == otelcol.StateClosed {
return nil
}
return errors.New("OTel Collector not in a closed state yet")
})
if err != nil {
slog.ErrorContext(ctx, "Failed to shutdown OTel Collector", "error", err, "state", oc.service.GetState())
} else {
slog.InfoContext(ctx, "OTel Collector shutdown", "state", oc.service.GetState())
oc.stopped = true
}
}
return nil
}
// Process an incoming Message Bus message in the plugin
func (oc *Collector) Process(ctx context.Context, msg *bus.Message) {
switch msg.Topic {
case bus.NginxConfigUpdateTopic:
oc.handleNginxConfigUpdate(ctx, msg)
case bus.ResourceUpdateTopic:
oc.handleResourceUpdate(ctx, msg)
default:
slog.DebugContext(ctx, "OTel collector plugin unknown topic", "topic", msg.Topic)
}
}
// Subscriptions returns the list of topics the plugin is subscribed to
func (oc *Collector) Subscriptions() []string {
return []string{
bus.ResourceUpdateTopic,
bus.NginxConfigUpdateTopic,
}
}
// Process receivers and log warning for sub-optimal configurations
func (oc *Collector) processReceivers(ctx context.Context, receivers []config.OtlpReceiver) {
for _, receiver := range receivers {
if receiver.OtlpTLSConfig == nil {
slog.WarnContext(ctx, "OTel receiver is configured without TLS. Connections are unencrypted.")
continue
}
if receiver.OtlpTLSConfig.GenerateSelfSignedCert {
slog.WarnContext(ctx,
"Self-signed certificate for OTel receiver requested, "+
"this is not recommended for production environments.",
)
if receiver.OtlpTLSConfig.ExistingCert {
slog.WarnContext(ctx,
"Certificate file already exists, skipping self-signed certificate generation",
)
}
} else {
slog.WarnContext(ctx, "OTel receiver is configured without TLS. Connections are unencrypted.")
}
}
}
// nolint: revive, cyclop
func (oc *Collector) bootup(ctx context.Context) error {
errChan := make(chan error)
go func() {
if oc.service == nil {
errChan <- errors.New("unable to start OTel collector: service is nil")
return
}
appErr := oc.service.Run(ctx)
if appErr != nil {
errChan <- appErr
}
slog.InfoContext(ctx, "OTel collector run finished")
}()
for {
select {
case err := <-errChan:
return err
default:
if oc.service == nil {
return errors.New("unable to start otel collector: service is nil")
}
state := oc.service.GetState()
switch state {
case otelcol.StateStarting:
// NoOp
continue
case otelcol.StateRunning:
oc.stopped = false
return nil
case otelcol.StateClosing:
case otelcol.StateClosed:
oc.stopped = true
default:
return fmt.Errorf("unable to start, otelcol state is %s", state)
}
}
}
}
func (oc *Collector) handleNginxConfigUpdate(ctx context.Context, msg *bus.Message) {
slog.DebugContext(ctx, "OTel collector plugin received nginx config update message")
oc.mu.Lock()
defer oc.mu.Unlock()
nginxConfigContext, ok := msg.Data.(*model.NginxConfigContext)
if !ok {
slog.ErrorContext(ctx, "Unable to cast message payload to *model.NginxConfigContext", "payload", msg.Data)
return
}
reloadCollector := oc.checkForNewReceivers(ctx, nginxConfigContext)
if reloadCollector {
slog.InfoContext(ctx, "Reloading OTel collector config, nginx config updated")
err := writeCollectorConfig(oc.config.Collector)
if err != nil {
slog.ErrorContext(ctx, "Failed to write OTel Collector config", "error", err)
return
}
oc.restartCollector(ctx)
}
}
func (oc *Collector) handleResourceUpdate(ctx context.Context, msg *bus.Message) {
slog.DebugContext(ctx, "OTel collector plugin received resource update message")
oc.mu.Lock()
defer oc.mu.Unlock()
resourceUpdateContext, ok := msg.Data.(*v1.Resource)
if !ok {
slog.ErrorContext(ctx, "Unable to cast message payload to *v1.Resource", "payload", msg.Data)
return
}
resourceProcessorUpdated := oc.updateResourceProcessor(resourceUpdateContext)
headersSetterExtensionUpdated := oc.updateHeadersSetterExtension(ctx, resourceUpdateContext)
if resourceProcessorUpdated || headersSetterExtensionUpdated {
slog.InfoContext(ctx, "Reloading OTel collector config, resource updated")
err := writeCollectorConfig(oc.config.Collector)
if err != nil {
slog.ErrorContext(ctx, "Failed to write OTel Collector config", "error", err)
return
}
oc.restartCollector(ctx)
}
}
func (oc *Collector) updateResourceProcessor(resourceUpdateContext *v1.Resource) bool {
resourceProcessorUpdated := false
if oc.config.Collector.Processors.Resource == nil {
oc.config.Collector.Processors.Resource = &config.Resource{
Attributes: make([]config.ResourceAttribute, 0),
}
}
if oc.config.Collector.Processors.Resource != nil &&
resourceUpdateContext.GetResourceId() != "" {
resourceProcessorUpdated = oc.updateResourceAttributes(
[]config.ResourceAttribute{
{
Key: "resource.id",
Action: "insert",
Value: resourceUpdateContext.GetResourceId(),
},
},
)
}
return resourceProcessorUpdated
}
func (oc *Collector) updateHeadersSetterExtension(
ctx context.Context,
resourceUpdateContext *v1.Resource,
) bool {
headersSetterExtensionUpdated := false
if oc.config.Collector.Extensions.HeadersSetter != nil &&
oc.config.Collector.Extensions.HeadersSetter.Headers != nil {
isUUIDHeaderSet := false
for _, header := range oc.config.Collector.Extensions.HeadersSetter.Headers {
if header.Key == "uuid" {
isUUIDHeaderSet = true
break
}
}
if !isUUIDHeaderSet {
slog.DebugContext(
ctx, "Adding uuid header to OTel collector",
"uuid", resourceUpdateContext.GetResourceId(),
)
oc.config.Collector.Extensions.HeadersSetter.Headers = append(
oc.config.Collector.Extensions.HeadersSetter.Headers,
config.Header{
Action: "insert",
Key: "uuid",
Value: resourceUpdateContext.GetResourceId(),
},
)
headersSetterExtensionUpdated = true
}
}
return headersSetterExtensionUpdated
}
func (oc *Collector) restartCollector(ctx context.Context) {
err := oc.Close(ctx)
if err != nil {
slog.ErrorContext(ctx, "Failed to shutdown OTel Collector", "error", err)
return
}
settings := OTelCollectorSettings(oc.config)
oTelCollector, err := otelcol.NewCollector(settings)
if err != nil {
slog.ErrorContext(ctx, "Failed to create OTel Collector", "error", err)
return
}
oc.service = oTelCollector
var runCtx context.Context
runCtx, oc.cancel = context.WithCancel(ctx)
if !oc.stopped {
slog.ErrorContext(ctx, "Unable to restart OTel collector, failed to stop collector")
return
}
slog.InfoContext(ctx, "Restarting OTel collector")
bootErr := oc.bootup(runCtx)
if bootErr != nil {
slog.ErrorContext(runCtx, "Unable to start OTel Collector", "error", bootErr)
}
}
func (oc *Collector) checkForNewReceivers(ctx context.Context, nginxConfigContext *model.NginxConfigContext) bool {
nginxReceiverFound, reloadCollector := oc.updateExistingNginxPlusReceiver(nginxConfigContext)
if !nginxReceiverFound && nginxConfigContext.PlusAPI.URL != "" {
slog.DebugContext(ctx, "Adding new NGINX Plus receiver", "url", nginxConfigContext.PlusAPI.URL)
oc.config.Collector.Receivers.NginxPlusReceivers = append(
oc.config.Collector.Receivers.NginxPlusReceivers,
config.NginxPlusReceiver{
InstanceID: nginxConfigContext.InstanceID,
PlusAPI: config.APIDetails{
URL: nginxConfigContext.PlusAPI.URL,
Listen: nginxConfigContext.PlusAPI.Listen,
Location: nginxConfigContext.PlusAPI.Location,
},
CollectionInterval: defaultCollectionInterval,
},
)
slog.DebugContext(ctx, "NGINX Plus API found, NGINX Plus receiver enabled to scrape metrics")
reloadCollector = true
} else if nginxConfigContext.PlusAPI.URL == "" {
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) {
tcplogReceiversFound := oc.updateTcplogReceivers(nginxConfigContext)
if tcplogReceiversFound {
reloadCollector = true
}
} else {
slog.DebugContext(ctx, "NAP logs feature disabled", "enabled_features", oc.config.Features)
}
return reloadCollector
}
func (oc *Collector) addNginxOssReceiver(ctx context.Context, nginxConfigContext *model.NginxConfigContext) bool {
nginxReceiverFound, reloadCollector := oc.updateExistingNginxOSSReceiver(nginxConfigContext)
if !nginxReceiverFound && nginxConfigContext.StubStatus.URL != "" {
slog.DebugContext(ctx, "Adding new NGINX OSS receiver", "url", nginxConfigContext.StubStatus.URL)
oc.config.Collector.Receivers.NginxReceivers = append(
oc.config.Collector.Receivers.NginxReceivers,
config.NginxReceiver{
InstanceID: nginxConfigContext.InstanceID,
StubStatus: config.APIDetails{
URL: nginxConfigContext.StubStatus.URL,
Listen: nginxConfigContext.StubStatus.Listen,
Location: nginxConfigContext.StubStatus.Location,
},
AccessLogs: toConfigAccessLog(nginxConfigContext.AccessLogs),
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
}
func (oc *Collector) updateExistingNginxPlusReceiver(
nginxConfigContext *model.NginxConfigContext,
) (nginxReceiverFound, reloadCollector bool) {
for index, nginxPlusReceiver := range oc.config.Collector.Receivers.NginxPlusReceivers {
if nginxPlusReceiver.InstanceID == nginxConfigContext.InstanceID {
nginxReceiverFound = true
if nginxPlusReceiver.PlusAPI.URL != nginxConfigContext.PlusAPI.URL {
oc.config.Collector.Receivers.NginxPlusReceivers = append(
oc.config.Collector.Receivers.NginxPlusReceivers[:index],
oc.config.Collector.Receivers.NginxPlusReceivers[index+1:]...,
)
if nginxConfigContext.PlusAPI.URL != "" {
slog.Debug("Updating existing NGINX Plus receiver", "url",
nginxConfigContext.PlusAPI.URL)
nginxPlusReceiver.PlusAPI.URL = nginxConfigContext.PlusAPI.URL
oc.config.Collector.Receivers.NginxPlusReceivers = append(
oc.config.Collector.Receivers.NginxPlusReceivers,
nginxPlusReceiver,
)
}
reloadCollector = true
nginxReceiverFound = true
}
return nginxReceiverFound, reloadCollector
}
}
return nginxReceiverFound, reloadCollector
}
func (oc *Collector) updateExistingNginxOSSReceiver(
nginxConfigContext *model.NginxConfigContext,
) (nginxReceiverFound, reloadCollector bool) {
for index, nginxReceiver := range oc.config.Collector.Receivers.NginxReceivers {
if nginxReceiver.InstanceID == nginxConfigContext.InstanceID {
nginxReceiverFound = true
if isOSSReceiverChanged(nginxReceiver, nginxConfigContext) {
oc.config.Collector.Receivers.NginxReceivers = append(
oc.config.Collector.Receivers.NginxReceivers[:index],
oc.config.Collector.Receivers.NginxReceivers[index+1:]...,
)
if nginxConfigContext.StubStatus.URL != "" {
slog.Debug("Updating existing NGINX OSS receiver", "url",
nginxConfigContext.StubStatus.URL)
nginxReceiver.StubStatus = config.APIDetails{
URL: nginxConfigContext.StubStatus.URL,
Listen: nginxConfigContext.StubStatus.Listen,
Location: nginxConfigContext.StubStatus.Location,
}
nginxReceiver.AccessLogs = toConfigAccessLog(nginxConfigContext.AccessLogs)
oc.config.Collector.Receivers.NginxReceivers = append(
oc.config.Collector.Receivers.NginxReceivers,
nginxReceiver,
)
}
reloadCollector = true
nginxReceiverFound = true
}
return nginxReceiverFound, reloadCollector
}
}
return nginxReceiverFound, reloadCollector
}
func (oc *Collector) updateTcplogReceivers(nginxConfigContext *model.NginxConfigContext) bool {
newTcplogReceiverAdded := false
if nginxConfigContext.NAPSysLogServers != nil {
napLoop:
for _, napSysLogServer := range nginxConfigContext.NAPSysLogServers {
if oc.doesTcplogReceiverAlreadyExist(napSysLogServer) {
continue napLoop
}
oc.config.Collector.Receivers.TcplogReceivers = append(
oc.config.Collector.Receivers.TcplogReceivers,
config.TcplogReceiver{
ListenAddress: napSysLogServer,
Operators: []config.Operator{
{
Type: "add",
Fields: map[string]string{
"field": "body",
"value": timestampConversionExpression,
},
},
{
Type: "syslog_parser",
Fields: map[string]string{
"protocol": "rfc3164",
},
},
{
Type: "remove",
Fields: map[string]string{
"field": "attributes.message",
},
},
{
Type: "add",
Fields: map[string]string{
"field": "resource[\"instance.id\"]",
"value": nginxConfigContext.InstanceID,
},
},
},
},
)
newTcplogReceiverAdded = true
}
}
tcplogReceiverDeleted := oc.areNapReceiversDeleted(nginxConfigContext)
return newTcplogReceiverAdded || tcplogReceiverDeleted
}
func (oc *Collector) areNapReceiversDeleted(nginxConfigContext *model.NginxConfigContext) bool {
listenAddressesToBeDeleted := oc.configDeletedNapReceivers(nginxConfigContext)
if len(listenAddressesToBeDeleted) != 0 {
oc.deleteNapReceivers(listenAddressesToBeDeleted)
return true
}
return false
}
func (oc *Collector) deleteNapReceivers(listenAddressesToBeDeleted map[string]bool) {
filteredReceivers := (oc.config.Collector.Receivers.TcplogReceivers)[:0]
for _, receiver := range oc.config.Collector.Receivers.TcplogReceivers {
if !listenAddressesToBeDeleted[receiver.ListenAddress] {
filteredReceivers = append(filteredReceivers, receiver)
}
}
oc.config.Collector.Receivers.TcplogReceivers = filteredReceivers
}
func (oc *Collector) configDeletedNapReceivers(nginxConfigContext *model.NginxConfigContext) map[string]bool {
elements := make(map[string]bool)
for _, tcplogReceiver := range oc.config.Collector.Receivers.TcplogReceivers {
elements[tcplogReceiver.ListenAddress] = true
}
if nginxConfigContext.NAPSysLogServers != nil {
addressesToDelete := make(map[string]bool)
for _, napAddress := range nginxConfigContext.NAPSysLogServers {
if !elements[napAddress] {
addressesToDelete[napAddress] = true
}
}
return addressesToDelete
}
return elements
}
func (oc *Collector) doesTcplogReceiverAlreadyExist(listenAddress string) bool {
for _, tcplogReceiver := range oc.config.Collector.Receivers.TcplogReceivers {
if listenAddress == tcplogReceiver.ListenAddress {
return true
}
}
return false
}
// nolint: revive
func (oc *Collector) updateResourceAttributes(
attributesToAdd []config.ResourceAttribute,
) (actionUpdated bool) {
actionUpdated = false
if oc.config.Collector.Processors.Resource.Attributes != nil {
OUTER:
for _, toAdd := range attributesToAdd {
for _, action := range oc.config.Collector.Processors.Resource.Attributes {
if action.Key == toAdd.Key {
continue OUTER
}
}
oc.config.Collector.Processors.Resource.Attributes = append(
oc.config.Collector.Processors.Resource.Attributes,
toAdd,
)
actionUpdated = true
}
}
return actionUpdated
}
func isOSSReceiverChanged(nginxReceiver config.NginxReceiver, nginxConfigContext *model.NginxConfigContext) bool {
return nginxReceiver.StubStatus.URL != nginxConfigContext.StubStatus.URL ||
len(nginxReceiver.AccessLogs) != len(nginxConfigContext.AccessLogs)
}
func toConfigAccessLog(al []*model.AccessLog) []config.AccessLog {
if al == nil {
return nil
}
results := make([]config.AccessLog, 0, len(al))
for _, ctxAccessLog := range al {
results = append(results, config.AccessLog{
LogFormat: escapeString(ctxAccessLog.Format),
FilePath: ctxAccessLog.Name,
})
}
return results
}
func escapeString(input string) string {
output := strings.ReplaceAll(input, "$", "$$")
output = strings.ReplaceAll(output, "\"", "\\\"")
return output
}