diff --git a/metricbeat/module/elasticsearch/elasticsearch.go b/metricbeat/module/elasticsearch/elasticsearch.go index 60e95c4c0d8c..b77691cad269 100644 --- a/metricbeat/module/elasticsearch/elasticsearch.go +++ b/metricbeat/module/elasticsearch/elasticsearch.go @@ -367,7 +367,6 @@ func GetXPack(http *helper.HTTP, resetURI string) (XPack, error) { return xpack, err } - // IsMLockAllEnabled returns if the given Elasticsearch node has mlockall enabled func IsMLockAllEnabled(http *helper.HTTP, resetURI, nodeID string) (bool, error) { content, err := fetchPath(http, resetURI, "_nodes/"+nodeID, "filter_path=nodes.*.process.mlockall") diff --git a/metricbeat/module/elasticsearch/elasticsearch_integration_test.go b/metricbeat/module/elasticsearch/elasticsearch_integration_test.go index 7f470d79c739..88fb77afe8e3 100644 --- a/metricbeat/module/elasticsearch/elasticsearch_integration_test.go +++ b/metricbeat/module/elasticsearch/elasticsearch_integration_test.go @@ -24,7 +24,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "math/rand" "net/http" "strings" @@ -206,7 +206,7 @@ func createIndex(host string, isHidden bool) (string, error) { return "", fmt.Errorf("could not send create index request: %w", err) } defer resp.Body.Close() - respBody, err := ioutil.ReadAll(resp.Body) + respBody, err := io.ReadAll(resp.Body) if resp.StatusCode != 200 { return "", fmt.Errorf("HTTP error %d: %s, %s", resp.StatusCode, resp.Status, string(respBody)) @@ -246,7 +246,7 @@ func enableTrialLicense(host string, version *version.V) error { defer resp.Body.Close() if resp.StatusCode != 200 { - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return err } @@ -271,7 +271,7 @@ func checkTrialLicenseEnabled(host string, version *version.V) (bool, error) { } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return false, err } @@ -294,7 +294,7 @@ func checkTrialLicenseEnabled(host string, version *version.V) (bool, error) { func createMLJob(host string, version *version.V) error { - mlJob, err := ioutil.ReadFile("ml_job/_meta/test/test_job.json") + mlJob, err := io.ReadFile("ml_job/_meta/test/test_job.json") if err != nil { return err } @@ -362,7 +362,7 @@ func checkCCRStatsExists(host string) (bool, error) { } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return false, err } @@ -381,7 +381,7 @@ func checkCCRStatsExists(host string) (bool, error) { } func setupCCRRemote(host string) error { - remoteSettings, err := ioutil.ReadFile("ccr/_meta/test/test_remote_settings.json") + remoteSettings, err := io.ReadFile("ccr/_meta/test/test_remote_settings.json") if err != nil { return err } @@ -392,7 +392,7 @@ func setupCCRRemote(host string) error { } func createCCRLeaderIndex(host string) error { - leaderIndex, err := ioutil.ReadFile("ccr/_meta/test/test_leader_index.json") + leaderIndex, err := io.ReadFile("ccr/_meta/test/test_leader_index.json") if err != nil { return err } @@ -403,7 +403,7 @@ func createCCRLeaderIndex(host string) error { } func createCCRFollowerIndex(host string) error { - followerIndex, err := ioutil.ReadFile("ccr/_meta/test/test_follower_index.json") + followerIndex, err := io.ReadFile("ccr/_meta/test/test_follower_index.json") if err != nil { return err } @@ -421,10 +421,7 @@ func checkExists(url string) bool { resp.Body.Close() // Entry exists - if resp.StatusCode == 200 { - return true - } - return false + return resp.StatusCode == 200 } func createEnrichStats(host string) error { @@ -457,7 +454,7 @@ func createEnrichStats(host string) error { } func createEnrichSourceIndex(host string) error { - sourceDoc, err := ioutil.ReadFile("enrich/_meta/test/source_doc.json") + sourceDoc, err := io.ReadFile("enrich/_meta/test/source_doc.json") if err != nil { return err } @@ -468,7 +465,7 @@ func createEnrichSourceIndex(host string) error { } func createEnrichPolicy(host string) error { - policy, err := ioutil.ReadFile("enrich/_meta/test/policy.json") + policy, err := io.ReadFile("enrich/_meta/test/policy.json") if err != nil { return err } @@ -485,7 +482,7 @@ func executeEnrichPolicy(host string) error { } func createEnrichIngestPipeline(host string) error { - pipeline, err := ioutil.ReadFile("enrich/_meta/test/ingest_pipeline.json") + pipeline, err := io.ReadFile("enrich/_meta/test/ingest_pipeline.json") if err != nil { return err } @@ -496,7 +493,7 @@ func createEnrichIngestPipeline(host string) error { } func ingestAndEnrichDoc(host string) error { - targetDoc, err := ioutil.ReadFile("enrich/_meta/test/target_doc.json") + targetDoc, err := io.ReadFile("enrich/_meta/test/target_doc.json") if err != nil { return err } @@ -510,31 +507,6 @@ func countIndices(elasticsearchHostPort string) (int, error) { return countCatItems(elasticsearchHostPort, "indices", "&expand_wildcards=open,hidden") } -func countShards(elasticsearchHostPort string) (int, error) { - return countCatItems(elasticsearchHostPort, "shards", "") -} - -func countCatItems(elasticsearchHostPort, catObject, extraParams string) (int, error) { - resp, err := http.Get("http://" + elasticsearchHostPort + "/_cat/" + catObject + "?format=json" + extraParams) - if err != nil { - return 0, err - } - defer resp.Body.Close() - - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - return 0, err - } - - var data []mapstr.M - err = json.Unmarshal(body, &data) - if err != nil { - return 0, err - } - - return len(data), nil -} - func checkSkip(t *testing.T, metricset string, ver *version.V) { checkSkipFeature := func(name string, availableVersion *version.V) { isAPIAvailable := elastic.IsFeatureAvailable(ver, availableVersion) @@ -558,7 +530,7 @@ func getElasticsearchVersion(elasticsearchHostPort string) (*version.V, error) { } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -599,7 +571,7 @@ func httpSendJSON(host, path, method string, body []byte) ([]byte, *http.Respons } defer resp.Body.Close() - body, err = ioutil.ReadAll(resp.Body) + body, err = io.ReadAll(resp.Body) if err != nil { return nil, nil, err } @@ -628,7 +600,7 @@ func waitForSuccess(f checkSuccessFunction, retryInterval time.Duration, numAtte } func randString(len int) string { - rand.Seed(time.Now().UnixNano()) + rand := rand.New(rand.NewSource(time.Now().UnixNano())) b := make([]byte, len) aIdx := int('a')