Skip to content

Commit

Permalink
[Metricbeat] Remove elasticsearc.index.created from the SM code (#25113
Browse files Browse the repository at this point in the history
…) (#25172)

(cherry picked from commit a951d19)
  • Loading branch information
sayden committed Apr 20, 2021
1 parent f0e0490 commit 22853a1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Expand Up @@ -76,6 +76,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Add support for Consul 1.9. {pull}24123[24123]
- Add support for the MemoryPressure, DiskPressure, OutOfDisk and PIDPressure status conditions in state_node. {pull}23905[23905]
- Store `cloudfoundry.container.cpu.pct` in decimal form and as `scaled_float`. {pull}24219[24219]
- Remove `index_stats.created` field from Elasticsearch/index Metricset {pull}25113[25113]

*Packetbeat*

Expand Down
37 changes: 5 additions & 32 deletions metricbeat/module/elasticsearch/index/data_xpack.go
Expand Up @@ -20,7 +20,6 @@ package index
import (
"encoding/json"
"fmt"
"strconv"
"time"

"github.com/joeshaw/multierror"
Expand All @@ -46,11 +45,10 @@ type Index struct {
Primaries indexStats `json:"primaries"`
Total indexStats `json:"total"`

Index string `json:"index"`
Created int64 `json:"created"`
Status string `json:"status"`
Hidden bool `json:"hidden"`
Shards shardStats `json:"shards"`
Index string `json:"index"`
Status string `json:"status"`
Hidden bool `json:"hidden"`
Shards shardStats `json:"shards"`
}

type indexStats struct {
Expand Down Expand Up @@ -131,7 +129,7 @@ type bulkStats struct {
}

func eventsMappingXPack(r mb.ReporterV2, m *MetricSet, info elasticsearch.Info, content []byte) error {
clusterStateMetrics := []string{"metadata", "routing_table"}
clusterStateMetrics := []string{"routing_table"}
clusterState, err := elasticsearch.GetClusterState(m.HTTP, m.HTTP.GetURI(), clusterStateMetrics)
if err != nil {
return errors.Wrap(err, "failure retrieving cluster state from Elasticsearch")
Expand Down Expand Up @@ -185,11 +183,6 @@ func parseAPIResponse(content []byte, indicesStats *stats) error {
// Fields added here are based on same fields being added by internal collection in
// https://github.com/elastic/elasticsearch/blob/master/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexStatsMonitoringDoc.java#L62-L124
func addClusterStateFields(idx *Index, clusterState common.MapStr) error {
indexMetadata, err := getClusterStateMetricForIndex(clusterState, idx.Index, "metadata")
if err != nil {
return errors.Wrap(err, "failed to get index metadata from cluster state")
}

indexRoutingTable, err := getClusterStateMetricForIndex(clusterState, idx.Index, "routing_table")
if err != nil {
return errors.Wrap(err, "failed to get index routing table from cluster state")
Expand All @@ -200,12 +193,6 @@ func addClusterStateFields(idx *Index, clusterState common.MapStr) error {
return errors.Wrap(err, "failed to get shards from routing table")
}

created, err := getIndexCreated(indexMetadata)
if err != nil {
return errors.Wrap(err, "failed to get index creation time")
}
idx.Created = created

// "index_stats.version.created", <--- don't think this is being used in the UI, so can we skip it?
// "index_stats.version.upgraded", <--- don't think this is being used in the UI, so can we skip it?

Expand Down Expand Up @@ -354,20 +341,6 @@ func getIndexShardStats(shards common.MapStr) (*shardStats, error) {
}, nil
}

func getIndexCreated(indexMetadata common.MapStr) (int64, error) {
v, err := indexMetadata.GetValue("settings.index.creation_date")
if err != nil {
return 0, err
}

c, ok := v.(string)
if !ok {
return 0, elastic.MakeErrorForMissingField("settings.index.creation_date", elastic.Elasticsearch)
}

return strconv.ParseInt(c, 10, 64)
}

func getShardsFromRoutingTable(indexRoutingTable common.MapStr) (map[string]interface{}, error) {
s, err := indexRoutingTable.GetValue("shards")
if err != nil {
Expand Down

0 comments on commit 22853a1

Please sign in to comment.