Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge ES default values to Sourcmeap configuration. #3355

Merged
merged 4 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions beater/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ func Test_UnpackConfig(t *testing.T) {
"cache": map[string]interface{}{
"expiration": 8 * time.Minute,
},
"index_pattern": "apm-test*",
"index_pattern": "apm-test*",
"elasticsearch.hosts": []string{"localhost:9201", "localhost:9202"},
},
"library_pattern": "^custom",
"exclude_from_grouping": "^grouping",
Expand Down Expand Up @@ -143,6 +144,11 @@ func Test_UnpackConfig(t *testing.T) {
SourceMapping: &SourceMapping{
Cache: &Cache{Expiration: 8 * time.Minute},
IndexPattern: "apm-test*",
ESConfig: &elasticsearch.Config{
Hosts: elasticsearch.Hosts{"localhost:9201", "localhost:9202"},
Protocol: "http",
Timeout: 5 * time.Second},
esConfigured: true,
},
LibraryPattern: "^custom",
ExcludeFromGrouping: "^grouping",
Expand Down Expand Up @@ -256,6 +262,7 @@ func Test_UnpackConfig(t *testing.T) {
Expiration: 7 * time.Second,
},
IndexPattern: "apm-*-sourcemap*",
ESConfig: elasticsearch.DefaultConfig(),
},
LibraryPattern: "rum",
ExcludeFromGrouping: "^/webpack",
Expand Down Expand Up @@ -478,7 +485,7 @@ func TestNewConfig_ESConfig(t *testing.T) {
// no es config given
cfg, err := NewConfig(version, ucfg, nil)
require.NoError(t, err)
assert.Nil(t, cfg.RumConfig.SourceMapping.ESConfig)
assert.Equal(t, elasticsearch.DefaultConfig(), cfg.RumConfig.SourceMapping.ESConfig)
assert.Equal(t, elasticsearch.DefaultConfig(), cfg.APIKeyConfig.ESConfig)

// with es config
Expand Down
41 changes: 29 additions & 12 deletions beater/config/rum.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ type SourceMapping struct {
Enabled *bool `config:"enabled"`
IndexPattern string `config:"index_pattern"`
ESConfig *elasticsearch.Config `config:"elasticsearch"`

store *sourcemap.Store
esConfigured bool
}

// IsEnabled indicates whether RUM endpoint is enabled or not
Expand Down Expand Up @@ -114,7 +116,7 @@ func (c *RumConfig) setup(log *logp.Logger, outputESCfg *common.Config) error {
return errors.Wrapf(err, "Invalid regex for `exclude_from_grouping`: ")
}

if c.SourceMapping == nil || c.SourceMapping.ESConfig != nil {
if c.SourceMapping == nil || c.SourceMapping.esConfigured {
return nil
}

Expand All @@ -124,11 +126,9 @@ func (c *RumConfig) setup(log *logp.Logger, outputESCfg *common.Config) error {
return nil
}
log.Info("Falling back to elasticsearch output for sourcemap storage")
esCfg := elasticsearch.DefaultConfig()
if err := outputESCfg.Unpack(esCfg); err != nil {
if err := outputESCfg.Unpack(c.SourceMapping.ESConfig); err != nil {
return errors.Wrap(err, "unpacking Elasticsearch config into Sourcemap config")
}
c.SourceMapping.ESConfig = esCfg
return nil
}

Expand All @@ -140,20 +140,37 @@ func replaceVersion(pattern, version string) string {
return regexObserverVersion.ReplaceAllLiteralString(pattern, version)
}

func (s *SourceMapping) Unpack(inp *common.Config) error {
cfg := tmpSourceMapping(*defaultSourcemapping())
if err := inp.Unpack(&cfg); err != nil {
return errors.Errorf("error unpacking sourcemapping config: %w", err)
}
*s = SourceMapping(cfg)
if inp.HasField("elasticsearch") {
s.esConfigured = true
}
return nil
}

type tmpSourceMapping SourceMapping
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps move this inside the Unpack method, and comment it to make it clear that it exists just to remove the custom "Unpack" method?


func defaultSourcemapping() *SourceMapping {
return &SourceMapping{
Cache: &Cache{Expiration: defaultSourcemapCacheExpiration},
IndexPattern: defaultSourcemapIndexPattern,
ESConfig: elasticsearch.DefaultConfig(),
}
}

func defaultRum(beatVersion string) *RumConfig {
return &RumConfig{
EventRate: &EventRate{
Limit: defaultEventRateLimit,
LruSize: defaultEventRateLRUSize,
},
AllowOrigins: []string{allowAllOrigins},
AllowHeaders: []string{},
SourceMapping: &SourceMapping{
Cache: &Cache{
Expiration: defaultSourcemapCacheExpiration,
},
IndexPattern: defaultSourcemapIndexPattern,
},
AllowOrigins: []string{allowAllOrigins},
AllowHeaders: []string{},
SourceMapping: defaultSourcemapping(),
LibraryPattern: defaultLibraryPattern,
ExcludeFromGrouping: defaultExcludeFromGrouping,
BeatVersion: beatVersion,
Expand Down
1 change: 1 addition & 0 deletions changelogs/head.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ https://github.com/elastic/apm-server/compare/7.6\...master[View commits]
[float]
==== Bugfixes
* Merge default values with custom Elasticsearch config for API Keys and add `required` tag for `host` {pull}3342[3342]
* Merge default values with custom Sourcemap Elasticsearch config {pull}3355[3355]

[float]
==== Intake API Changes
Expand Down