Skip to content

Commit 17d3fb6

Browse files
committed
Use "type" instead of "service_type" and kept "instance"
1 parent 0ab10c6 commit 17d3fb6

16 files changed

+188
-212
lines changed

agent/metric_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ var (
5353
},
5454
Services: []config.Service{
5555
{
56-
ServiceType: "myapplication",
57-
JMXPort: 1234,
56+
Type: "myapplication",
57+
JMXPort: 1234,
5858
JMXMetrics: []config.JmxMetric{
5959
{
6060
Name: "heap_size_mb",
@@ -72,11 +72,11 @@ var (
7272
},
7373
},
7474
{
75-
ServiceType: "apache",
76-
Address: "127.0.0.1",
77-
Port: 80,
78-
HTTPPath: "/",
79-
HTTPHost: "127.0.0.1:80",
75+
Type: "apache",
76+
Address: "127.0.0.1",
77+
Port: 80,
78+
HTTPPath: "/",
79+
HTTPHost: "127.0.0.1:80",
8080
},
8181
},
8282
}

config/config.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,7 @@ func migrateScrapper(k *koanf.Koanf, config map[string]interface{}, deprecatedPa
544544
func migrateServices(config map[string]interface{}) prometheus.MultiError {
545545
migratedOptions := map[string]string{
546546
"cassandra_detailed_tables": "detailed_items",
547-
"id": "service_type",
548-
"instance": "service_instance",
547+
"id": "type",
549548
"mgmt_port": "stats_port",
550549
}
551550

config/config_test.go

+20-39
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ func TestStructuredConfig(t *testing.T) { //nolint:maintidx
265265
},
266266
Services: []Service{
267267
{
268-
ServiceType: "service1",
269-
ServiceInstance: "instance1",
268+
Type: "service1",
269+
Instance: "instance1",
270270
Port: 8080,
271271
IgnorePorts: []int{8081},
272272
Address: "127.0.0.1",
@@ -717,7 +717,7 @@ func TestLoad(t *testing.T) { //nolint:maintidx
717717
WantConfig: Config{
718718
Services: []Service{
719719
{
720-
ServiceType: "service1",
720+
Type: "service1",
721721
CheckType: "nagios",
722722
CheckCommand: "/path/to/bin --with-option",
723723
},
@@ -838,7 +838,7 @@ func TestLoad(t *testing.T) { //nolint:maintidx
838838
WantConfig: Config{
839839
Services: []Service{
840840
{
841-
ServiceType: "cassandra",
841+
Type: "cassandra",
842842
DetailedItems: []string{
843843
"keyspace.table1",
844844
"keyspace.table2",
@@ -856,8 +856,8 @@ func TestLoad(t *testing.T) { //nolint:maintidx
856856
WantConfig: Config{
857857
Services: []Service{
858858
{
859-
ServiceType: "service1",
860-
StatsPort: 9090,
859+
Type: "service1",
860+
StatsPort: 9090,
861861
},
862862
},
863863
},
@@ -878,49 +878,30 @@ func TestLoad(t *testing.T) { //nolint:maintidx
878878
Files: []string{"testdata/deprecated_service_id.conf"},
879879
WantWarnings: []string{
880880
"testdata/deprecated_service_id.conf: setting is deprecated in 'service' override: 'id'" +
881-
", use 'service_type' instead",
881+
", use 'type' instead",
882882
},
883883
WantConfig: Config{
884884
Services: []Service{
885885
{
886-
ServiceType: "apache",
887-
Port: 1234,
886+
Type: "apache",
887+
Port: 1234,
888888
},
889889
},
890890
},
891891
},
892892
{
893-
Name: "deprecated_service_instance",
894-
Files: []string{"testdata/deprecated_service_instance.conf"},
893+
Name: "deprecated_service_id_with_instance",
894+
Files: []string{"testdata/deprecated_service_id_with_instance.conf"},
895895
WantWarnings: []string{
896-
"testdata/deprecated_service_instance.conf: setting is deprecated in 'service' override: 'instance'" +
897-
", use 'service_instance' instead",
896+
"testdata/deprecated_service_id_with_instance.conf: setting is deprecated in 'service' override: 'id'" +
897+
", use 'type' instead",
898898
},
899899
WantConfig: Config{
900900
Services: []Service{
901901
{
902-
ServiceType: "apache",
903-
ServiceInstance: "my_container",
904-
Port: 1234,
905-
},
906-
},
907-
},
908-
},
909-
{
910-
Name: "deprecated_service_id_and_instance",
911-
Files: []string{"testdata/deprecated_service_id_and_instance.conf"},
912-
WantWarnings: []string{
913-
"testdata/deprecated_service_id_and_instance.conf: setting is deprecated in 'service' override: 'id'" +
914-
", use 'service_type' instead",
915-
"testdata/deprecated_service_id_and_instance.conf: setting is deprecated in 'service' override: 'instance'" +
916-
", use 'service_instance' instead",
917-
},
918-
WantConfig: Config{
919-
Services: []Service{
920-
{
921-
ServiceType: "apache",
922-
ServiceInstance: "my_container",
923-
Port: 1234,
902+
Type: "apache",
903+
Instance: "my_container",
904+
Port: 1234,
924905
},
925906
},
926907
},
@@ -1177,13 +1158,13 @@ func TestDump(t *testing.T) {
11771158
},
11781159
Services: []Service{
11791160
{
1180-
ServiceType: "in-dump",
1161+
Type: "in-dump",
11811162
Password: "not-in-dump",
11821163
JMXPassword: "not-in-dump",
11831164
KeyFile: "not-in-dump",
11841165
},
11851166
{
1186-
ServiceType: "in-dump-2",
1167+
Type: "in-dump-2",
11871168
Password: "",
11881169
JMXPassword: "",
11891170
KeyFile: "",
@@ -1201,13 +1182,13 @@ func TestDump(t *testing.T) {
12011182
},
12021183
Services: []Service{
12031184
{
1204-
ServiceType: "in-dump",
1185+
Type: "in-dump",
12051186
Password: "*****",
12061187
JMXPassword: "*****",
12071188
KeyFile: "*****",
12081189
},
12091190
{
1210-
ServiceType: "in-dump-2",
1191+
Type: "in-dump-2",
12111192
// In dump because these fields were unset.
12121193
Password: "",
12131194
JMXPassword: "",

config/loader_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ func TestLoader(t *testing.T) {
184184
"stats_protocol": "",
185185
"check_type": "",
186186
"ignore_ports": nil,
187-
"service_type": "service1",
188-
"service_instance": "instance1",
187+
"type": "service1",
188+
"instance": "instance1",
189189
"port": 0.0,
190190
"stats_port": 0.0,
191191
"check_command": "",
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
service:
2-
- service_type: "cassandra"
2+
- type: "cassandra"
33
cassandra_detailed_tables:
44
- "keyspace.table1"
55
- "keyspace.table2"
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
service:
2-
- service_type: "service1"
2+
- type: "service1"
33
mgmt_port: 9090

config/testdata/deprecated_service_instance.conf

-4
This file was deleted.

config/testdata/full.conf

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ nvidia_smi:
201201
timeout: 5
202202

203203
service:
204-
- service_type: "service1"
205-
service_instance: "instance1"
204+
- type: "service1"
205+
instance: "instance1"
206206
port: 8080
207207
ignore_ports:
208208
- 8081

config/testdata/loader.conf

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ metric:
4343
target: 127.0.0.1
4444

4545
service:
46-
- service_type: "service1"
47-
service_instance: "instance1"
46+
- type: "service1"
47+
instance: "instance1"
4848

4949
service_ignore_metrics:
5050
- name: "redis"

config/testdata/unused.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ bleemeo:
22
unused_key: "unused"
33

44
service:
5-
- service_type: "service1"
5+
- type: "service1"
66
check_type: "nagios"
77
check_command: "/path/to/bin --with-option"
88
another_key: 5

config/types.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ type Listener struct {
322322

323323
type Service struct {
324324
// The name of the service type, like "apache", "nginx". For custom service, it could be any value.
325-
ServiceType string `yaml:"service_type"`
325+
Type string `yaml:"type"`
326326
// Instance of the service, used to differentiate between two same services (like two apaches)
327-
ServiceInstance string `yaml:"service_instance"`
327+
Instance string `yaml:"instance"`
328328
// The port the service is running on.
329329
Port int `yaml:"port"`
330330
// Ports that should be ignored.

discovery/discovery.go

+22-22
Original file line numberDiff line numberDiff line change
@@ -153,39 +153,39 @@ func validateServices(services []config.Service) (map[NameInstance]config.Servic
153153
replacer := strings.NewReplacer(".", "_", "-", "_")
154154

155155
for _, srv := range services {
156-
if srv.ServiceType == "" {
157-
warning := fmt.Errorf("%w: the key \"service_type\" is missing in one of your service override", config.ErrInvalidValue)
156+
if srv.Type == "" {
157+
warning := fmt.Errorf("%w: the key \"type\" is missing in one of your service override", config.ErrInvalidValue)
158158
warnings.Append(warning)
159159

160160
continue
161161
}
162162

163-
if !model.IsValidMetricName(model.LabelValue(srv.ServiceType)) {
164-
newServiceType := replacer.Replace(srv.ServiceType)
163+
if !model.IsValidMetricName(model.LabelValue(srv.Type)) {
164+
newServiceType := replacer.Replace(srv.Type)
165165
if !model.IsValidMetricName(model.LabelValue(newServiceType)) {
166166
warning := fmt.Errorf(
167-
"%w: service_type \"%s\" can only contains letters, digits and underscore",
168-
config.ErrInvalidValue, srv.ServiceType,
167+
"%w: service type \"%s\" can only contains letters, digits and underscore",
168+
config.ErrInvalidValue, srv.Type,
169169
)
170170
warnings.Append(warning)
171171

172172
continue
173173
}
174174

175175
warning := fmt.Errorf(
176-
"%w: service_type \"%s\" can not contains dot (.) or dash (-). Changed to \"%s\"",
177-
config.ErrInvalidValue, srv.ServiceType, newServiceType,
176+
"%w: service type \"%s\" can not contains dot (.) or dash (-). Changed to \"%s\"",
177+
config.ErrInvalidValue, srv.Type, newServiceType,
178178
)
179179
warnings.Append(warning)
180180

181-
srv.ServiceType = newServiceType
181+
srv.Type = newServiceType
182182
}
183183

184184
// SSL and StartTLS can't be used at the same time.
185185
if srv.SSL && srv.StartTLS {
186186
warning := fmt.Errorf(
187187
"%w: service '%s' can't set both SSL and StartTLS, StartTLS will be used",
188-
config.ErrInvalidValue, srv.ServiceType,
188+
config.ErrInvalidValue, srv.Type,
189189
)
190190
warnings.Append(warning)
191191

@@ -198,7 +198,7 @@ func validateServices(services []config.Service) (map[NameInstance]config.Servic
198198
default:
199199
warning := fmt.Errorf(
200200
"%w: service '%s' has an unsupported stats protocol: '%s'",
201-
config.ErrInvalidValue, srv.ServiceType, srv.StatsProtocol,
201+
config.ErrInvalidValue, srv.Type, srv.StatsProtocol,
202202
)
203203
warnings.Append(warning)
204204

@@ -209,15 +209,15 @@ func validateServices(services []config.Service) (map[NameInstance]config.Servic
209209

210210
// Check for duplicated overrides.
211211
key := NameInstance{
212-
Name: srv.ServiceType,
213-
Instance: srv.ServiceInstance,
212+
Name: srv.Type,
213+
Instance: srv.Instance,
214214
}
215215

216216
if _, ok := serviceMap[key]; ok {
217-
warning := fmt.Sprintf("a service override is duplicated for '%s'", srv.ServiceType)
217+
warning := fmt.Sprintf("a service override is duplicated for '%s'", srv.Type)
218218

219-
if srv.ServiceInstance != "" {
220-
warning = fmt.Sprintf("%s on instance '%s'", warning, srv.ServiceInstance)
219+
if srv.Instance != "" {
220+
warning = fmt.Sprintf("%s on instance '%s'", warning, srv.Instance)
221221
}
222222

223223
warnings.Append(fmt.Errorf("%w: %s", config.ErrInvalidValue, warning))
@@ -558,8 +558,8 @@ func copyAndMergeServiceWithOverride(servicesMap map[NameInstance]Service, overr
558558

559559
for _, v := range overrides {
560560
key := NameInstance{
561-
Name: v.ServiceType,
562-
Instance: v.ServiceInstance,
561+
Name: v.Type,
562+
Instance: v.Instance,
563563
}
564564
service := serviceMapWithOverride[key]
565565

@@ -593,8 +593,8 @@ func applyOverrideInPlace(
593593
for _, serviceKey := range serviceKeys {
594594
service := servicesMap[serviceKey]
595595

596-
if service.Name != service.Config.ServiceType && service.Config.ServiceType != "" {
597-
service.Name = service.Config.ServiceType
596+
if service.Name != service.Config.Type && service.Config.Type != "" {
597+
service.Name = service.Config.Type
598598
service.ServiceType = ""
599599
}
600600

@@ -605,8 +605,8 @@ func applyOverrideInPlace(
605605
service.ServiceType = CustomService
606606
}
607607

608-
if service.Config.ServiceInstance != "" {
609-
service.Instance = service.Config.ServiceInstance
608+
if service.Config.Instance != "" {
609+
service.Instance = service.Config.Instance
610610
}
611611

612612
service.Active = true

0 commit comments

Comments
 (0)