Skip to content

Commit

Permalink
Cherry-pick #8335 to 6.x: Adding elasticsearch/ccr metricset (#8357)
Browse files Browse the repository at this point in the history
* Adding elasticsearch/ccr metricset (#8335)

This PR adds the `elasticsearch/ccr` metricset which collects cross-cluster replication (CCR) stats from the `GET _ccr/stats` Elasticsearch API and indexes them in `metricbeat-*`.

(cherry picked from commit 0f2b29a)

* Cleaning up CHANGELOG
  • Loading branch information
ycombinator authored Sep 24, 2018
1 parent ca81155 commit 4f14d66
Show file tree
Hide file tree
Showing 20 changed files with 645 additions and 23 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ https://github.com/elastic/beats/compare/v6.4.0...6.x[Check the HEAD diff]
- Add support to renamed fields planned for redis 5.0. {pull}8167[8167]
- Allow TCP helper to support delimiters and graphite module to accept multiple metrics in a single payload. {pull}8278[8278]
- Added 'died' PID state to process_system metricset on system module {pull}8275[8275]


- Add `metrics` metricset to MongoDB module. {pull}7611[7611]
- Added `ccr` metricset to Elasticsearch module. {pull}8335[8335]

*Packetbeat*

Expand Down
79 changes: 79 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -3459,6 +3459,85 @@ type: keyword
Elasticsearch state id.
--
[float]
== ccr fields
Cross-cluster replication stats
*`elasticsearch.ccr.leader.index`*::
+
--
type: keyword
Name of leader index
--
*`elasticsearch.ccr.leader.max_seq_no`*::
+
--
type: long
Maximum sequence number of operation on the leader shard
--
*`elasticsearch.ccr.follower.index`*::
+
--
type: keyword
Name of follower index
--
*`elasticsearch.ccr.follower.shard.number`*::
+
--
type: long
Number of the shard within the index
--
*`elasticsearch.ccr.follower.operations_indexed`*::
+
--
type: long
Number of operations indexed (replicated) into the follower shard from the leader shard
--
*`elasticsearch.ccr.follower.time_since_last_fetch.ms`*::
+
--
type: long
Time, in ms, since the follower last fetched from the leader
--
*`elasticsearch.ccr.follower.global_checkpoint`*::
+
--
type: long
Global checkpoint value on follower shard
--
[float]
Expand Down
4 changes: 4 additions & 0 deletions metricbeat/docs/modules/elasticsearch.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ It also supports the options described in <<module-http-config-options>>.

The following metricsets are available:

* <<metricbeat-metricset-elasticsearch-ccr,ccr>>

* <<metricbeat-metricset-elasticsearch-cluster_stats,cluster_stats>>

* <<metricbeat-metricset-elasticsearch-index,index>>
Expand All @@ -69,6 +71,8 @@ The following metricsets are available:

* <<metricbeat-metricset-elasticsearch-shard,shard>>

include::elasticsearch/ccr.asciidoc[]

include::elasticsearch/cluster_stats.asciidoc[]

include::elasticsearch/index.asciidoc[]
Expand Down
23 changes: 23 additions & 0 deletions metricbeat/docs/modules/elasticsearch/ccr.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
////
This file is generated! See scripts/docs_collector.py
////

[[metricbeat-metricset-elasticsearch-ccr]]
=== Elasticsearch ccr metricset

beta[]

include::../../../module/elasticsearch/ccr/_meta/docs.asciidoc[]


==== Fields

For a description of each field in the metricset, see the
<<exported-fields-elasticsearch,exported fields>> section.

Here is an example document generated by this metricset:

[source,json]
----
include::../../../module/elasticsearch/ccr/_meta/data.json[]
----
3 changes: 2 additions & 1 deletion metricbeat/docs/modules_list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ This file is generated! See scripts/docs_collector.py
|<<metricbeat-module-dropwizard,Dropwizard>> beta[] |image:./images/icon-no.png[No prebuilt dashboards] |
.1+| .1+| |<<metricbeat-metricset-dropwizard-collector,collector>> beta[]
|<<metricbeat-module-elasticsearch,Elasticsearch>> beta[] |image:./images/icon-no.png[No prebuilt dashboards] |
.9+| .9+| |<<metricbeat-metricset-elasticsearch-cluster_stats,cluster_stats>> beta[]
.10+| .10+| |<<metricbeat-metricset-elasticsearch-ccr,ccr>> beta[]
|<<metricbeat-metricset-elasticsearch-cluster_stats,cluster_stats>> beta[]
|<<metricbeat-metricset-elasticsearch-index,index>> beta[]
|<<metricbeat-metricset-elasticsearch-index_recovery,index_recovery>> beta[]
|<<metricbeat-metricset-elasticsearch-index_summary,index_summary>> beta[]
Expand Down
16 changes: 16 additions & 0 deletions metricbeat/helper/elastic/elastic.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"strings"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/metricbeat/mb"
)

Expand Down Expand Up @@ -92,3 +93,18 @@ func ReportErrorForMissingField(field string, product Product, r mb.ReporterV2)
func MakeErrorForMissingField(field string, product Product) error {
return fmt.Errorf("Could not find field '%v' in %v stats API response", field, strings.Title(product.String()))
}

// IsFeatureAvailable returns whether a feature is available in the current product version
func IsFeatureAvailable(currentProductVersion, featureAvailableInProductVersion string) (bool, error) {
currentVersion, err := common.NewVersion(currentProductVersion)
if err != nil {
return false, err
}

wantVersion, err := common.NewVersion(featureAvailableInProductVersion)
if err != nil {
return false, err
}

return !currentVersion.LessThan(wantVersion), nil
}
1 change: 1 addition & 0 deletions metricbeat/include/list.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions metricbeat/module/elasticsearch/ccr/_meta/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"@timestamp": "2017-10-12T08:05:34.853Z",
"beat": {
"hostname": "host.example.com",
"name": "host.example.com"
},
"elasticsearch": {
"ccr": {
"follower": {
"global_checkpoint": 1,
"index": "my_follower",
"operations_indexed": 2,
"shard": {
"number": 0
},
"time_since_last_fetch": {
"ms": 4926
}
},
"leader": {
"index": "my_leader",
"max_seq_no": 1
}
},
"cluster": {
"id": "KSGkOjOuSg6whAgtpPyhQw",
"name": "elasticsearch"
}
},
"metricset": {
"host": "127.0.0.1:9200",
"module": "elasticsearch",
"name": "ccr",
"rtt": 115
},
"service": {
"name": "elasticsearch"
}
}
3 changes: 3 additions & 0 deletions metricbeat/module/elasticsearch/ccr/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This is the `ccr` metricset of the Elasticsearch module. It interrogates the
Cross Cluster Replication Stats API endpoint to fetch information about shards
in the Elasticsearch cluster that are participating in cross-cluster replication.
40 changes: 40 additions & 0 deletions metricbeat/module/elasticsearch/ccr/_meta/fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
- name: ccr
type: group
description: >
Cross-cluster replication stats
release: beta
fields:
- name: leader
type: group
fields:
- name: index
type: keyword
description: >
Name of leader index
- name: max_seq_no
type: long
description: >
Maximum sequence number of operation on the leader shard
- name: follower
type: group
fields:
- name: index
type: keyword
description: >
Name of follower index
- name: shard.number
type: long
description: >
Number of the shard within the index
- name: operations_indexed
type: long
description: >
Number of operations indexed (replicated) into the follower shard from the leader shard
- name: time_since_last_fetch.ms
type: long
description: >
Time, in ms, since the follower last fetched from the leader
- name: global_checkpoint
type: long
description: >
Global checkpoint value on follower shard
98 changes: 98 additions & 0 deletions metricbeat/module/elasticsearch/ccr/_meta/test/ccr_stats.700.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"my_follower": [
{
"leader_index": "my_leader",
"follower_index": "my_follower",
"shard_id": 0,
"leader_global_checkpoint": 1,
"leader_max_seq_no": 1,
"follower_global_checkpoint": 1,
"follower_max_seq_no": 1,
"last_requested_seq_no": 1,
"number_of_concurrent_reads": 1,
"number_of_concurrent_writes": 0,
"number_of_queued_writes": 0,
"mapping_version": 2,
"total_fetch_time_millis": 21,
"number_of_successful_fetches": 142,
"number_of_failed_fetches": 6743,
"operations_received": 2,
"total_transferred_bytes": 166,
"total_index_time_millis": 48,
"number_of_successful_bulk_operations": 2,
"number_of_failed_bulk_operations": 0,
"number_of_operations_indexed": 2,
"fetch_exceptions": [
{
"from_seq_no": 2,
"retries": 6743,
"exception": {
"type": "exception",
"reason": "NoShardAvailableActionException[No shard available for [Request{fromSeqNo=2, maxOperationCount=1024, shardId=[leader][0], expectedHistoryUUID=ki9Do9c-QQKVydB-6Txkdg, maxOperationSizeInBytes=9223372036854775807}]]; nested: RemoteTransportException[[d0XH9XU][127.0.0.1:9300][indices:data/read/xpack/ccr/shard_changes[s]]]; nested: IndexNotFoundException[no such index];",
"caused_by": {
"type": "no_shard_available_action_exception",
"reason": "No shard available for [Request{fromSeqNo=2, maxOperationCount=1024, shardId=[leader][0], expectedHistoryUUID=ki9Do9c-QQKVydB-6Txkdg, maxOperationSizeInBytes=9223372036854775807}]",
"caused_by": {
"type": "index_not_found_exception",
"reason": "no such index",
"index_uuid": "RH8_j_w0Q0GGmpY0HMVQ_A",
"index": "my_leader"
}
}
}
}
],
"time_since_last_fetch_millis": 470
},
{
"leader_index": "my_leader",
"follower_index": "my_follower",
"shard_id": 1,
"leader_global_checkpoint": -1,
"leader_max_seq_no": -1,
"follower_global_checkpoint": -1,
"follower_max_seq_no": -1,
"last_requested_seq_no": -1,
"number_of_concurrent_reads": 0,
"number_of_concurrent_writes": 0,
"number_of_queued_writes": 0,
"mapping_version": 2,
"total_fetch_time_millis": 0,
"number_of_successful_fetches": 336,
"number_of_failed_fetches": 0,
"operations_received": 0,
"total_transferred_bytes": 0,
"total_index_time_millis": 0,
"number_of_successful_bulk_operations": 0,
"number_of_failed_bulk_operations": 0,
"number_of_operations_indexed": 0,
"fetch_exceptions": [],
"time_since_last_fetch_millis": 4323
},
{
"leader_index": "my_leader",
"follower_index": "my_follower",
"shard_id": 2,
"leader_global_checkpoint": 1,
"leader_max_seq_no": 1,
"follower_global_checkpoint": 1,
"follower_max_seq_no": 1,
"last_requested_seq_no": 1,
"number_of_concurrent_reads": 0,
"number_of_concurrent_writes": 0,
"number_of_queued_writes": 0,
"mapping_version": 2,
"total_fetch_time_millis": 0,
"number_of_successful_fetches": 372,
"number_of_failed_fetches": 0,
"operations_received": 2,
"total_transferred_bytes": 166,
"total_index_time_millis": 32,
"number_of_successful_bulk_operations": 2,
"number_of_failed_bulk_operations": 0,
"number_of_operations_indexed": 2,
"fetch_exceptions": [],
"time_since_last_fetch_millis": 4323
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading

0 comments on commit 4f14d66

Please sign in to comment.