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

Elasticsearch: Handle no-index case in backend mode #68534

Merged
merged 2 commits into from May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/tsdb/elasticsearch/client/client_test.go
Expand Up @@ -118,6 +118,12 @@ func TestClient_Index(t *testing.T) {
patternInDatasource string
indexInRequest []string
}{
{
name: "empty string",
indexInDatasource: "",
patternInDatasource: "",
indexInRequest: []string{},
},
{
name: "single string",
indexInDatasource: "logs-*",
Expand Down
7 changes: 6 additions & 1 deletion pkg/tsdb/elasticsearch/client/index_pattern.go
Expand Up @@ -35,7 +35,12 @@ type staticIndexPattern struct {
}

func (ip *staticIndexPattern) GetIndices(timeRange backend.TimeRange) ([]string, error) {
return []string{ip.indexName}, nil
name := ip.indexName
if name != "" {
return []string{name}, nil
} else {
return []string{}, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

this is super nit pick, but I don't think name := ip.indexName improves readability and it adds assigning of new variable. So I would suggest to just do

	if ip.indexName != "" {
		return []string{ip.indexName}, nil
	} else {
		return []string{}, nil
	}

Copy link
Contributor

@matyax matyax May 17, 2023

Choose a reason for hiding this comment

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

I'm curious to know if, with Go, you could do both things at the same time with:

   return []string{ip.indexName}, nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@matyax unfortunately no, in case of indexName being "" (empty-string), that would return a single-item array where the item is empty-string

Copy link
Contributor

Choose a reason for hiding this comment

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

Right! I still have a hard time understanding this array format. Thanks for the explanation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ivanahuckova agreed, changed 👍

}

type intervalGenerator interface {
Expand Down