Skip to content

Commit 8409a5f

Browse files
simittgraphaelli
authored andcommitted
[ACM] Only allow cache expiration values in full seconds. (#2443) (#2451)
* [ACM] Only allow cache expiration values in full seconds. fixes #2438
1 parent 5592e12 commit 8409a5f

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

beater/config.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,19 @@ import (
2727

2828
"github.com/pkg/errors"
2929

30-
"github.com/elastic/apm-server/sourcemap"
3130
"github.com/elastic/beats/libbeat/common"
3231
"github.com/elastic/beats/libbeat/common/transport/tlscommon"
3332
"github.com/elastic/beats/libbeat/paths"
33+
34+
"github.com/elastic/apm-server/sourcemap"
3435
)
3536

3637
const (
3738
// DefaultPort of APM Server
3839
DefaultPort = "8200"
3940

40-
defaultAPMPipeline = "apm"
41+
defaultAPMPipeline = "apm"
42+
errMsgInvalidACMCfg = "invalid value for `apm-server.agent.config.cache.expiration`, only accepting full seconds"
4143
)
4244

4345
type Config struct {
@@ -157,6 +159,9 @@ func newConfig(version string, ucfg *common.Config) (*Config, error) {
157159
return nil, errors.Wrap(err, "Error processing configuration")
158160
}
159161

162+
if float64(int(c.AgentConfig.Cache.Expiration.Seconds())) != c.AgentConfig.Cache.Expiration.Seconds() {
163+
return nil, errors.New(errMsgInvalidACMCfg)
164+
}
160165
if c.RumConfig.isEnabled() {
161166
if _, err := regexp.Compile(c.RumConfig.LibraryPattern); err != nil {
162167
return nil, errors.New(fmt.Sprintf("Invalid regex for `library_pattern`: %v", err.Error()))

beater/config_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,3 +369,26 @@ func TestTLSSettings(t *testing.T) {
369369
}
370370
})
371371
}
372+
373+
func TestAgentConfig(t *testing.T) {
374+
t.Run("InvalidValueTooSmall", func(t *testing.T) {
375+
cfg, err := newConfig("9.9.9",
376+
common.MustNewConfigFrom(map[string]string{"agent.config.cache.expiration": "123ms"}))
377+
require.Error(t, err)
378+
assert.Nil(t, cfg)
379+
})
380+
381+
t.Run("InvalidUnit", func(t *testing.T) {
382+
cfg, err := newConfig("9.9.9",
383+
common.MustNewConfigFrom(map[string]string{"agent.config.cache.expiration": "1230ms"}))
384+
require.Error(t, err)
385+
assert.Nil(t, cfg)
386+
})
387+
388+
t.Run("Valid", func(t *testing.T) {
389+
cfg, err := newConfig("9.9.9",
390+
common.MustNewConfigFrom(map[string]string{"agent.config.cache.expiration": "123000ms"}))
391+
require.NoError(t, err)
392+
assert.Equal(t, time.Second*123, cfg.AgentConfig.Cache.Expiration)
393+
})
394+
}

changelogs/7.3.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ https://github.com/elastic/apm-server/compare/v7.2.1\...v7.3.0[View commits]
2020
[float]
2121
==== Added
2222
- Support adding transaction and span information to metrics {pull}2265[2265],{pull}2287[2287].
23-
- Initial support for remote agent configuration, requires Kibana {pull}2289[2289],{pull}2301[2301],{pull}2386[2386],{pull}2407[2407],{pull}2421[2421].
23+
- Initial support for remote agent configuration, requires Kibana {pull}2289[2289],{pull}2301[2301],{pull}2386[2386],{pull}2407[2407],{pull}2421[2421],{pull}2443[2443].
2424
- Add basic caching to remote agent configuration {pull}2337[2337].
2525
- Enable APM pipeline by default {pull}2301[2301].
2626
- Add fields required by breakdown graphs APM pipeline by default {pull}2315[2315],{pull}2397[2397].

tests/system/test_integration_acm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AgentConfigurationIntegrationTest(ElasticTest):
1313
config_overrides = {
1414
"logging_json": "true",
1515
"kibana_enabled": "true",
16-
"acm_cache_expiration": "1ms", # no cache
16+
"acm_cache_expiration": "1s",
1717
}
1818

1919
def create_service_config(self, settings, name, env=None, _id="new"):
@@ -160,7 +160,7 @@ def test_config_requests(self):
160160
assert updated_config_with_env_rsp.status_code == 200, updated_config_with_env_rsp.status_code
161161
# TODO (gr): remove when cache can be disabled via config
162162
# wait for cache to purge
163-
time.sleep(.10) # sleep much more than acm_cache_expiration to reduce flakiness
163+
time.sleep(1.1) # sleep much more than acm_cache_expiration to reduce flakiness
164164

165165
# TODO (gr): include If-None-Match header - https://github.com/elastic/apm-server/issues/2434
166166
r5_post_update = requests.get(self.agent_config_url,

0 commit comments

Comments
 (0)