-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check ES for CCR feature availability #17073
Changes from 10 commits
cdc8a17
79e1b81
0965036
be74b1f
52bf9d4
d0570ab
13e4b24
ef82a63
c16a5e1
0ae344c
cafb9c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
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. | ||
Cross-Cluster Replication Stats API endpoint to fetch metrics about cross-cluster | ||
replication from the Elasticsearch clusters that are participating in cross-cluster | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor, but I'm trying to clean up the docs by using the correct attribute to resolve product names. So you should use {es} instead of Elasticsearch throughout this topic. |
||
replication. | ||
|
||
If the Elasticserach cluster does not have the cross-cluster replication feature | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest pruning a few words here and saying: "...does not have cross-cluster replication enabled..." |
||
enabled, this metricset will not collect any metrics. A DEBUG log message about this | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again, some pruning: "...will not collect metrics." |
||
will be emitted in the Metricbeat log. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package ccr | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/elastic/beats/v7/metricbeat/module/elasticsearch" | ||
|
||
mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing" | ||
) | ||
|
||
func startESServer(esVersion, license string, ccrEnabled bool) *httptest.Server { | ||
|
||
nodesLocalHandler := func(w http.ResponseWriter, r *http.Request) { | ||
w.Write([]byte(`{"nodes": { "foobar": {}}}`)) | ||
} | ||
clusterStateMasterHandler := func(w http.ResponseWriter, r *http.Request) { | ||
w.Write([]byte(`{"master_node": "foobar"}`)) | ||
} | ||
rootHandler := func(w http.ResponseWriter, r *http.Request) { | ||
if r.URL.Path != "/" { | ||
http.NotFound(w, r) | ||
} | ||
w.Write([]byte(`{"version": { "number": "` + esVersion + `" } }`)) | ||
} | ||
licenseHandler := func(w http.ResponseWriter, r *http.Request) { | ||
w.Write([]byte(`{ "license": { "type": "` + license + `" } }`)) | ||
} | ||
xpackHandler := func(w http.ResponseWriter, r *http.Request) { | ||
w.Write([]byte(`{ "features": { "ccr": { "enabled": ` + strconv.FormatBool(ccrEnabled) + `}}}`)) | ||
} | ||
ccrStatsHandler := func(w http.ResponseWriter, r *http.Request) { | ||
http.Error(w, "this should never have been called", 418) | ||
} | ||
|
||
mux := http.NewServeMux() | ||
mux.Handle("/_nodes/_local/nodes", http.HandlerFunc(nodesLocalHandler)) | ||
mux.Handle("/_cluster/state/master_node", http.HandlerFunc(clusterStateMasterHandler)) | ||
mux.Handle("/", http.HandlerFunc(rootHandler)) | ||
mux.Handle("/_license", http.HandlerFunc(licenseHandler)) // for 7.0 and above | ||
mux.Handle("/_xpack/license", http.HandlerFunc(licenseHandler)) // for before 7.0 | ||
mux.Handle("/_xpack", http.HandlerFunc(xpackHandler)) | ||
mux.Handle("/_ccr/stats", http.HandlerFunc(ccrStatsHandler)) | ||
|
||
return httptest.NewServer(mux) | ||
} | ||
|
||
func TestCCRNotAvailable(t *testing.T) { | ||
tests := map[string]struct { | ||
esVersion string | ||
license string | ||
ccrEnabled bool | ||
}{ | ||
"old_version": { | ||
"6.4.0", | ||
"platinum", | ||
true, | ||
}, | ||
"low_license": { | ||
"7.6.0", | ||
"basic", | ||
true, | ||
}, | ||
"feature_unavailable": { | ||
"7.6.0", | ||
"platinum", | ||
false, | ||
}, | ||
} | ||
|
||
// Disable license caching for these tests | ||
elasticsearch.LicenseCacheEnabled = false | ||
defer func() { elasticsearch.LicenseCacheEnabled = true }() | ||
|
||
for name, test := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
server := startESServer(test.esVersion, test.license, test.ccrEnabled) | ||
defer server.Close() | ||
|
||
ms := mbtest.NewReportingMetricSetV2Error(t, getConfig(server.URL)) | ||
events, errs := mbtest.ReportingFetchV2Error(ms) | ||
|
||
require.Empty(t, errs) | ||
require.Empty(t, events) | ||
}) | ||
} | ||
} | ||
|
||
func getConfig(host string) map[string]interface{} { | ||
return map[string]interface{}{ | ||
"module": elasticsearch.ModuleName, | ||
"metricsets": []string{"ccr"}, | ||
"hosts": []string{host}, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a sentence fragment. Maybe say something like:
"This metricset uses the Cross-Cluster Replication Stats API endpoint to fetch...."