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

[Telemetry] collector set to np #51618

Merged
merged 18 commits into from
Nov 26, 2019

Conversation

Bamieh
Copy link
Member

@Bamieh Bamieh commented Nov 25, 2019

Fully migrate (server.usage.collectorSet) to New Platform under (UsageCollection) plugin.

The PR is huge but its mostly moving plugins to use this NP plugin instead.

  • Implement the new NP plugin
  • Fully migrate all plugins to use UsageCollection
  • Remove usage.collectorSet from core.
  • Update readme src/plugins/usage_collection/README.md

Testing

  • All Tests passing again
  • Test status api
  • Test local collection
  • Test xpack collection
  • Test monitoring collection
  • Test makeStatsCollector compatiblity.

Reviewers:

The PR is huge as it is touching many-many plugins, if your team is required a review; a quick way to filter the files to see only the changes relevant to you is
by filtering the files through github:

image

Footer Notes

This PR does not change the current collectorSet behavior in any way.

Closes #46924
Closes #51371

Dev Docs

Fully migrate (server.usage.collectorSet) to New Platform under (UsageCollection) plugin. To use the UsageCollector plugin to collect server side stats with the NP follow the quick guide below (Note that all the plugins are already migrated to use this new plugin in this very same PR):

  1. Make sure usageCollection is in your optional Plugins:
// plugin/kibana.json
{
  "id": "...",
  "optionalPlugins": ["usageCollection"]
}
  1. Register Usage collector in the setup function:
// server/plugin.ts
class Plugin {
  setup(core, plugins) {
    registerMyPluginUsageCollector(plugins.usageCollection);
  }
}
  1. Creating and registering a Usage Collector. Ideally collectors would be defined in a separate directory server/collectors/register.ts.
// server/collectors/register.ts
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { CallCluster } from 'src/legacy/core_plugins/elasticsearch';

export function registerMyPluginUsageCollector(usageCollection?: UsageCollectionSetup): void {
  // usageCollection is an optional dependency, so make sure to return if it is not registered.
  if (!usageCollection) {
    return;
  }

  // create usage collector
  const myCollector = usageCollection.makeUsageCollector({
    type: MY_USAGE_TYPE,
    fetch: async (callCluster: CallCluster) => {

    // query ES and get some data
    // summarize the data into a model
    // return the modeled object that includes whatever you want to track

      return {
        my_objects: {
          total: SOME_NUMBER
        }
      };
    },
  });

  // register usage collector
  usageCollection.registerCollector(myCollector);
}

@Bamieh Bamieh added Feature:NP Migration Feature:Telemetry v7.6.0 v8.0.0 release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. labels Nov 25, 2019
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@Bamieh Bamieh marked this pull request as ready for review November 26, 2019 14:39
@Bamieh Bamieh requested a review from a team as a code owner November 26, 2019 14:39
@Bamieh Bamieh requested a review from a team November 26, 2019 14:39
@Bamieh Bamieh requested review from a team as code owners November 26, 2019 14:39
Copy link
Contributor

@crob611 crob611 left a comment

Choose a reason for hiding this comment

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

Canvas changes look good 👍

Copy link
Contributor

@chrisdavies chrisdavies left a comment

Choose a reason for hiding this comment

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

The lens stuff looks good to me. I didn't review the over-arching PR, nor did I pull it down and run it.

Copy link
Contributor

@smith smith left a comment

Choose a reason for hiding this comment

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

APM changes look good.

@tsullivan
Copy link
Member

This PR does not change the current collectorSet behavior in any way.

I tested that Kibana Monitoring still works, with the self-monitoring use case, so I agree there are no regressions there.

image

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@walterra walterra left a comment

Choose a reason for hiding this comment

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

ML changes LGTM

Copy link
Member

@tsullivan tsullivan left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for doing this. It looks like a lot of work! Thanks for helping me understand the current status of Telemetry Plugin (still in Legacy) and Usage Collection Plugin (New Platform)

Copy link
Member

@legrego legrego left a comment

Choose a reason for hiding this comment

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

Spaces related changes LGTM! Thanks for doing this!

Copy link
Contributor

@kindsun kindsun left a comment

Choose a reason for hiding this comment

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

File Upload changes lgtm!

@Bamieh Bamieh requested a review from a team November 26, 2019 17:46

export const initServerWithKibana = (kbnServer: KbnServer) => {
export const initServerWithKibana = (kbnServer: Server) => {
const usageCollection = kbnServer.newPlatform.setup.plugins.usageCollection as UsageCollection;
Copy link
Member

Choose a reason for hiding this comment

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

So ideally in the NP and if we were shimmed correctly here, this would all happen in the setup method right?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jasonrhodes correct. you can check the (dev notes) for a full example.

Copy link
Contributor

@joshdover joshdover left a comment

Choose a reason for hiding this comment

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

No fundamental problems I'm worried about, just some suggestions.

maximumWaitTimeForAllCollectorsInS: config.maximumWaitTimeForAllCollectorsInS,
});

return collectorSet;
Copy link
Contributor

Choose a reason for hiding this comment

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

You may want to expose this as a key on an object to make changes to this API in the future simpler:

Suggested change
return collectorSet;
return { collectorSet };

That way you can add additional keys to the exposed API without breaking existing usages.

Copy link
Member Author

Choose a reason for hiding this comment

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

@joshdover my aim is to keep the setup function only for initializing this class and passing configs to it. The actual contract is the CollectorSet class itself. This would prevent bloating the code inside the plugin itself, and restricting it inside the CollectorSet class.

src/plugins/usage_collection/server/plugin.ts Outdated Show resolved Hide resolved
});

// register usage collector
usageCollection.registerCollector(myCollector);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this step useful? Seems like it'd be nice if usageCollection.makeUsageCollector just automatically registered it as well.

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 wanted to keep the changes to the collectorSet api to a minimal.

Initially the idea behind was that we might want to do other stuff to the collector other than registering it with the usage collector.

This might still be the case we'd want to have with statsCollector. which use the same collector but register it under statsCollection: used for monitoring ui stats and does not report it under usage.

src/plugins/usage_collection/README.md Outdated Show resolved Hide resolved
src/legacy/core_plugins/kibana/index.js Outdated Show resolved Hide resolved
src/legacy/core_plugins/kibana/index.js Outdated Show resolved Hide resolved
src/legacy/core_plugins/kibana/index.js Outdated Show resolved Hide resolved
register: (options: unknown) => unknown;
};
};
export type APMLegacyServer = Pick<Server, 'savedObjects' | 'log'> & {
Copy link
Member

@sorenlouv sorenlouv Nov 26, 2019

Choose a reason for hiding this comment

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

Yay, no more custom types. I think actually you can remove all of it so:

export type APMLegacyServer = Server;

(yes, we should just delete APMLegacyServer and use Server everywhere)

Copy link
Member

Choose a reason for hiding this comment

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

FWIW, this was per suggestion of @rudolf, to be very explicit about whatever functionality we are still using from Server, so we have better control over what we allow Server to be used for. I personally still think that that is a good idea

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@Bamieh Bamieh merged commit 0039e97 into elastic:master Nov 26, 2019
@Bamieh Bamieh deleted the telemetry/collector_set_to_np branch November 26, 2019 23:55
Bamieh added a commit that referenced this pull request Nov 27, 2019
* merge conflicts

* fix upgrade_assistant code

* fix upgrade_assistant code

* checkout upgrade_assistant from master

* checkout upgrade_assistant from master

* redo upgrade_assistant work on 7.x branch
jloleysens added a commit to jloleysens/kibana that referenced this pull request Nov 27, 2019
* upstream/7.x:
  Fix infinite redirect loop when multiple cookies are sent (elastic#50452) (elastic#51821)
  [Console] Proxy fallback (elastic#50185) (elastic#51814)
  Added endgame-* index and new heading 3 Elastic Endpoint SMP. (elastic#51071) (elastic#51828)
  [Maps] Added options to disable zoom, hide tool tips, widgets/overlays in embeddable maps (elastic#50663) (elastic#51811)
  Move errors and validate index pattern ⇒ NP (elastic#51805) (elastic#51831)
  [SIEM][Detection Engine] Adds ecs threat properties to rules (elastic#51782) (elastic#51827)
  [Lens] Remove client-side reference to server source code (elastic#51763) (elastic#51825)
  fixes drag and drop in tests (elastic#51806) (elastic#51813)
  [Uptime] Redesign/44541  new monitor list expanded row (elastic#46567) (elastic#51809)
  [7.x] [Telemetry] collector set to np (elastic#51618) (elastic#51787)
  [Uptime] added test for chart wrapper (elastic#50399) (elastic#51808)
  Expressions service fixes: better error and loading states handling (elastic#51183) (elastic#51800)
  Query String(Bar) Input - cleanup (elastic#51598) (elastic#51804)
  [ML] Adjust and re-enable categorization advanced wizard test (elastic#51005) (elastic#51017)
  fixes url state tests (elastic#51746) (elastic#51798)
  fixes browser field tests (elastic#51738) (elastic#51799)
  [Task Manager] Tests for the ability to run tasks of varying durations in parallel (elastic#51572) (elastic#51701)
  [ML] Fix anomaly detection test suite (elastic#51712) (elastic#51795)
  [SIEM] Fix Timeline drag and drop behavior (elastic#51558) (elastic#51793)
timductive pushed a commit to timductive/kibana that referenced this pull request Dec 16, 2019
* first iteration

* local collection ready

* type check

* fix collectorSet tests

* unskip test

* ordering

* collectors as array in constructor

* update README files

* update README and canvas to check for optional dep

* update README with more details

* Add file path for README example

* type UsageCollectionSetup

* run type check after refactor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:NP Migration Feature:Telemetry release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. v7.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix tests broken by 071656b9081cab19a51e891f6ffda133a56aca93 collectorSets in the New Platform