forked from prometheus-community/elasticsearch_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindices_settings_test.go
More file actions
106 lines (99 loc) · 3.92 KB
/
Copy pathindices_settings_test.go
File metadata and controls
106 lines (99 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2021 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package collector
import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"github.com/go-kit/log"
)
func TestIndicesSettings(t *testing.T) {
// Testcases created using:
// docker run -d -p 9200:9200 elasticsearch:VERSION
// curl -XPUT http://localhost:9200/twitter
// curl -XPUT http://localhost:9200/facebook
// curl -XPUT http://localhost:9200/instagram
// curl -XPUT http://localhost:9200/viber
// curl -XPUT http://localhost:9200/instagram/_settings --header "Content-Type: application/json" -d '
// {
// "index": {
// "mapping": {
// "total_fields": {
// "limit": 10000
// }
// },
// "blocks": {
// "read_only_allow_delete": "true"
// }
// }
// }'
// curl -XPUT http://localhost:9200/twitter/_settings --header "Content-Type: application/json" -d '
// {
// "index": {
// "blocks": {
// "read_only_allow_delete": "true"
// }
// }
// }'
// curl http://localhost:9200/_all/_settings
tcs := map[string]string{
"6.5.4": `{"viber":{"settings":{"index":{"creation_date":"1618593207186","number_of_shards":"5","number_of_replicas":"1","uuid":"lWg86KTARzO3r7lELytT1Q","version":{"created":"6050499"},"provided_name":"viber"}}},"instagram":{"settings":{"index":{"mapping":{"total_fields":{"limit":"10000"}},"number_of_shards":"5","blocks":{"read_only_allow_delete":"true"},"provided_name":"instagram","creation_date":"1618593203353","number_of_replicas":"1","uuid":"msb6eG7aT8GmNe-a4oyVtQ","version":{"created":"6050499"}}}},"twitter":{"settings":{"index":{"number_of_shards":"5","blocks":{"read_only_allow_delete":"true"},"provided_name":"twitter","creation_date":"1618593193641","number_of_replicas":"1","uuid":"YRUT8t4aSkKsNmGl7K3y4Q","version":{"created":"6050499"}}}},"facebook":{"settings":{"index":{"creation_date":"1618593199101","number_of_shards":"5","number_of_replicas":"1","uuid":"trZhb_YOTV-RWKitTYw81A","version":{"created":"6050499"},"provided_name":"facebook"}}}}`,
}
for ver, out := range tcs {
for hn, handler := range map[string]http.Handler{
"plain": http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, out)
}),
} {
ts := httptest.NewServer(handler)
defer ts.Close()
u, err := url.Parse(ts.URL)
if err != nil {
t.Fatalf("Failed to parse URL: %s", err)
}
c := NewIndicesSettings(log.NewNopLogger(), http.DefaultClient, u, "_all")
nsr, err := c.fetchAndDecodeIndicesSettings()
if err != nil {
t.Fatalf("Failed to fetch or decode indices settings: %s", err)
}
t.Logf("[%s/%s] All Indices Settings Response: %+v", hn, ver, nsr)
// if nsr.Cluster.Routing.Allocation.Enabled != "ALL" {
// t.Errorf("Wrong setting for cluster routing allocation enabled")
// }
var counter int
var totalFields int
for key, value := range nsr {
if value.Settings.IndexInfo.Blocks.ReadOnly == "true" {
counter++
if key != "instagram" && key != "twitter" {
t.Errorf("Wrong read_only index")
}
}
if value.Settings.IndexInfo.Mapping.TotalFields.Limit == "10000" {
totalFields++
if key != "instagram" {
t.Errorf("Expected 10000 total_fields only for instagram")
}
}
}
if counter != 2 {
t.Errorf("Wrong number of read_only indexes")
}
if totalFields != 1 {
t.Errorf(("Wrong number of total_fields found"))
}
}
}
}