Skip to content

Commit

Permalink
[Heartbeat] Use service.name not service_name in configs
Browse files Browse the repository at this point in the history
Using the nesting this way lets us handle future fields like
`service.environment` more cleanly if/when they become available.

See https://github.com/elastic/ecs/blob/master/rfcs/text/0002-rfc-environment.md
for the proposal to add service.environment
  • Loading branch information
andrewvc committed Jul 30, 2020
1 parent e64fa2d commit 1e43b22
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion heartbeat/_meta/config/beat.reference.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ heartbeat.monitors:
name: my-icmp-monitor

# Name of corresponding APM service, if Elastic APM is in use for the monitored service.
# service_name: my-apm-service-name
# service.name: my-apm-service-name

# Enable/Disable monitor
#enabled: true
Expand Down
2 changes: 1 addition & 1 deletion heartbeat/_meta/config/beat.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ heartbeat.monitors:
# Total test connection and data exchange timeout
#timeout: 16s
# Name of corresponding APM service, if Elastic APM is in use for the monitored service.
#service_name: my-apm-service-name
#service.name: my-apm-service-name

{{header "Elasticsearch template setting"}}

Expand Down
4 changes: 2 additions & 2 deletions heartbeat/docs/getting-started.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ heartbeat.monitors:
- type: http
schedule: '@every 5s'
urls: ["http://example.net"]
service_name: apm-service-name <4>
service.name: apm-service-name <4>
id: my-http-service
name: My HTTP Service
----------------------------------------------------------------------
Expand All @@ -92,7 +92,7 @@ https://github.com/gorhill/cronexpr#implementation[this `cronexpr` implementatio
was started. Heartbeat adds the `@every` keyword to the syntax provided by the
`cronexpr` package.
<3> The `mode` specifies whether to ping one IP (`any`) or all resolvable IPs
<4> The `service_name` field can be used to integrate heartbeat with elastic APM via the Uptime UI.
<4> The `service.name` field can be used to integrate heartbeat with elastic APM via the Uptime UI.

include::{libbeat-dir}/shared/config-check.asciidoc[]

Expand Down
2 changes: 1 addition & 1 deletion heartbeat/docs/heartbeat-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ heartbeat.monitors:
- type: http
id: service-status
name: Service Status
service_name: my-apm-service-name
service.name: my-apm-service-name
hosts: ["http://localhost:80/service/status"]
check.response.status: [200]
schedule: '@every 5s'
Expand Down
2 changes: 1 addition & 1 deletion heartbeat/docs/monitors/monitor-common-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ as `monitor.name`.

[float]
[[service-name]]
==== `service_name`
==== `service.name`

Optional APM service name for this monitor. Corresponds to the `service.name` ECS field. Set this when monitoring an app
that is also using APM to enable integrations between Uptime and APM data in Kibana.
Expand Down
2 changes: 1 addition & 1 deletion heartbeat/heartbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ heartbeat.monitors:
name: my-icmp-monitor

# Name of corresponding APM service, if Elastic APM is in use for the monitored service.
# service_name: my-apm-service-name
# service.name: my-apm-service-name

# Enable/Disable monitor
#enabled: true
Expand Down
2 changes: 1 addition & 1 deletion heartbeat/heartbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ heartbeat.monitors:
# Total test connection and data exchange timeout
#timeout: 16s
# Name of corresponding APM service, if Elastic APM is in use for the monitored service.
#service_name: my-apm-service-name
#service.name: my-apm-service-name

# ======================= Elasticsearch template setting =======================

Expand Down
2 changes: 1 addition & 1 deletion heartbeat/monitors.d/sample.http.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
name: My HTTP Monitor

# Name of corresponding APM service, if Elastic APM is in use for the monitored service.
#service_name: my-apm-service-name
#service.name: my-apm-service-name

# Enable/Disable monitor
#enabled: true
Expand Down
2 changes: 1 addition & 1 deletion heartbeat/monitors.d/sample.icmp.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
name: My ICMP Monitor

# Name of corresponding APM service, if Elastic APM is in use for the monitored service.
#service_name: my-apm-service-name
#service.name: my-apm-service-name

# Enable/Disable monitor
#enabled: true
Expand Down
2 changes: 1 addition & 1 deletion heartbeat/monitors.d/sample.tcp.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
name: My TCP monitor

# Name of corresponding APM service, if Elastic APM is in use for the monitored service.
#service_name: my-apm-service-name
#service.name: my-apm-service-name

# Enable/Disable monitor
#enabled: true
Expand Down
6 changes: 5 additions & 1 deletion heartbeat/monitors/stdfields/stdfields.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ import (
// ErrPluginDisabled is returned when the monitor plugin is marked as disabled.
var ErrPluginDisabled = errors.New("Monitor not loaded, plugin is disabled")

type ServiceFields struct {
Name string `config:"name"`
}

// StdMonitorFields represents the generic configuration options around a monitor plugin.
type StdMonitorFields struct {
ID string `config:"id"`
Name string `config:"name"`
Type string `config:"type" validate:"required"`
Schedule *schedule.Schedule `config:"schedule" validate:"required"`
Timeout time.Duration `config:"timeout"`
ServiceName string `config:"service_name"`
Service ServiceFields `config:"service"`
Enabled bool `config:"enabled"`
}

Expand Down
4 changes: 2 additions & 2 deletions heartbeat/monitors/wrappers/monitors.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ func addMonitorMeta(stdMonFields stdfields.StdMonitorFields, isMulti bool) jobs.
},
}

if stdMonFields.ServiceName != "" {
if stdMonFields.Service.Name != "" {
fieldsToMerge["service"] = common.MapStr{
"name": stdMonFields.ServiceName,
"name": stdMonFields.Service.Name,
}
}

Expand Down
4 changes: 2 additions & 2 deletions heartbeat/monitors/wrappers/monitors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestSimpleJob(t *testing.T) {

func TestJobWithServiceName(t *testing.T) {
fields := testMonFields
fields.ServiceName = "testServiceName"
fields.Service.Name = "testServiceName"
testCommonWrap(t, testDef{
"simple",
fields,
Expand All @@ -123,7 +123,7 @@ func TestJobWithServiceName(t *testing.T) {
"check_group": isdef.IsString,
},
"service": map[string]interface{}{
"name": fields.ServiceName,
"name": fields.Service.Name,
},
}),
hbtestllext.MonitorTimespanValidator,
Expand Down

0 comments on commit 1e43b22

Please sign in to comment.