From ac53debe82b1fb88451d40ea71a97056ca126056 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Tue, 16 Feb 2021 09:56:37 +0100 Subject: [PATCH 1/4] a --- .../testdata/endpoint_basic-endpoint-security.yml | 1 + .../pkg/agent/program/testdata/endpoint_basic.yml | 1 + x-pack/elastic-agent/pkg/config/config.go | 5 +++++ x-pack/elastic-agent/pkg/core/server/server.go | 9 +++++++++ 4 files changed, 16 insertions(+) diff --git a/x-pack/elastic-agent/pkg/agent/program/testdata/endpoint_basic-endpoint-security.yml b/x-pack/elastic-agent/pkg/agent/program/testdata/endpoint_basic-endpoint-security.yml index b77a83633aef..d81d276f3685 100644 --- a/x-pack/elastic-agent/pkg/agent/program/testdata/endpoint_basic-endpoint-security.yml +++ b/x-pack/elastic-agent/pkg/agent/program/testdata/endpoint_basic-endpoint-security.yml @@ -2,6 +2,7 @@ revision: 5 fleet: agent: id: fleet-agent-id + logging.level: error host: id: host-agent-id api: diff --git a/x-pack/elastic-agent/pkg/agent/program/testdata/endpoint_basic.yml b/x-pack/elastic-agent/pkg/agent/program/testdata/endpoint_basic.yml index 728b4813a4eb..1681926c56e8 100644 --- a/x-pack/elastic-agent/pkg/agent/program/testdata/endpoint_basic.yml +++ b/x-pack/elastic-agent/pkg/agent/program/testdata/endpoint_basic.yml @@ -3,6 +3,7 @@ name: Endpoint Host fleet: agent: id: fleet-agent-id + logging.level: error host: id: host-agent-id access_api_key: VuaCfGcBCdbkQm-e5aOx:ui2lp2axTNmsyakw9tvNnw diff --git a/x-pack/elastic-agent/pkg/config/config.go b/x-pack/elastic-agent/pkg/config/config.go index 593631f0050e..c065d955aff8 100644 --- a/x-pack/elastic-agent/pkg/config/config.go +++ b/x-pack/elastic-agent/pkg/config/config.go @@ -116,6 +116,11 @@ func NewConfigFrom(from interface{}, opts ...interface{}) (*Config, error) { } if len(skippedKeys) > 0 { err = cfg.Merge(skippedKeys, ucfg.ResolveNOOP) + + // we're modifying object + for k, v := range skippedKeys { + data[k] = v + } } return newConfigFrom(cfg), err } diff --git a/x-pack/elastic-agent/pkg/core/server/server.go b/x-pack/elastic-agent/pkg/core/server/server.go index f0b8ac73d8a5..c84d7de9a5d9 100644 --- a/x-pack/elastic-agent/pkg/core/server/server.go +++ b/x-pack/elastic-agent/pkg/core/server/server.go @@ -249,9 +249,11 @@ func (s *Server) Checkin(server proto.ElasticAgent_CheckinServer) error { }() var ok bool + var observedConfigStateIdx uint64 var firstCheckin *proto.StateObserved select { case firstCheckin, ok = <-firstCheckinChan: + observedConfigStateIdx = firstCheckin.ConfigStateIdx break case <-time.After(InitialCheckinTimeout): // close connection @@ -281,6 +283,13 @@ func (s *Server) Checkin(server proto.ElasticAgent_CheckinServer) error { s.logger.Debug("check-in stream cannot connect, application is being destroyed; closing connection") return status.Error(codes.Unavailable, "application cannot connect being destroyed") } + + // application is running as a service and counter is already counting + // force config reload + if observedConfigStateIdx > 0 { + appState.expectedConfigIdx = observedConfigStateIdx + 1 + } + checkinDone := make(chan bool) appState.checkinDone = checkinDone appState.checkinLock.Unlock() From b99169dfbe3b0afe0b2676dd68e12da95e53e02d Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Tue, 16 Feb 2021 13:05:04 +0100 Subject: [PATCH 2/4] changelog --- x-pack/elastic-agent/CHANGELOG.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/elastic-agent/CHANGELOG.asciidoc b/x-pack/elastic-agent/CHANGELOG.asciidoc index 58f827aca178..b0b5066d27d2 100644 --- a/x-pack/elastic-agent/CHANGELOG.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.asciidoc @@ -34,6 +34,7 @@ - Fixed Monitoring filebeat and metricbeat not connecting to Agent over GRPC {pull}23843[23843] - Fixed make status readable in the log. {pull}23849[23849] - Windows agent doesn't uninstall with a lowercase `c:` drive in the path {pull}23998[23998] +- Fix reloading of log level for services {pull}[24055]24055 ==== New features From 9e1f96dbd7771ff14b91f08b40d68aa5638e2a5d Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Tue, 16 Feb 2021 13:42:29 +0100 Subject: [PATCH 3/4] nil check --- x-pack/elastic-agent/pkg/core/server/server.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/elastic-agent/pkg/core/server/server.go b/x-pack/elastic-agent/pkg/core/server/server.go index c84d7de9a5d9..97517eb6ce6b 100644 --- a/x-pack/elastic-agent/pkg/core/server/server.go +++ b/x-pack/elastic-agent/pkg/core/server/server.go @@ -253,7 +253,9 @@ func (s *Server) Checkin(server proto.ElasticAgent_CheckinServer) error { var firstCheckin *proto.StateObserved select { case firstCheckin, ok = <-firstCheckinChan: - observedConfigStateIdx = firstCheckin.ConfigStateIdx + if firstCheckin != nil { + observedConfigStateIdx = firstCheckin.ConfigStateIdx + } break case <-time.After(InitialCheckinTimeout): // close connection From a599a3b60508a811c9c226163f0794d5d9307ea2 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Tue, 16 Feb 2021 13:43:48 +0100 Subject: [PATCH 4/4] comment --- x-pack/elastic-agent/pkg/config/config.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/elastic-agent/pkg/config/config.go b/x-pack/elastic-agent/pkg/config/config.go index c065d955aff8..2de84972a6b6 100644 --- a/x-pack/elastic-agent/pkg/config/config.go +++ b/x-pack/elastic-agent/pkg/config/config.go @@ -117,7 +117,8 @@ func NewConfigFrom(from interface{}, opts ...interface{}) (*Config, error) { if len(skippedKeys) > 0 { err = cfg.Merge(skippedKeys, ucfg.ResolveNOOP) - // we're modifying object + // we modified incoming object + // cleanup so skipped keys are not missing for k, v := range skippedKeys { data[k] = v }