From da7de8d65981dd0101f6c20e1bd5464a35b57f35 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Tue, 16 Feb 2021 19:03:09 +0100 Subject: [PATCH] [Ingest Management] Fix reloading of log level for services (#24055) (#24062) [Ingest Management] Fix reloading of log level for services (#24055) --- x-pack/elastic-agent/CHANGELOG.asciidoc | 1 + .../testdata/endpoint_basic-endpoint-security.yml | 1 + .../pkg/agent/program/testdata/endpoint_basic.yml | 1 + x-pack/elastic-agent/pkg/config/config.go | 6 ++++++ x-pack/elastic-agent/pkg/core/server/server.go | 11 +++++++++++ 5 files changed, 20 insertions(+) diff --git a/x-pack/elastic-agent/CHANGELOG.asciidoc b/x-pack/elastic-agent/CHANGELOG.asciidoc index d3fd1fa65d5..c53f14af7fc 100644 --- a/x-pack/elastic-agent/CHANGELOG.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.asciidoc @@ -29,6 +29,7 @@ - Fix timeout issue stopping service applications {pull}20256[20256] - Fix incorrect hash when upgrading agent {pull}22322[22322] - Fixed nil pointer during unenroll {pull}23609[23609] +- Fix reloading of log level for services {pull}[24055]24055 ==== New features 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 b77a83633ae..d81d276f368 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 9eee9b3a01d..0ac80534c6c 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 593631f0050..2de84972a6b 100644 --- a/x-pack/elastic-agent/pkg/config/config.go +++ b/x-pack/elastic-agent/pkg/config/config.go @@ -116,6 +116,12 @@ func NewConfigFrom(from interface{}, opts ...interface{}) (*Config, error) { } if len(skippedKeys) > 0 { err = cfg.Merge(skippedKeys, ucfg.ResolveNOOP) + + // we modified incoming object + // cleanup so skipped keys are not missing + 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 f0b8ac73d8a..97517eb6ce6 100644 --- a/x-pack/elastic-agent/pkg/core/server/server.go +++ b/x-pack/elastic-agent/pkg/core/server/server.go @@ -249,9 +249,13 @@ func (s *Server) Checkin(server proto.ElasticAgent_CheckinServer) error { }() var ok bool + var observedConfigStateIdx uint64 var firstCheckin *proto.StateObserved select { case firstCheckin, ok = <-firstCheckinChan: + if firstCheckin != nil { + observedConfigStateIdx = firstCheckin.ConfigStateIdx + } break case <-time.After(InitialCheckinTimeout): // close connection @@ -281,6 +285,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()