Skip to content
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

Report kibana_settings to X-Pack Monitoring #7664

Merged
merged 6 commits into from
Aug 9, 2018

Conversation

ycombinator
Copy link
Contributor

@ycombinator ycombinator commented Jul 20, 2018

Resolves #7621.

Depends on elastic/kibana#21100.

X-Pack Monitoring of Kibana requires two types of documents in the .monitoring-kibana-* indices: kibana_stats and kibana_settings. We made Metricbeat's kibana/stats metricset index kibana_stats documents into .monitoring-kibana-* in #7525. This PR makes the same metricset index kibana_settings documents into .monitoring-kibana-*.

To test this PR

The idea is that metricbeat (specifically the kibana/stats metricset with xpack.enabled: true) will create exactly the same documents in .monitoring-kibana-* indices as Kibana's bulk uploader does today.

  1. Start up Elasticsearch (with the default Basic license is okay)

  2. Start up Kibana (with the default Basic license is okay), checked out from master.

  3. Enable Monitoring in Elasticsearch (via the cluster setting xpack.monitoring.collection.enabled: true). You can do this via Elasticsearch's Cluster Update Settings API or by clicking the "Turn on Monitoring" button in the Monitoring UI in Kibana.

  4. Let Kibana run for ~20 seconds so a few documents are indexed into .monitoring-kibana-*.

  5. Stop Kibana

  6. From .monitoring-kibana-*, retrieve a document for type = kibana_settings

  7. Delete the .monitoring-kibana-* indices.

  8. In kibana.yml, set xpack.monitoring.kibana.collection.enabled: false. This will ensure that Kibana is no longer directly shipping its monitoring metrics to Elasticsearch.

  9. Start up Kibana again, this time checked out from [Monitoring] Kibana settings api kibana#21100.

  10. Enable the kibana module in metricbeat: ./metricbeat modules enable kibana.

  11. In modules.d/kibana.yml, add the stats metricset and set xpack.enabled: true. Concretely, your modules.d/kibana.yml should look something like this:

    - module: kibana
       metricsets:
       - stats
       period: 10s
       hosts: ["localhost:5601"]
       #basepath: ""
       #username: "user"
       #password: "secret"
       xpack.enabled: true

    Additionally, if your Kibana URLs have a basepath prefix, say foo, make sure to un-comment the basepath setting in the kibana module YAML file and set it's value to "foo".

  12. Start metricbeat.

  13. Let metricbeat run for ~20 seconds so a few documents are indexed into .monitoring-kibana-*.

  14. Stop metricbeat

  15. From .monitoring-kibana-*, retrieve a document for type = kibana_settings.

  16. Using a tool such as http://www.jsondiff.com, compare the documents indexed by Kibana's with those indexed by metricbeat. Verify that their structures are identical (same fields, not necessarily same values), except for these known and expected differences:

    1. Only Metricbeat-indexed documents are expected to contain the fields @timestamp, beat, host, and metricset. These are "standard" fields added by beats and metricbeat and don't have an adverse impact since they are additive.
    2. Only Kibana-indexed documents are expected to contain the field source_node. This field is used for debugging purposes only and not actually consumed by either the Monitoring UI or Telemetry feature in Kibana.

@ycombinator ycombinator added in progress Pull request is currently in progress. Metricbeat Metricbeat v7.0.0-alpha1 monitoring labels Jul 20, 2018
@@ -34,18 +37,21 @@ func init() {
}

var (
hostParser = parse.URLHostParserBuilder{
statsPath = "api/stats"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about making these 2 a const?

now := time.Now()

m.fetchStats(r, intervalMs, now)
m.fetchSettings(r, intervalMs, now)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to have the XPack check directly here instead of in the fetchSettings method below. The reason is that for a read it would make it directly clear here that it is only called if XPack is enabled.

@@ -0,0 +1,18 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a test file for 6.3 or 6.4?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The settings API in Kibana is not expected to exist until 6.5. Once it has been implemented for 6.5, I can add a settings.650.json file here. Should I do that?

Is your concern about how Metricbeat >= 6.5.0 will react when running with Kibana < 6.5.0?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Seems like we should get the version number of KB on the first request and make decisions based on it.

Copy link
Contributor Author

@ycombinator ycombinator Jul 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I have a question about this. Prior to 6.4.0 there is no GET /api/stats in Kibana either. Does that mean we should be checking the version of Kibana before making that call too? [EDIT] This would require yet another Kibana API call, to GET /api/status first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think we will need such a check or at least provide a good error message.

I think we could check the version once during New and just assume it stays the same over the lifetime of the metricset for now. So we would only do it once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to add this version check in New in a separate PR since it affects code that has already been merged into master (#7525). I will rebase this PR on top of my new PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version check PR: #7697

Copy link
Contributor Author

@ycombinator ycombinator Jul 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented version check for Kibana settings API in 85b2438.

@ycombinator ycombinator added review and removed in progress Pull request is currently in progress. labels Aug 7, 2018
@ycombinator
Copy link
Contributor Author

@ruflin The Kibana PR that this PR was dependent upon has now been merged. So this PR is ready for a final review/merge.

@ycombinator ycombinator added the needs_backport PR is waiting to be backported to other branches. label Aug 8, 2018
NOTICE.txt Outdated
@@ -171,6 +171,21 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

--------------------------------------------------------------------
Dependency: github.com/coreos/go-semver
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this package still somewhere used?

Copy link
Contributor Author

@ycombinator ycombinator Aug 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be any more. This section probably got re-introduced during a rebase or something. I will remove it. Thanks for catching!

var data map[string]interface{}
err := json.Unmarshal(content, &data)
if err != nil {
r.Error(err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we report an error in x-pack or just ignore it? I would opt for ignoring for now as it ends up in an other index and we will not make use of it.

if err != nil {
return nil, err
}

kibanaVersion, err := kibana.GetVersion(http, statsPath)
kibanaVersion, err := kibana.GetVersion(statsHTTP, statsPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I just realised that bugs me a bit with this implementation is that it requires Kibana to be up and running normally when Metricbeat is started. Assuming Kibana is flaky during the moment the check happens, the metricset will not be running but error out even though Kibana could be totally fine again 1 sec later.

Not for this PR but thought worth mentioning.

Copy link
Contributor Author

@ycombinator ycombinator Aug 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I suppose we could move this check (and the code dependent on it) into Fetch() but that might be too expensive to run every fetch cycle?

Copy link
Contributor Author

@ycombinator ycombinator Aug 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we need another metricset lifecycle method in addition to New() and Fetch(), say Ping() (I know, not a great name), which runs periodically but less frequently than Fetch(). The frequency can be defined per-metricset in that metricset's New() function.

By default this Ping() method would do nothing. A metricset could, however, override it. The code in Ping() could then set fields in the metricset's struct so the code in Fetch() can use the data in those fields.

In the case of this metricset, we would move the Kibana version checking (and dependent) code into Ping().

Thoughts? I agree that this would be beyond the scope of this PR but, if you like it, I can make a separate issue/followup PR for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using fetch but do it only once? I remember we do something like that in other cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged as it's something we should discuss as a follow up.

@@ -101,17 +131,35 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
// It returns the event which is then forward to the output. In case of an error, a
// descriptive error must be returned.
func (m *MetricSet) Fetch(r mb.ReporterV2) {
content, err := m.http.FetchContent()
intervalMs := m.Module().Config().Period.Nanoseconds() / 1000 / 1000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have this code inside the x-pack part as it's only used there I think? Perhaps we can find a way to only if that xPackEnabled check once and run instead also in fetchStats. Why not move this to line 151 with the fetchSettings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I fully understood your comment but I took a stab at it in 3afa1a2. Take a look and let me know what you think. Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

func (m *MetricSet) fetchSettings(r mb.ReporterV2, intervalMs int64, now time.Time) {
content, err := m.settingsHTTP.FetchContent()
if err != nil {
r.Error(err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we report an error? I think we will not make use of it.

@ruflin ruflin merged commit 2af5ab9 into elastic:master Aug 9, 2018
ruflin pushed a commit that referenced this pull request Aug 13, 2018
Resolves #7621.

Depends on elastic/kibana#21100.

X-Pack Monitoring of Kibana requires two types of documents in the `.monitoring-kibana-*` indices: `kibana_stats` and `kibana_settings`. We made Metricbeat's `kibana/stats` metricset index `kibana_stats` documents into `.monitoring-kibana-*` in #7525. This PR makes the same metricset index `kibana_settings` documents into `.monitoring-kibana-*`.

(cherry picked from commit 2af5ab9)
@ycombinator ycombinator removed the needs_backport PR is waiting to be backported to other branches. label Aug 13, 2018
@ycombinator ycombinator deleted the metricbeat/kibana/settings branch December 25, 2019 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Index kibana_settings docs for Kibana X-Pack Monitoring
2 participants