Skip to content

Commit

Permalink
fix: ensure ES index names are lowercase (elastic#4295)
Browse files Browse the repository at this point in the history
Ensure customized index names are always lowercase,
fixing regression introduced with https://github.com/elastic/beats/pull/18854/files

fixes elastic#4294
  • Loading branch information
simitt committed Oct 12, 2020
1 parent becac3b commit f1a15b6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
11 changes: 11 additions & 0 deletions changelogs/7.9.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@

https://github.com/elastic/apm-server/compare/7.8\...7.9[View commits]

* <<release-notes-7.9.3>>
* <<release-notes-7.9.2>>
* <<release-notes-7.9.1>>
* <<release-notes-7.9.0>>

[float]
[[release-notes-7.9.3]]
=== APM Server version 7.9.3

https://github.com/elastic/apm-server/compare/v7.9.2\...v7.9.3[View commits]

[float]
==== Bug fixes
* Ensure custom index names are lowercased {pull}4295[4295]

[float]
[[release-notes-7.9.2]]
=== APM Server version 7.9.2
Expand Down
6 changes: 4 additions & 2 deletions idxmgmt/supporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package idxmgmt

import (
"fmt"
"strings"

"github.com/pkg/errors"
"go.uber.org/atomic"
Expand Down Expand Up @@ -176,6 +177,7 @@ func (s *supporter) buildSelector(cfg *common.Config, err error) (outil.Selector
MultiKey: "indices",
EnableSingleOnly: true,
FailEmpty: true,
Case: outil.SelectorLowerCase,
}
return outil.BuildSelectorFromConfig(cfg, buildSettings)
}
Expand Down Expand Up @@ -236,7 +238,7 @@ func getEventCustomIndex(evt *beat.Event) string {
// returns index from alias
if tmp := evt.Meta["alias"]; tmp != nil {
if alias, ok := tmp.(string); ok {
return alias
return strings.ToLower(alias)
}
}

Expand All @@ -245,7 +247,7 @@ func getEventCustomIndex(evt *beat.Event) string {
if idx, ok := tmp.(string); ok {
ts := evt.Timestamp.UTC()
return fmt.Sprintf("%s-%d.%02d.%02d",
idx, ts.Year(), ts.Month(), ts.Day())
strings.ToLower(idx), ts.Year(), ts.Month(), ts.Day())
}
}

Expand Down
10 changes: 5 additions & 5 deletions idxmgmt/supporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,26 +148,26 @@ func TestIndexSupport_BuildSelector(t *testing.T) {
withIlm: "apm-7.0.0-sourcemap",
fields: common.MapStr{"processor.event": "sourcemap"},
},
"MetaInformationAlias": {
"MetaInformationAlia-lowercased": {
noIlm: "apm-7.0.0-meta",
withIlm: "apm-7.0.0-meta", //meta overwrites ilm
fields: common.MapStr{"processor.event": "span"},
meta: common.MapStr{"alias": "apm-7.0.0-meta", "index": "test-123"},
meta: common.MapStr{"alias": "APM-7.0.0-meta", "index": "test-123"},
cfg: common.MapStr{"output.elasticsearch.index": "apm-customized"},
},
"MetaInformationIndex": {
noIlm: fmt.Sprintf("apm-7.0.0-%s", day),
withIlm: fmt.Sprintf("apm-7.0.0-%s", day), //meta overwrites ilm
fields: common.MapStr{"processor.event": "span"},
meta: common.MapStr{"index": "apm-7.0.0"},
meta: common.MapStr{"index": "APM-7.0.0"},
cfg: common.MapStr{"output.elasticsearch.index": "apm-customized"},
},
"CustomIndex": {
"CustomIndex-lowercased": {
noIlm: "apm-customized",
withIlm: "apm-7.0.0-metric", //custom index ignored when ilm enabled
ilmAuto: "apm-customized", //custom respected for ilm auto
fields: common.MapStr{"processor.event": "metric"},
cfg: common.MapStr{"output.elasticsearch.index": "apm-customized"},
cfg: common.MapStr{"output.elasticsearch.index": "APM-customized"},
},
"DifferentCustomIndices": {
noIlm: fmt.Sprintf("apm-7.0.0-%s", day),
Expand Down

0 comments on commit f1a15b6

Please sign in to comment.