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

Retrofit the Bulk Uploader types combiner [ch2198] #22030

Merged
merged 8 commits into from
Aug 21, 2018

Conversation

tsullivan
Copy link
Member

@tsullivan tsullivan commented Aug 15, 2018

Replaces #21356
Resolves #21238

This PR allows the bulk uploader to handle new types of data without needing to update any legacy code. It helps remove future maintenance on monitoring/server/kibana_monitoring, i.e. internal monitoring stats upload.

Changes:

  • Flag src/server/status/collectors/get_ops_stats_collector.js with internalIgnore: true to make it used only for the HTTP stats API. Bulk Uploader uses a different ops stats collector that's going to stay in Monitoring.
  • Give collector instances a formatForBulkUpload method, which allows them to customize how they get combined into the payload for internal data upload. Customizations are optional, default will work most of the time.
    • Add formatForBulkUpload methods to the collectors created ingetKibanaUsageCollector and getReportingUsageCollector
  • Add getFilteredCollectorSet method to the collectorSet instance, to get a collectorSet instance that has only one kind of collector registered.
  • Remove BulkUploader.combineStatsLegacy

To test:

  • Index .monitoring-kibana-* data when running master
  • Index .monitoring-kibana-* data when running this branch
  • Compare 2 documents created with the different branches; they should have the same shape. http://jsondiff.com/ helps compare

Look at the kibana_stats and kibana_settings documents when comparing

@tsullivan tsullivan added v7.0.0 Team:Monitoring Stack Monitoring team labels Aug 15, 2018
@tsullivan tsullivan changed the title [WIP] Retrofit the Bulk Uploader types combiner [ch2198] Aug 15, 2018
@elastic elastic deleted a comment from elasticmachine Aug 15, 2018
@tsullivan tsullivan changed the title Retrofit the Bulk Uploader types combiner [ch2198] [WIP] Retrofit the Bulk Uploader types combiner [ch2198] Aug 15, 2018
@tsullivan tsullivan force-pushed the monitoring/collector-format branch 3 times, most recently from eb78627 to 8778c55 Compare August 15, 2018 22:12
@tsullivan tsullivan changed the title [WIP] Retrofit the Bulk Uploader types combiner [ch2198] Retrofit the Bulk Uploader types combiner [ch2198] Aug 15, 2018
fix usage collector, add comments to formatForBulk

remove unnecessary customizations
@elastic elastic deleted a comment from elasticmachine Aug 15, 2018
this.type = type;
this.init = init;
this.fetch = fetch;

this.log = getCollectorLogger(server);
const defaultFormatterForBulkUpload = result => ({ type, payload: result });
this._formatForBulkUpload = formatForBulkUpload || defaultFormatterForBulkUpload;
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm doing some testing, and it looks like I want to override this in the UsageCollector class. Usage collectors should organize their data in the kibana_stats type in the usage namespace. - c940ee1

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, that's snazzy!

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@chrisronline
Copy link
Contributor

So when I run master for kibana_settings, I don't see the xpack: { default_admin_email } in the document (I don't have one set FYI). However, in your branch, I do see one.

Is that expected?

@tsullivan
Copy link
Member Author

However, in your branch, I do see one.

I'm guessing you see the value as null. That is expected to happen once when Kibana first starts up.

The issue of seeing no value for default_admin_email is addressed in #22091, because that shouldn't be happening.

@chrisronline
Copy link
Contributor

@tsullivan So I should ignore that difference right now? Because the two documents (from master and your branch) are not identical

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@tsullivan
Copy link
Member Author

@chrisronline I merged in master after the blocker bug fix, please take another look at the settings collector, because I had to resolve a conflict there.

Let me know if you are still seeing differences in the shape of the data.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@chrisronline
Copy link
Contributor

@tsullivan Great, functionally this LGTM! Going to review the code now

@@ -44,6 +44,7 @@ export function getOpsStatsCollector(server, kbnServer) {
kibana: getKibanaInfoForStats(server, kbnServer),
...kbnServer.metrics // latest metrics captured from the ops event listener in src/server/status/index
};
}
},
internalIgnore: true, // Ignore this one from internal uploader. A different stats collector is used there.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if this can be more verbose to avoid ambiguity - maybe ignoreForInternalUploader?

@@ -73,12 +72,12 @@ export class CollectorSet {
* Call a bunch of fetch methods and then do them in bulk
* @param {Array} collectors - an array of collectors, default to all registered collectors
*/
bulkFetch(callCluster, collectors = this._collectors) {
if (!Array.isArray(collectors)) {
bulkFetch(callCluster, collectors = this) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we rename collectors to collectorSet to avoid any potential confusion? By collectors, I'd assume we're doing with an array of collectors versus a typed CollectorSet object

@@ -90,10 +89,19 @@ export class CollectorSet {
this._log.warn(`Unable to fetch data from ${collectorType} collector`);
});
});
return Promise.all(fetchPromises);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering, is there a specific reason we keep using promises versus using async/await?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really. This lets us not await each fetch one at a time. I could be wrong, but using Promise.props inside the loop has it run all the fetches at the same time.


/*
* Helper Factory methods
* Define as instance properties to allow enclosing the server object
*/
this.makeStatsCollector = options => new Collector(server, options);
this.makeUsageCollector = options => new UsageCollector(server, options);
this._makeCollectorSetFromArray = collectorsArray => new CollectorSet(server, collectorsArray);
Copy link
Contributor

@chrisronline chrisronline Aug 20, 2018

Choose a reason for hiding this comment

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

Why is this an instanced variable versus just static function defined at the top?

Copy link
Member Author

Choose a reason for hiding this comment

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

Having it here let's us enclose the server object that the constructor is called with

*/
formatForBulkUpload: result => {
return {
type: 'kibana_stats',
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use the constants here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this can use KIBANA_STATS_TYPE_MONITORING from the monitoring constants.

*/
formatForBulkUpload: result => {
return {
type: 'kibana_stats',
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto on the constant


// convert the raw data to a nested object by taking each payload through
// its formatter, organizing it per-type
const typesNested = rawData.reduce((accum, { type, result }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we include a sample of what the data structure looks like before and after each transformation? I find that helps understand intent a lot

Copy link
Contributor

@chrisronline chrisronline left a comment

Choose a reason for hiding this comment

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

Overall, looking great! I had a few questions and suggestions!

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@chrisronline chrisronline left a comment

Choose a reason for hiding this comment

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

LGTM! Tested and works great!

@tsullivan tsullivan merged commit 8718d1e into elastic:master Aug 21, 2018
@tsullivan tsullivan deleted the monitoring/collector-format branch August 21, 2018 19:29
tsullivan added a commit to tsullivan/kibana that referenced this pull request Aug 21, 2018
* Retrofit the Bulk Uploader types combiner [ch2198]

fix usage collector, add comments to formatForBulk

remove unnecessary customizations

* override default format for bulk upload for usage type collectors

* rename to ignoreForInternalUploader

* collectors -> collectorSet

* use constant for kibana_stats type

* example of data formatting for bulk in function comment
@tsullivan
Copy link
Member Author

6.5.0/6.x: #22223

tsullivan added a commit that referenced this pull request Aug 21, 2018
* Retrofit the Bulk Uploader types combiner [ch2198]

fix usage collector, add comments to formatForBulk

remove unnecessary customizations

* override default format for bulk upload for usage type collectors

* rename to ignoreForInternalUploader

* collectors -> collectorSet

* use constant for kibana_stats type

* example of data formatting for bulk in function comment
w33ble pushed a commit to w33ble/kibana that referenced this pull request Sep 13, 2018
Closes https://github.com/elastic/kibana-canvas/issues/128

Makes a summary of Canvas usage that looks like:
```
{
  "kibana_canvas": {
    "elements": {
      "per_page": {
        "avg": 2,
        "max": 3,
        "min": 1
      },
      "total": 4
    },
    "functions": {
      "in_use": [
        "filters",
        "demodata",
        "markdown",
        "render",
        "image",
        "pointseries",
        "plot",
        "getCell",
        "repeatImage"
      ],
      "per_element": {
        "avg": 4,
        "max": 5, 
        "min": 2
      },
      "total": 16
    },
    "pages": {
      "per_workpad": {
        "avg": 1,
        "max": 1,
        "min": 1
      },
      "total": 2
    },
    "workpads": {
      "total": 2
    }
  }
}
```

To complete end-to-end Telemetry functionality, More work is going on with Monitoring and Telemetry to have every registered collector automatically include the their data in the overall payload. There's ongoing work to implement that in core Kibana, but none of it blocks the PR from being merged.
- Having the Canvas usage stats automatically added to `.monitoring-kibana-*` documents depends on this PR: elastic#22030
   - That PR can be pulled to help test this PR. The result will be Canvas usage stats in the `kibana_stats` documents in `.monitoring-kibana-*`.
- Having Canvas usage stats automatically included in the telemetry payload that gets sent to Elastic depends on this unstarted issue: elastic#21239
- Without that additional work, the way to test this PR is to check for the `usage.kibana_canvas` data in the`localhost:5601/api/stats?extended=true` API response.

That pending work in Kibana core does not block this PR from getting merged.
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.

3 participants