Skip to content

Commit

Permalink
more lint
Browse files Browse the repository at this point in the history
  • Loading branch information
crespocarlos committed Apr 24, 2024
1 parent f41413f commit 472e183
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 46 deletions.
1 change: 0 additions & 1 deletion metricbeat/module/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
62 changes: 17 additions & 45 deletions metricbeat/module/elasticsearch/elasticsearch_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"math/rand"
"net/http"
"strings"
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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)
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 472e183

Please sign in to comment.