Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b21e0b2

Browse files
authored
chore(go.d/sd): make module optional in the template (#21273)
1 parent 9e72950 commit b21e0b2

File tree

6 files changed

+53
-143
lines changed

6 files changed

+53
-143
lines changed

src/go/plugin/go.d/agent/discovery/sd/pipeline/pipeline_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ services:
210210
wantComposeCalls: 2, // compose called per target (2 targets)
211211
wantConfGroups: []*confgroup.Group{
212212
// same expected configs as the legacy "new group with targets"
213-
prepareDiscoveredGroup("mock1-foobar1", "mock2-foobar2"),
213+
prepareDiscoveredGroupWithModule("mock1-foobar1", "svc-foobar1", "mock2-foobar2", "svc-foobar2"),
214214
},
215215
},
216216
}
@@ -239,6 +239,27 @@ func prepareDiscoveredGroup(configNames ...string) *confgroup.Group {
239239
}
240240
}
241241

242+
func prepareDiscoveredGroupWithModule(values ...string) *confgroup.Group {
243+
var configs []confgroup.Config
244+
245+
for i := 0; i < len(values); i += 2 {
246+
cfgName := values[i]
247+
modName := values[i+1]
248+
configs = append(configs, confgroup.Config{}.
249+
SetProvider("mock").
250+
SetSourceType(confgroup.TypeDiscovered).
251+
SetSource("test").
252+
SetName(cfgName).
253+
SetModule(modName),
254+
)
255+
}
256+
257+
return &confgroup.Group{
258+
Source: "test",
259+
Configs: configs,
260+
}
261+
}
262+
242263
func newMockDiscoverer(tags string, tggs ...model.TargetGroup) *mockDiscoverer {
243264
return &mockDiscoverer{
244265
tags: mustParseTags(tags),

src/go/plugin/go.d/agent/discovery/sd/pipeline/services.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ func (s *serviceEngine) compose(tgt model.Target) []confgroup.Config {
9797
continue
9898
}
9999

100+
for _, cfg := range cfgs {
101+
if cfg.Module() == "" {
102+
cfg.SetModule(r.id)
103+
}
104+
}
105+
100106
out = append(out, cfgs...)
101107
}
102108

src/go/plugin/go.d/agent/discovery/sd/pipeline/services_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,24 @@ func TestServiceEngine_compose(t *testing.T) {
7979
configYAML: configA,
8080
target: newMockTarget("mock1"),
8181
wantConfigs: []confgroup.Config{
82-
{"name": "mock1-1"},
82+
{"name": "mock1-1", "module": "rule1"},
8383
},
8484
},
8585
"one rule -> two configs (YAML list)": {
8686
configYAML: configA,
8787
target: newMockTarget("mock2"),
8888
wantConfigs: []confgroup.Config{
89-
{"name": "mock2-2"},
90-
{"name": "mock2-3"},
89+
{"name": "mock2-2", "module": "rule2"},
90+
{"name": "mock2-3", "module": "rule2"},
9191
},
9292
},
9393
"multiple rules aggregated (no drop before)": {
9494
configYAML: configA,
9595
target: newMockTarget("mock3"),
9696
wantConfigs: []confgroup.Config{
97-
{"name": "mock3-2"},
98-
{"name": "mock3-3"},
99-
{"name": "mock3-4"},
97+
{"name": "mock3-2", "module": "rule2"},
98+
{"name": "mock3-3", "module": "rule2"},
99+
{"name": "mock3-4", "module": "rule3"},
100100
},
101101
},
102102
"hard drop stops further evaluation": {

src/go/plugin/go.d/config/go.d/sd/docker.conf

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,70 +20,60 @@ services:
2020
- id: "apache"
2121
match: '{{ match "sp" .Image "httpd httpd:* */apache */apache:* */apache2 */apache2:*" }}'
2222
config_template: |
23-
module: apache
2423
name: docker_{{.Name}}
2524
url: http://{{.Address}}/server-status?auto
2625

2726
- id: "beanstalk"
2827
match: '{{ match "sp" .Image "*/beanstalkd */beanstalkd:*" }}'
2928
config_template: |
30-
module: beanstalk
3129
name: docker_{{.Name}}
3230
address: {{.Address}}
3331

3432
- id: "boinc"
3533
match: '{{ match "sp" .Image "boinc/client boinc/client:* */boinc */boinc:*" }}'
3634
config_template: |
37-
module: boinc
3835
name: docker_{{.Name}}
3936
address: {{.Address}}
4037

4138
- id: "cockroachdb"
4239
match: '{{ match "sp" .Image "cockroachdb/cockroach cockroachdb/cockroach:*" }}'
4340
config_template: |
44-
module: cockroachdb
4541
name: docker_{{.Name}}
4642
url: http://{{.Address}}/_status/vars
4743

4844
- id: "consul"
4945
match: '{{ match "sp" .Image "consul consul:* */consul */consul:*" }}'
5046
config_template: |
51-
module: consul
5247
name: docker_{{.Name}}
5348
url: http://{{.Address}}
5449

5550
- id: "coredns"
5651
match: '{{ match "sp" .Image "*/coredns */coredns:*" }}'
5752
config_template: |
58-
module: coredns
5953
name: docker_{{.Name}}
6054
url: http://{{.Address}}/metrics
6155

6256
- id: "couchbase"
6357
match: '{{ or (eq .PrivatePort "8091") (match "sp" .Image "couchbase couchbase:*") }}'
6458
config_template: |
65-
module: couchbase
6659
name: docker_{{.Name}}
6760
url: http://{{.Address}}
6861

6962
- id: "couchdb"
7063
match: '{{ or (eq .PrivatePort "5984") (match "sp" .Image "couchdb couchdb:*") }}'
7164
config_template: |
72-
module: couchdb
7365
name: docker_{{.Name}}
7466
url: http://{{.Address}}
7567

7668
- id: "dovecot"
7769
match: '{{ or (eq .PrivatePort "24242") (match "sp" .Image "*/dovecot */dovecot:*") }}'
7870
config_template: |
79-
module: dovecot
8071
name: docker_{{.Name}}
8172
address: {{.Address}}
8273

8374
- id: "elasticsearch"
8475
match: '{{ or (eq .PrivatePort "9200") (match "sp" .Image "elasticsearch elasticsearch:* */elasticsearch */elasticsearch:* */opensearch */opensearch:*") }}'
8576
config_template: |
86-
module: elasticsearch
8777
name: docker_{{.Name}}
8878
{{ if glob .Image "*elastic*" -}}
8979
url: http://{{.Address}}
@@ -97,86 +87,72 @@ services:
9787
- id: "gearman"
9888
match: '{{ and (eq .PrivatePort "4730") (match "sp" .Image "*/gearmand */gearmand:*") }}'
9989
config_template: |
100-
module: gearman
10190
name: docker_{{.Name}}
10291
address: {{.Address}}
10392

10493
- id: "ipfs"
10594
match: '{{ and (eq .PrivatePort "5001") (match "sp" .Image "ipfs/kubo ipfs/kubo:*") }}'
10695
config_template: |
107-
module: ipfs
10896
name: docker_{{.Name}}
10997
url: http://{{.Address}}
11098

11199
- id: "lighttpd"
112100
match: '{{ match "sp" .Image "*/lighttpd */lighttpd:*" }}'
113101
config_template: |
114-
module: lighttpd
115102
name: docker_{{.Name}}
116103
url: http://{{.Address}}/server-status?auto
117104

118105
- id: "maxscale"
119106
match: '{{ or (eq .PrivatePort "8989") (match "sp" .Image "mariadb/maxscale mariadb/maxscale:*") }}'
120107
config_template: |
121-
module: maxscale
122108
name: docker_{{.Name}}
123109
url: http://{{.Address}}
124110

125111
- id: "memcached"
126112
match: '{{ or (eq .PrivatePort "11211") (match "sp" .Image "memcached memcached:* */memcached */memcached:*") }}'
127113
config_template: |
128-
module: memcached
129114
name: docker_{{.Name}}
130115
address: {{.Address}}
131116

132117
- id: "mongodb"
133118
match: '{{ or (eq .PrivatePort "27017") (match "sp" .Image "mongo mongo:* */mongodb */mongodb:* */mongodb-community-server */mongodb-community-server:*") }}'
134119
config_template: |
135-
module: mongodb
136120
name: docker_{{.Name}}
137121
uri: mongodb://{{.Address}}
138122

139123
- id: "mysql"
140124
match: '{{ or (eq .PrivatePort "3306") (match "sp" .Image "mysql mysql:* */mysql */mysql:* mariadb mariadb:* */mariadb */mariadb:* percona percona:* */percona-mysql */percona-mysql:*") }}'
141125
config_template: |
142-
module: mysql
143126
name: docker_{{.Name}}
144127
dsn: netdata@tcp({{.Address}})/
145128

146129
- id: "nats"
147130
match: '{{ and (eq .PrivatePort "8222") (match "sp" .Image "nats nats:*") }}'
148131
config_template: |
149-
- module: nats
150-
name: docker_{{.Name}}
132+
- name: docker_{{.Name}}
151133
url: http://{{.Address}}
152134

153135
- id: "nginx"
154136
match: '{{ match "sp" .Image "nginx nginx:*" }}'
155137
config_template: |
156-
- module: nginx
157-
name: docker_{{.Name}}
138+
- name: docker_{{.Name}}
158139
url: http://{{.Address}}/stub_status
159-
- module: nginx
160-
name: docker_{{.Name}}
140+
- name: docker_{{.Name}}
161141
url: http://{{.Address}}/basic_status
162-
- module: nginx
163-
name: docker_{{.Name}}
142+
- name: docker_{{.Name}}
164143
url: http://{{.Address}}/nginx_status
165-
- module: nginx
166-
name: docker_{{.Name}}
144+
- name: docker_{{.Name}}
167145
url: http://{{.Address}}/status
168146

169147
- id: "nginxunit"
170148
match: '{{ match "sp" .Image "nginx/unit nginx/unit:*" }}'
171149
config_template: |
172-
- module: nginxunit
173-
name: docker_{{.Name}}
150+
- name: docker_{{.Name}}
174151
url: http://{{.Address}}
175152

176153
- id: "oracledb"
177154
match: '{{ and (eq .PrivatePort "1521" "2484") (match "sp" .Image "oracle/database oracle/database:*") }}'
178155
config_template: |
179-
module: oracledb
180156
name: docker_{{.Name}}
181157
{{ if eq .PrivatePort "1521" -}}
182158
dsn: 'oracle://username:password@{{.Address}}/XE'
@@ -187,14 +163,12 @@ services:
187163
- id: "pgbouncer"
188164
match: '{{ or (eq .PrivatePort "6432") (match "sp" .Image "*/pgbouncer */pgbouncer:*") }}'
189165
config_template: |
190-
module: pgbouncer
191166
name: docker_{{.Name}}
192167
dsn: postgres://netdata:postgres@{{.Address}}/pgbouncer
193168

194169
- id: "pika"
195170
match: '{{ match "sp" .Image "pikadb/pika pikadb/pika:*" }}'
196171
config_template: |
197-
module: pika
198172
name: docker_{{.Name}}
199173
address: redis://@{{.Address}}
200174

@@ -208,93 +182,79 @@ services:
208182
- id: "proxysql"
209183
match: '{{ or (eq .PrivatePort "6032") (match "sp" .Image "*/proxysql */proxysql:*") }}'
210184
config_template: |
211-
module: proxysql
212185
name: docker_{{.Name}}
213186
dsn: stats:stats@tcp({{.Address}})/
214187

215188
- id: "puppet"
216189
match: '{{ or (eq .PrivatePort "8140") (match "sp" .Image "puppet/puppetserver puppet/puppetserver:*") }}'
217190
config_template: |
218-
module: puppet
219191
name: docker_{{.Name}}
220192
url: https://{{.Address}}
221193
tls_skip_verify: yes
222194

223195
- id: "rabbitmq"
224196
match: '{{ or (eq .PrivatePort "15672") (match "sp" .Image "rabbitmq rabbitmq:* */rabbitmq */rabbitmq:*") }}'
225197
config_template: |
226-
module: rabbitmq
227198
name: docker_{{.Name}}
228199
url: http://{{.Address}}
229200

230201
- id: "redis"
231202
match: '{{ or (eq .PrivatePort "6379") (match "sp" .Image "redis redis:* */redis */redis:*") }}'
232203
config_template: |
233-
module: redis
234204
name: docker_{{.Name}}
235205
address: redis://@{{.Address}}
236206

237207
- id: "rethinkdb"
238208
match: '{{ and (eq .PrivatePort "28015") (match "sp" .Image "rethinkdb rethinkdb:* */rethinkdb */rethinkdb:*") }}'
239209
config_template: |
240-
module: rethinkdb
241210
name: docker_{{.Name}}
242211
address: {{.Address}}
243212

244213
- id: "squid"
245214
match: '{{ match "sp" .Image "*/squid */squid:*" }}'
246215
config_template: |
247-
module: squid
248216
name: docker_{{.Name}}
249217
url: http://{{.Address}}
250218

251219
- id: "tengine"
252220
match: '{{ match "sp" .Image "*/tengine */tengine:*" }}'
253221
config_template: |
254-
module: tengine
255222
name: docker_{{.Name}}
256223
url: http://{{.Address}}/us
257224

258225
- id: "tor"
259226
match: '{{ and (eq .PrivatePort "9051") (match "sp" .Image "*/tor */tor:*") }}'
260227
config_template: |
261-
module: tor
262228
name: docker_{{.Name}}
263229
address: {{.Address}}
264230

265231
- id: "tomcat"
266232
match: '{{ match "sp" .Image "tomcat tomcat:* */tomcat */tomcat:*" }}'
267233
config_template: |
268-
module: tomcat
269234
name: docker_{{.Name}}
270235
url: http://{{.Address}}
271236

272237
- id: "typesense"
273238
match: '{{ match "sp" .Image "typesense/typesense typesense/typesense:*" }}'
274239
config_template: |
275-
module: typesense
276240
name: docker_{{.Name}}
277241
url: http://{{.Address}}
278242
api_key: {{ trimPrefix "--api-key=" (regexFind "--api-key=[^ ]+" .Command) -}}
279243

280244
- id: "varnish"
281245
match: '{{ match "sp" .Image "varnish varnish:*" }}'
282246
config_template: |
283-
module: varnish
284247
name: docker_{{.Name}}
285248
docker_container: {{.Name}}
286249

287250
- id: "vernemq"
288251
match: '{{ match "sp" .Image "*/vernemq */vernemq:*" }}'
289252
config_template: |
290-
module: vernemq
291253
name: docker_{{.Name}}
292254
url: http://{{.Address}}/metrics
293255

294256
- id: "zookeeper"
295257
match: '{{ or (eq .PrivatePort "2181") (match "sp" .Image "*/zookeeper */zookeeper:*") }}'
296258
config_template: |
297-
module: zookeeper
298259
name: docker_{{.Name}}
299260
address: {{.Address}}
300-

0 commit comments

Comments
 (0)