Skip to content

Commit

Permalink
Remove field
Browse files Browse the repository at this point in the history
  • Loading branch information
crespocarlos committed Apr 24, 2024
1 parent 8f8f313 commit 1beefae
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 57 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
12 changes: 2 additions & 10 deletions metricbeat/module/elasticsearch/elasticsearch_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,11 @@ func TestGetAllIndices(t *testing.T) {
name, ok := event.MetricSetFields["name"]
require.True(t, ok)

hidden, ok := event.MetricSetFields["hidden"]
require.True(t, ok)

isHidden, ok := hidden.(bool)
require.True(t, ok)

switch name {
case indexVisible:
idxVisibleExists = true
require.False(t, isHidden)
case indexHidden:
idxHiddenExists = true
require.True(t, isHidden)
}
}

Expand Down Expand Up @@ -204,14 +196,14 @@ func createIndex(host string, isHidden bool) (string, error) {

req, err := http.NewRequest("PUT", fmt.Sprintf("http://%v/%v", host, indexName), strings.NewReader(reqBody))
if err != nil {
return "", fmt.Errorf("could not build create index request: %w", err)
return "", errors.Wrap(err, "could not build create index request")
}
req.Header.Add("Content-Type", "application/json")

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return "", fmt.Errorf("could not send create index request: %w", err)
return "", errors.Wrap(err, "could not send create index request")
}
defer resp.Body.Close()
respBody, err := ioutil.ReadAll(resp.Body)
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)

Check failure on line 201 in metricbeat/module/elasticsearch/index/data.go

View workflow job for this annotation

GitHub Actions / lint (windows)

G601: Implicit memory aliasing in for loop. (gosec)

Check failure on line 201 in metricbeat/module/elasticsearch/index/data.go

View workflow job for this annotation

GitHub Actions / lint (linux)

G601: Implicit memory aliasing in for loop. (gosec)
if err != nil {
errs = append(errs, fmt.Errorf("failure adding cluster state fields: %w", err))
Expand Down

0 comments on commit 1beefae

Please sign in to comment.