From 1e43b22f4b06d6ea58e51dd021422bc8cefbf059 Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Wed, 29 Jul 2020 21:04:59 -0500 Subject: [PATCH 01/11] [Heartbeat] Use service.name not service_name in configs 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 --- heartbeat/_meta/config/beat.reference.yml.tmpl | 2 +- heartbeat/_meta/config/beat.yml.tmpl | 2 +- heartbeat/docs/getting-started.asciidoc | 4 ++-- heartbeat/docs/heartbeat-options.asciidoc | 2 +- heartbeat/docs/monitors/monitor-common-options.asciidoc | 2 +- heartbeat/heartbeat.reference.yml | 2 +- heartbeat/heartbeat.yml | 2 +- heartbeat/monitors.d/sample.http.yml.disabled | 2 +- heartbeat/monitors.d/sample.icmp.yml.disabled | 2 +- heartbeat/monitors.d/sample.tcp.yml.disabled | 2 +- heartbeat/monitors/stdfields/stdfields.go | 6 +++++- heartbeat/monitors/wrappers/monitors.go | 4 ++-- heartbeat/monitors/wrappers/monitors_test.go | 4 ++-- 13 files changed, 20 insertions(+), 16 deletions(-) diff --git a/heartbeat/_meta/config/beat.reference.yml.tmpl b/heartbeat/_meta/config/beat.reference.yml.tmpl index 1b4cd61937af..6cc417ccc982 100644 --- a/heartbeat/_meta/config/beat.reference.yml.tmpl +++ b/heartbeat/_meta/config/beat.reference.yml.tmpl @@ -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 diff --git a/heartbeat/_meta/config/beat.yml.tmpl b/heartbeat/_meta/config/beat.yml.tmpl index d1557176903e..3da9e911b998 100644 --- a/heartbeat/_meta/config/beat.yml.tmpl +++ b/heartbeat/_meta/config/beat.yml.tmpl @@ -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"}} diff --git a/heartbeat/docs/getting-started.asciidoc b/heartbeat/docs/getting-started.asciidoc index 21da1fb05471..267f0d2330a6 100644 --- a/heartbeat/docs/getting-started.asciidoc +++ b/heartbeat/docs/getting-started.asciidoc @@ -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 ---------------------------------------------------------------------- @@ -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[] diff --git a/heartbeat/docs/heartbeat-options.asciidoc b/heartbeat/docs/heartbeat-options.asciidoc index 5d29987f27bc..0b34eb4e6108 100644 --- a/heartbeat/docs/heartbeat-options.asciidoc +++ b/heartbeat/docs/heartbeat-options.asciidoc @@ -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' diff --git a/heartbeat/docs/monitors/monitor-common-options.asciidoc b/heartbeat/docs/monitors/monitor-common-options.asciidoc index ac1e0b27a1cb..3114deda14e9 100644 --- a/heartbeat/docs/monitors/monitor-common-options.asciidoc +++ b/heartbeat/docs/monitors/monitor-common-options.asciidoc @@ -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. diff --git a/heartbeat/heartbeat.reference.yml b/heartbeat/heartbeat.reference.yml index 2bdb968eb496..0e57b37dd5d0 100644 --- a/heartbeat/heartbeat.reference.yml +++ b/heartbeat/heartbeat.reference.yml @@ -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 diff --git a/heartbeat/heartbeat.yml b/heartbeat/heartbeat.yml index 19c3f79e9689..56e740a84e1e 100644 --- a/heartbeat/heartbeat.yml +++ b/heartbeat/heartbeat.yml @@ -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 ======================= diff --git a/heartbeat/monitors.d/sample.http.yml.disabled b/heartbeat/monitors.d/sample.http.yml.disabled index 93284e6ae403..31359b9597b6 100644 --- a/heartbeat/monitors.d/sample.http.yml.disabled +++ b/heartbeat/monitors.d/sample.http.yml.disabled @@ -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 diff --git a/heartbeat/monitors.d/sample.icmp.yml.disabled b/heartbeat/monitors.d/sample.icmp.yml.disabled index f41e018aba2c..b79fdf75ddac 100644 --- a/heartbeat/monitors.d/sample.icmp.yml.disabled +++ b/heartbeat/monitors.d/sample.icmp.yml.disabled @@ -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 diff --git a/heartbeat/monitors.d/sample.tcp.yml.disabled b/heartbeat/monitors.d/sample.tcp.yml.disabled index 4e922a1b53ea..1b6aeda72015 100644 --- a/heartbeat/monitors.d/sample.tcp.yml.disabled +++ b/heartbeat/monitors.d/sample.tcp.yml.disabled @@ -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 diff --git a/heartbeat/monitors/stdfields/stdfields.go b/heartbeat/monitors/stdfields/stdfields.go index 53ba59ada881..0ce19e44ad4a 100644 --- a/heartbeat/monitors/stdfields/stdfields.go +++ b/heartbeat/monitors/stdfields/stdfields.go @@ -29,6 +29,10 @@ 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"` @@ -36,7 +40,7 @@ type StdMonitorFields struct { 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"` } diff --git a/heartbeat/monitors/wrappers/monitors.go b/heartbeat/monitors/wrappers/monitors.go index 7896bcf12f04..28cd4aa8cfd6 100644 --- a/heartbeat/monitors/wrappers/monitors.go +++ b/heartbeat/monitors/wrappers/monitors.go @@ -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, } } diff --git a/heartbeat/monitors/wrappers/monitors_test.go b/heartbeat/monitors/wrappers/monitors_test.go index 49b2100827b2..d8ff497225ef 100644 --- a/heartbeat/monitors/wrappers/monitors_test.go +++ b/heartbeat/monitors/wrappers/monitors_test.go @@ -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, @@ -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, From efd1cea66443dc6b9c91716eb8f146245e4d303e Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Thu, 30 Jul 2020 17:48:54 -0500 Subject: [PATCH 02/11] Add sample agent.yml --- x-pack/elastic-agent/_meta/elastic-agent.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/x-pack/elastic-agent/_meta/elastic-agent.yml b/x-pack/elastic-agent/_meta/elastic-agent.yml index b084f0661a16..180c65639ca7 100644 --- a/x-pack/elastic-agent/_meta/elastic-agent.yml +++ b/x-pack/elastic-agent/_meta/elastic-agent.yml @@ -9,6 +9,26 @@ outputs: password: changeme inputs: + - type: synthetics/monitors + streams: + - type: http + name: MyHTTPMonitor + id: my-id + target: "https://elastic.co" + schedule: "@every 10s" + http: # example HTTP specific option + user: blah + password: something else + - type: icmp + name: MyICMPMonitor + id: my-icmp-id + target: "elastic.co" + schedule: "@every 10s" + - type: tcp + name: MyTCPMonitor + id: my-tcp-id + target: "elastic.co:80" + schedule: "@every 10s" - type: system/metrics # The only two requirement are that it has only characters allowed in an Elasticsearch index name From 99245abab60406d98de9aeb8e0388ce5252b20d9 Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Thu, 30 Jul 2020 17:49:33 -0500 Subject: [PATCH 03/11] Revert "Add sample agent.yml" This reverts commit efd1cea66443dc6b9c91716eb8f146245e4d303e. --- x-pack/elastic-agent/_meta/elastic-agent.yml | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/x-pack/elastic-agent/_meta/elastic-agent.yml b/x-pack/elastic-agent/_meta/elastic-agent.yml index 180c65639ca7..b084f0661a16 100644 --- a/x-pack/elastic-agent/_meta/elastic-agent.yml +++ b/x-pack/elastic-agent/_meta/elastic-agent.yml @@ -9,26 +9,6 @@ outputs: password: changeme inputs: - - type: synthetics/monitors - streams: - - type: http - name: MyHTTPMonitor - id: my-id - target: "https://elastic.co" - schedule: "@every 10s" - http: # example HTTP specific option - user: blah - password: something else - - type: icmp - name: MyICMPMonitor - id: my-icmp-id - target: "elastic.co" - schedule: "@every 10s" - - type: tcp - name: MyTCPMonitor - id: my-tcp-id - target: "elastic.co:80" - schedule: "@every 10s" - type: system/metrics # The only two requirement are that it has only characters allowed in an Elasticsearch index name From e73652249f5a24ee808b2fa865192dde0901cd3d Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Wed, 5 Aug 2020 17:26:55 -0500 Subject: [PATCH 04/11] FMT --- heartbeat/monitors/stdfields/stdfields.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/heartbeat/monitors/stdfields/stdfields.go b/heartbeat/monitors/stdfields/stdfields.go index 0ce19e44ad4a..4bfa767a5eb0 100644 --- a/heartbeat/monitors/stdfields/stdfields.go +++ b/heartbeat/monitors/stdfields/stdfields.go @@ -35,13 +35,13 @@ type ServiceFields struct { // 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"` - Service ServiceFields `config:"service"` - Enabled bool `config:"enabled"` + 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"` + Service ServiceFields `config:"service"` + Enabled bool `config:"enabled"` } func ConfigToStdMonitorFields(config *common.Config) (StdMonitorFields, error) { From a8ca9f1312d2d162f6a77dc161b7fb0b709b0a64 Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Thu, 6 Aug 2020 07:58:53 -0500 Subject: [PATCH 05/11] More work --- heartbeat/beater/heartbeat.go | 1 - heartbeat/monitors/task.go | 2 ++ libbeat/publisher/pipeline/client.go | 2 ++ libbeat/publisher/pipeline/pipeline.go | 1 + x-pack/elastic-agent/elastic-agent.yml | 33 +++++++------------------- 5 files changed, 14 insertions(+), 25 deletions(-) diff --git a/heartbeat/beater/heartbeat.go b/heartbeat/beater/heartbeat.go index 7e0f2aa75a1e..4fb8d6891a40 100644 --- a/heartbeat/beater/heartbeat.go +++ b/heartbeat/beater/heartbeat.go @@ -54,7 +54,6 @@ func New(b *beat.Beat, rawConfig *common.Config) (beat.Beater, error) { if err := rawConfig.Unpack(&parsedConfig); err != nil { return nil, fmt.Errorf("Error reading config file: %v", err) } - limit := parsedConfig.Scheduler.Limit locationName := parsedConfig.Scheduler.Location if locationName == "" { diff --git a/heartbeat/monitors/task.go b/heartbeat/monitors/task.go index 0853b5547183..3d4ae86ea735 100644 --- a/heartbeat/monitors/task.go +++ b/heartbeat/monitors/task.go @@ -154,9 +154,11 @@ func runPublishJob(job jobs.Job, client beat.Client) []scheduler.TaskFunc { Meta: event.Meta.Clone(), Fields: event.Fields.Clone(), } + logp.Warn("PUBLISH TO LIBBEAT") client.Publish(clone) } else { // no clone needed if no continuations + logp.Warn("PUBLISH TO LIBBEAT") client.Publish(*event) } } diff --git a/libbeat/publisher/pipeline/client.go b/libbeat/publisher/pipeline/client.go index 2ce792ed8875..f3061cdc4fc7 100644 --- a/libbeat/publisher/pipeline/client.go +++ b/libbeat/publisher/pipeline/client.go @@ -73,6 +73,7 @@ func (c *client) PublishAll(events []beat.Event) { } func (c *client) Publish(e beat.Event) { + logp.Warn("ATRACE publish") c.mutex.Lock() defer c.mutex.Unlock() @@ -144,6 +145,7 @@ func (c *client) publish(e beat.Event) { } func (c *client) Close() error { + logp.Warn("ATRACE Closing beats Pipeline") log := c.logger() // first stop ack handling. ACK handler might block on wait (with timeout), waiting diff --git a/libbeat/publisher/pipeline/pipeline.go b/libbeat/publisher/pipeline/pipeline.go index 80b439d96e6d..aea208618474 100644 --- a/libbeat/publisher/pipeline/pipeline.go +++ b/libbeat/publisher/pipeline/pipeline.go @@ -283,6 +283,7 @@ func (p *Pipeline) ConnectWith(cfg beat.ClientConfig) (beat.Client, error) { return nil, err } + logp.Warn("ATRACE make client") client := &client{ pipeline: p, closeRef: cfg.CloseRef, diff --git a/x-pack/elastic-agent/elastic-agent.yml b/x-pack/elastic-agent/elastic-agent.yml index a78b05981426..35b3af876495 100644 --- a/x-pack/elastic-agent/elastic-agent.yml +++ b/x-pack/elastic-agent/elastic-agent.yml @@ -14,32 +14,17 @@ outputs: username: elastic password: changeme +agent.monitoring.enabled: false + inputs: - - type: system/metrics - - # The only two requirement are that it has only characters allowed in an Elasticsearch index name - # Index names must meet the following criteria: - # Lowercase only - # Cannot include \, /, *, ?, ", <, >, |, ` ` (space character), ,, # - # Cannot start with -, _, + - # Cannot be . or .. + - type: synthetics/http + id: unique-http-id + name: my-http + schedule: '@every 10s' + hosts: ["http://elastic.co"] + timeout: 16s + wait: 1s dataset.namespace: default - use_output: default - streams: - - metricset: cpu - # The only two requirement are that it has only characters allowed in an Elasticsearch index name - # Index names must meet the following criteria: - # Lowercase only - # Cannot include \, /, *, ?, ", <, >, |, ` ` (space character), ,, # - # Cannot start with -, _, + - # Cannot be . or .. - dataset.name: system.cpu - - metricset: memory - dataset.name: system.memory - - metricset: network - dataset.name: system.network - - metricset: filesystem - dataset.name: system.filesystem # agent.monitoring: # # enabled turns on monitoring of running processes From debf1665ffb860c80ea2e046f86fbec594812d85 Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Tue, 20 Oct 2020 18:41:46 -0500 Subject: [PATCH 06/11] Remove debugger traces --- heartbeat/monitors/task.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/heartbeat/monitors/task.go b/heartbeat/monitors/task.go index c86c9c4ded65..eb53ddeb1953 100644 --- a/heartbeat/monitors/task.go +++ b/heartbeat/monitors/task.go @@ -122,11 +122,9 @@ func runPublishJob(job jobs.Job, client beat.Client) []scheduler.TaskFunc { Meta: event.Meta.Clone(), Fields: event.Fields.Clone(), } - logp.Warn("PUBLISH TO LIBBEAT") client.Publish(clone) } else { // no clone needed if no continuations - logp.Warn("PUBLISH TO LIBBEAT") client.Publish(*event) } } From 0fb831c6ca52bd0571aa819d36eae1de8f58ad99 Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Tue, 20 Oct 2020 18:42:37 -0500 Subject: [PATCH 07/11] Remove debugger traces --- libbeat/publisher/pipeline/client.go | 2 -- libbeat/publisher/pipeline/pipeline.go | 1 - 2 files changed, 3 deletions(-) diff --git a/libbeat/publisher/pipeline/client.go b/libbeat/publisher/pipeline/client.go index 9f0d8e7217a1..edb5a3f1eb35 100644 --- a/libbeat/publisher/pipeline/client.go +++ b/libbeat/publisher/pipeline/client.go @@ -74,7 +74,6 @@ func (c *client) PublishAll(events []beat.Event) { } func (c *client) Publish(e beat.Event) { - logp.Warn("ATRACE publish") c.mutex.Lock() defer c.mutex.Unlock() @@ -146,7 +145,6 @@ func (c *client) publish(e beat.Event) { } func (c *client) Close() error { - logp.Warn("ATRACE Closing beats Pipeline") log := c.logger() // first stop ack handling. ACK handler might block on wait (with timeout), waiting diff --git a/libbeat/publisher/pipeline/pipeline.go b/libbeat/publisher/pipeline/pipeline.go index aea208618474..80b439d96e6d 100644 --- a/libbeat/publisher/pipeline/pipeline.go +++ b/libbeat/publisher/pipeline/pipeline.go @@ -283,7 +283,6 @@ func (p *Pipeline) ConnectWith(cfg beat.ClientConfig) (beat.Client, error) { return nil, err } - logp.Warn("ATRACE make client") client := &client{ pipeline: p, closeRef: cfg.CloseRef, From 8c32645ca84a65719733e36070f103b6d1cfbbe4 Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Wed, 11 Nov 2020 20:08:14 -0600 Subject: [PATCH 08/11] Add legacy support and tests --- heartbeat/monitors/stdfields/stdfields.go | 25 +++++-- .../monitors/stdfields/stdfields_test.go | 65 +++++++++++++++++++ 2 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 heartbeat/monitors/stdfields/stdfields_test.go diff --git a/heartbeat/monitors/stdfields/stdfields.go b/heartbeat/monitors/stdfields/stdfields.go index 4bfa767a5eb0..6fee706be35c 100644 --- a/heartbeat/monitors/stdfields/stdfields.go +++ b/heartbeat/monitors/stdfields/stdfields.go @@ -18,6 +18,7 @@ package stdfields import ( + "fmt" "time" "github.com/pkg/errors" @@ -35,22 +36,32 @@ type ServiceFields struct { // 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"` - Service ServiceFields `config:"service"` - Enabled bool `config:"enabled"` + 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"` + Service ServiceFields `config:"service"` + LegacyServiceName string `config:"service_name""` + Enabled bool `config:"enabled"` } func ConfigToStdMonitorFields(config *common.Config) (StdMonitorFields, error) { mpi := StdMonitorFields{Enabled: true} if err := config.Unpack(&mpi); err != nil { + fmt.Printf("HIER %s", err) return mpi, errors.Wrap(err, "error unpacking monitor plugin config") } + // Use `service_name` if `service.name` is unspecified + // `service_name` was only document in the 7.10.0 release. + if mpi.LegacyServiceName != "" { + if mpi.Service.Name == "" { + mpi.Service.Name = mpi.LegacyServiceName + } + } + if !mpi.Enabled { return mpi, ErrPluginDisabled } diff --git a/heartbeat/monitors/stdfields/stdfields_test.go b/heartbeat/monitors/stdfields/stdfields_test.go new file mode 100644 index 000000000000..c20fc28688ab --- /dev/null +++ b/heartbeat/monitors/stdfields/stdfields_test.go @@ -0,0 +1,65 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 stdfields + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/elastic/beats/v7/libbeat/common" +) + +func TestLegacyServiceNameConfig(t *testing.T) { + srvName := "myService" + + configBase := func() common.MapStr { + return common.MapStr{ + "type": "http", + "id": "myId", + "schedule": "@every 1s", + } + } + + legacyOnly := configBase() + legacyOnly["service_name"] = srvName + + newOnly := configBase() + newOnly["service"] = common.MapStr{"name": srvName} + + mix := configBase() + mix["service"] = common.MapStr{"name": srvName} + mix["service_name"] = "ignoreMe" + + confMaps := []common.MapStr{ + legacyOnly, + newOnly, + mix, + } + + for _, cm := range confMaps { + t.Run(fmt.Sprintf("given config map %#v", cm), func(t *testing.T) { + c, err := common.NewConfigFrom(cm) + require.NoError(t, err) + f, err := ConfigToStdMonitorFields(c) + require.Equal(t, srvName, f.Service.Name) + }) + } + +} From f7dfcfd8f73c6ce655668d289d1dbd55424c042f Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Wed, 11 Nov 2020 20:12:07 -0600 Subject: [PATCH 09/11] Add changelog --- CHANGELOG.next.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 72c80626c937..012db75a465e 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -100,7 +100,6 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d *Heartbeat* - *Journalbeat* - Improve parsing of syslog.pid in journalbeat to strip the username when present {pull}16116[16116] @@ -341,6 +340,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d *Heartbeat* +- The `service_name` monitor option is being replaced with `service.name` which is more correct. We will support the old option till 8.0. {pull}20330[20330] *Journalbeat* From 799be2a44ada8d8139ce6a8630b9ad1fbf8eaefc Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Thu, 12 Nov 2020 12:04:54 -0600 Subject: [PATCH 10/11] Remove extra quote --- heartbeat/monitors/stdfields/stdfields.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/heartbeat/monitors/stdfields/stdfields.go b/heartbeat/monitors/stdfields/stdfields.go index 6fee706be35c..784b84cabd7b 100644 --- a/heartbeat/monitors/stdfields/stdfields.go +++ b/heartbeat/monitors/stdfields/stdfields.go @@ -42,7 +42,7 @@ type StdMonitorFields struct { Schedule *schedule.Schedule `config:"schedule" validate:"required"` Timeout time.Duration `config:"timeout"` Service ServiceFields `config:"service"` - LegacyServiceName string `config:"service_name""` + LegacyServiceName string `config:"service_name"` Enabled bool `config:"enabled"` } From 95c2bc215674de226cb464e91cf1c4513a1d6797 Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Thu, 12 Nov 2020 13:14:55 -0600 Subject: [PATCH 11/11] Mage update --- x-pack/heartbeat/heartbeat.reference.yml | 2 +- x-pack/heartbeat/heartbeat.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/heartbeat/heartbeat.reference.yml b/x-pack/heartbeat/heartbeat.reference.yml index 41cecf5143a4..c182cd6fe3b0 100644 --- a/x-pack/heartbeat/heartbeat.reference.yml +++ b/x-pack/heartbeat/heartbeat.reference.yml @@ -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 diff --git a/x-pack/heartbeat/heartbeat.yml b/x-pack/heartbeat/heartbeat.yml index 19c3f79e9689..56e740a84e1e 100644 --- a/x-pack/heartbeat/heartbeat.yml +++ b/x-pack/heartbeat/heartbeat.yml @@ -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 =======================