Skip to content

Commit

Permalink
Remove field
Browse files Browse the repository at this point in the history
  • Loading branch information
crespocarlos committed Apr 23, 2024
1 parent 8f8f313 commit 158da0a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 51 deletions.
37 changes: 0 additions & 37 deletions metricbeat/module/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,43 +386,6 @@ func (b *boolStr) UnmarshalJSON(raw []byte) error {
return nil
}

type IndexSettings struct {
Hidden bool
}

// GetIndicesSettings returns a map of index names to their settings.
// Note that as of now it is optimized to fetch only the "hidden" index setting to keep the memory
// footprint of this function call as low as possible.
func GetIndicesSettings(http *helper.HTTP, resetURI string) (map[string]IndexSettings, error) {
content, err := fetchPath(http, resetURI, "*/_settings", "filter_path=*.settings.index.hidden&expand_wildcards=all")

if err != nil {
return nil, fmt.Errorf("could not fetch indices settings: %w", err)
}

var resp map[string]struct {
Settings struct {
Index struct {
Hidden boolStr `json:"hidden"`
} `json:"index"`
} `json:"settings"`
}

err = json.Unmarshal(content, &resp)
if err != nil {
return nil, fmt.Errorf("could not parse indices settings response: %w", err)
}

ret := make(map[string]IndexSettings, len(resp))
for index, settings := range resp {
ret[index] = IndexSettings{
Hidden: bool(settings.Settings.Index.Hidden),
}
}

return ret, nil
}

// 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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"io/ioutil"
"math/rand"
"net/http"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -197,12 +196,12 @@ func setupTest(t *testing.T, esHost string, esVersion *version.V) {
}

// createIndex creates an random elasticsearch index
func createIndex(host string, isHidden bool) (string, error) {
func createIndex(host string) (string, error) {
indexName := randString(5)

reqBody := fmt.Sprintf(`{ "settings": { "index.hidden": %v } }`, isHidden)

Check failure on line 202 in metricbeat/module/elasticsearch/elasticsearch_integration_test.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

reqBody declared and not used (typecheck)

req, err := http.NewRequest("PUT", fmt.Sprintf("http://%v/%v", host, indexName), strings.NewReader(reqBody))
req, err := http.NewRequest("PUT", fmt.Sprintf("http://%v/%v", host, indexName), nil)
if err != nil {
return "", fmt.Errorf("could not build create index request: %w", err)
}
Expand All @@ -217,7 +216,7 @@ func createIndex(host string, isHidden bool) (string, error) {
respBody, err := ioutil.ReadAll(resp.Body)

Check failure on line 216 in metricbeat/module/elasticsearch/elasticsearch_integration_test.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

respBody declared and not used (typecheck)

if resp.StatusCode != 200 {
return "", fmt.Errorf("HTTP error %d: %s, %s", resp.StatusCode, resp.Status, string(respBody))
return "", fmt.Errorf("HTTP error %d: %s, %s", resp.StatusCode, resp.Status)
}

return indexName, nil
Expand Down
10 changes: 0 additions & 10 deletions metricbeat/module/elasticsearch/index/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,13 @@ func eventsMapping(r mb.ReporterV2, httpClient *helper.HTTP, info elasticsearch.
return fmt.Errorf("failure parsing Indices Stats Elasticsearch API response: %w", err)
}

indicesSettings, err := elasticsearch.GetIndicesSettings(httpClient, httpClient.GetURI())
if err != nil {
return fmt.Errorf("failure retrieving indices settings from Elasticsearch: %w", err)
}

var errs multierror.Errors
for name, idx := range indicesStats.Indices {
event := mb.Event{
ModuleFields: mapstr.M{},
}
idx.Index = name

settings, exists := indicesSettings[name]
if exists {
idx.Hidden = settings.Hidden
}

err = addClusterStateFields(&idx, clusterState)
if err != nil {
errs = append(errs, fmt.Errorf("failure adding cluster state fields: %w", err))
Expand Down

0 comments on commit 158da0a

Please sign in to comment.