-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Source resolver should resolve sources by investigating configured in…
…dexes and not actual tables found in Clickhouse (#183) Solves the issue of getting `Panic recovered: elasticsearch-only indexes should not be routed here at all` which should never be the case. This could occur when: - index existed in Elasticsearch - index was configured in Quesma - matching table was absent in Clickhouse Additionally: - moved `IndexMatches` method to `elasticsearch` package - created tests for `ResolveSources()`
- Loading branch information
Showing
7 changed files
with
163 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package quesma | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"mitmproxy/quesma/elasticsearch" | ||
"mitmproxy/quesma/quesma/config" | ||
"testing" | ||
) | ||
|
||
func TestResolveSources(t *testing.T) { | ||
type args struct { | ||
indexPattern string | ||
cfg config.QuesmaConfiguration | ||
im elasticsearch.IndexManagement | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{ | ||
name: "Index only in Clickhouse,pattern:", | ||
args: args{ | ||
indexPattern: "test", | ||
cfg: config.QuesmaConfiguration{IndexConfig: map[string]config.IndexConfiguration{"test": {Enabled: true}}}, | ||
im: NewFixedIndexManagement(), | ||
}, | ||
want: sourceClickhouse, | ||
}, | ||
{ | ||
name: "Index only in Clickhouse,pattern:", | ||
args: args{ | ||
indexPattern: "*", | ||
cfg: config.QuesmaConfiguration{IndexConfig: map[string]config.IndexConfiguration{"test": {Enabled: true}}}, | ||
im: NewFixedIndexManagement(), | ||
}, | ||
want: sourceClickhouse, | ||
}, | ||
{ | ||
name: "Index only in Elasticsearch,pattern:", | ||
args: args{ | ||
indexPattern: "test", | ||
cfg: config.QuesmaConfiguration{IndexConfig: map[string]config.IndexConfiguration{}}, | ||
im: NewFixedIndexManagement("test"), | ||
}, | ||
want: sourceElasticsearch, | ||
}, | ||
{ | ||
name: "Index only in Elasticsearch,pattern:", | ||
args: args{ | ||
indexPattern: "*", | ||
cfg: config.QuesmaConfiguration{IndexConfig: map[string]config.IndexConfiguration{}}, | ||
im: NewFixedIndexManagement("test"), | ||
}, | ||
want: sourceElasticsearch, | ||
}, | ||
{ | ||
name: "Indexes both in Elasticsearch and Clickhouse", | ||
args: args{ | ||
indexPattern: "*", | ||
cfg: config.QuesmaConfiguration{IndexConfig: map[string]config.IndexConfiguration{"kibana-sample-data-logs": {Enabled: true}}}, | ||
im: NewFixedIndexManagement("logs-generic-default"), | ||
}, | ||
want: sourceBoth, | ||
}, | ||
{ | ||
name: "Indexes both in Elasticsearch and Clickhouse, but explicitly disabled", | ||
args: args{ | ||
indexPattern: "*", | ||
cfg: config.QuesmaConfiguration{IndexConfig: map[string]config.IndexConfiguration{"logs-generic-default": {Enabled: false}}}, | ||
im: NewFixedIndexManagement("logs-generic-default"), | ||
}, | ||
want: sourceElasticsearch, | ||
}, | ||
{ | ||
name: "Index neither in Clickhouse nor in Elasticsearch", | ||
args: args{ | ||
indexPattern: "*", | ||
cfg: config.QuesmaConfiguration{IndexConfig: map[string]config.IndexConfiguration{}}, | ||
im: NewFixedIndexManagement(), | ||
}, | ||
want: sourceNone, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name+tt.args.indexPattern, func(t *testing.T) { | ||
got, _, _ := ResolveSources(tt.args.indexPattern, tt.args.cfg, tt.args.im) | ||
assert.Equalf(t, tt.want, got, "ResolveSources(%v, %v, %v)", tt.args.indexPattern, tt.args.cfg, tt.args.im) | ||
}) | ||
} | ||
} | ||
|
||
func NewFixedIndexManagement(indexes ...string) elasticsearch.IndexManagement { | ||
return stubIndexManagement{indexes: indexes} | ||
} | ||
|
||
type stubIndexManagement struct { | ||
indexes []string | ||
} | ||
|
||
func (s stubIndexManagement) Start() {} | ||
func (s stubIndexManagement) Stop() {} | ||
func (s stubIndexManagement) ReloadIndices() {} | ||
func (s stubIndexManagement) GetSources() elasticsearch.Sources { | ||
var dataStreams = []elasticsearch.DataStream{} | ||
for _, index := range s.indexes { | ||
dataStreams = append(dataStreams, elasticsearch.DataStream{Name: index}) | ||
} | ||
return elasticsearch.Sources{DataStreams: dataStreams} | ||
} | ||
|
||
func (s stubIndexManagement) GetSourceNames() map[string]bool { | ||
var result = make(map[string]bool) | ||
for _, index := range s.indexes { | ||
result[index] = true | ||
} | ||
return result | ||
} | ||
|
||
func (s stubIndexManagement) GetSourceNamesMatching(indexPattern string) map[string]bool { | ||
var result = make(map[string]bool) | ||
for _, index := range s.indexes { | ||
if elasticsearch.IndexMatches(indexPattern, index) { | ||
result[index] = true | ||
} | ||
} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters