This repository has been archived by the owner on Feb 25, 2023. It is now read-only.
/
base_config.go
117 lines (98 loc) · 3.36 KB
/
base_config.go
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
// Copyright 2020, Jeff Alder
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package nr_yml
import (
"github.com/newrelic/go-agent/v3/newrelic"
"os"
)
// Don't use this; it's only exported for the yaml parser
type ConfigYaml struct {
AppName *string `yaml:"app_name"`
License *string `yaml:"license_key"`
Host *string `yaml:"host"`
Enabled *bool `yaml:"agent_enabled"`
HighSecurity *bool `yaml:"high_security"`
SecurityPoliciesToken *string `yaml:"security_policies_token"`
LogStreamName *string `yaml:"log_stream_name"`
LogLevel *string `yaml:"log_level"`
Labels *map[string]string `yaml:"labels"`
DistributedTracing *DistributedTracingYaml `yaml:"distributed_tracing"`
InfiniteTracing *InfiniteTracingYaml `yaml:"infinite_tracing"`
ProcessHost *ProcessHostYaml `yaml:"process_host"`
Attributes *AttributesYaml `yaml:"attributes"`
Utilization *UtilizationYaml `yaml:"utilization"`
}
func (yamlValues ConfigYaml) update(cfg *newrelic.Config) {
if yamlValues.AppName != nil {
newrelic.ConfigAppName(*yamlValues.AppName)(cfg)
}
if yamlValues.Enabled != nil {
newrelic.ConfigEnabled(*yamlValues.Enabled)(cfg)
}
if yamlValues.License != nil {
newrelic.ConfigLicense(*yamlValues.License)(cfg)
}
if yamlValues.HighSecurity != nil {
cfg.HighSecurity = *yamlValues.HighSecurity
}
if yamlValues.SecurityPoliciesToken != nil {
cfg.SecurityPoliciesToken = *yamlValues.SecurityPoliciesToken
}
if yamlValues.Host != nil {
cfg.Host = *yamlValues.Host
}
if yamlValues.Labels != nil {
cfg.Labels = *yamlValues.Labels
}
if yamlValues.Attributes != nil {
yamlValues.Attributes.update(cfg)
}
if yamlValues.InfiniteTracing != nil {
yamlValues.InfiniteTracing.update(cfg)
}
if yamlValues.DistributedTracing != nil {
yamlValues.DistributedTracing.update(cfg)
}
if yamlValues.ProcessHost != nil {
yamlValues.ProcessHost.update(cfg)
}
if yamlValues.Utilization != nil {
yamlValues.Utilization.update(cfg)
}
yamlValues.updateLogging(cfg)
}
func (yamlValues ConfigYaml) updateLogging(cfg *newrelic.Config) {
var logStream *os.File
if yamlValues.LogStreamName == nil {
return
}
switch *yamlValues.LogStreamName {
case "STDOUT", "Stdout", "stdout":
logStream = os.Stdout
case "STDERR", "Stderr", "stderr":
logStream = os.Stderr
}
if logStream != nil {
if yamlValues.LogLevel == nil {
newrelic.ConfigInfoLogger(logStream)(cfg)
} else {
switch *yamlValues.LogLevel {
case "DEBUG", "Debug", "debug":
newrelic.ConfigDebugLogger(logStream)(cfg)
default:
newrelic.ConfigInfoLogger(logStream)(cfg)
}
}
}
}