-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Fix issue 6342: Automatically lowercase the index name #6640
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package elasticsearch | ||
|
||
import ( | ||
"unicode" | ||
"github.com/elastic/beats/libbeat/logp" | ||
"strings" | ||
) | ||
|
||
func TryLowercaseIndex(index string) string { | ||
for _, u := range []rune(index) { | ||
if unicode.IsUpper(u) { | ||
newIndex := strings.ToLower(index) | ||
logp.Warn("Index name %s is invalid, replace it with %s", index, newIndex) | ||
return newIndex | ||
} | ||
} | ||
return index | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a few things that bug me in this:
I wonder if instead, we could provide a better errors message when this situation happen and either tell them to use a lowercase index or we could provide a lowercase processor. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we provide a better errors message and an additional flag like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personnaly I would not add a custom flag, they are easy to add, hard to remove and it make the CLI more complicated. But the error message could mention how to fix the situation. "Use the lowercase processor to normalize your index" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First of all I don't like magic. Sending a field with upper case and then converting it to lower case automatically for the index naming feels like magic to me. I see multiple options moving forward:
I'm leaning towards the output config for the reason that this is an Elasticsearch specific issue so it should be an Elasticsearch config option. Having a config option off by default will also make it clear that when turning it on, it will have some processing overhead. For the flag: As we have -E everything should be a config option and not a flag if possible (there are exceptions). +1 on providing better error messages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Correct. Glad we got a conclusion. I would be +1 to add a specific options to the elasticsearch output to lowercase the index name and make it off by default. If you move forward with the changes can you sign the CLA? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ph Yeah, I'd like to, and I have signed the CLA. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package elasticsearch | ||
|
||
import ( | ||
"testing" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTryLowercaseIndex(t *testing.T) { | ||
testCases := map[string]string{ | ||
"ElasticSearch": "elasticsearch", | ||
"ELASTIC": "elastic", | ||
"beats": "beats", | ||
} | ||
|
||
for former, latter := range testCases { | ||
assert.Equal(t, latter, TryLowercaseIndex(former)) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function TryLowercaseIndex should have comment or be unexported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't need to export it :)