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

[Usage Collection] Usage collection add saved objects client to collector fetch context #80554

Conversation

TinaHeiligers
Copy link
Contributor

Summary

Resolves #74840

Adds the scoped saved objects client to usage collectors' fetch context.
The saved objects client is scoped to the kibana_system role when the usage data is retrieved to send to the remote service (it will be encrypted) or to view a an example of the data that is sent. In the latter case (when the data's unencrypted), the saved objects service is scoped to the current user to ensure we're only showing them what they're allowed to see.

Before:
// server/plugin.ts
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { CoreSetup, CoreStart } from 'kibana/server';

class Plugin {
  private savedObjectsRepository?: ISavedObjectsRepository;

  public setup(core: CoreSetup, plugins: { usageCollection?: UsageCollectionSetup }) {
    registerMyPluginUsageCollector(() => this.savedObjectsRepository, plugins.usageCollection);
  }

  public start(core: CoreStart) {
    this.savedObjectsRepository = core.savedObjects.createInternalRepository();
  }
}
After:
// server/plugin.ts
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { CoreSetup, CoreStart } from 'kibana/server';

class Plugin {
  private savedObjectsRepository?: ISavedObjectsRepository;

  public setup(core: CoreSetup, plugins: { usageCollection?: UsageCollectionSetup }) {
    registerMyPluginUsageCollector(plugins.usageCollection);
  }

  public start(core: CoreStart) {
    this.savedObjectsRepository = core.savedObjects.createInternalRepository();
  }
}

Checklist

For maintainers

Copy link
Contributor Author

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

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

The data plugin imports types from the usage_collection plugin in the search/collectors/register file. The changes made in this PR bubbled up to the data plugins' API docs in the same way as a previous [PR] (80fa55d)

Copy link
Member

@Bamieh Bamieh left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -157,5 +162,6 @@ export interface Collection<
clusterDetailsGetter: ClusterDetailsGetter<CustomContext>;
esCluster: ILegacyClusterClient;
esClientGetter: () => IClusterClient | undefined; // the collection could still return undefined for the es client getter.
soServiceGetter: () => SavedObjectsServiceStart | undefined; // the collection could still return undefined for the Saved Objects Service getter.
Copy link
Member

Choose a reason for hiding this comment

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

irrelated to PR: in what cases it would return undefined?

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 saved objects client is only available during the start cycle, so if it's called before it's initialized, we'll return undefined. It's the same as for the new elasticsearch client.

@TinaHeiligers TinaHeiligers marked this pull request as ready for review October 14, 2020 18:56
@TinaHeiligers TinaHeiligers requested review from a team as code owners October 14, 2020 18:56
@TinaHeiligers TinaHeiligers requested a review from a team October 14, 2020 18:56
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-telemetry (Team:KibanaTelemetry)

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

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 for stack monitoring! It doesn't seem like you touched anything specific to us

Copy link
Member

@lukasolson lukasolson left a comment

Choose a reason for hiding this comment

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

AppArch changes LGTM

@TinaHeiligers TinaHeiligers merged commit 9afd63f into elastic:master Oct 14, 2020
@TinaHeiligers TinaHeiligers deleted the usage-collection-add-soclient-to-fetch branch October 14, 2020 23:26
TinaHeiligers added a commit that referenced this pull request Oct 15, 2020
… collector fetch context (#80554) (#80603)

# Resolved Conflicts:
#	src/plugins/usage_collection/server/routes/stats/stats.ts
gmmorris added a commit to gmmorris/kibana that referenced this pull request Oct 15, 2020
* master: (102 commits)
  [Resolver] Fix flaky test (elastic#80576)
  Update Security Solution Bug Report Template (elastic#80668)
  [Observability] Kibana home page Observability link pointing to `/landing` (elastic#80636)
  [APM] Update User Experience app callout code to reflect new name (elastic#80641)
  [APM] Add missing ML privileges (elastic#80553)
  [DOCS] Adds intro line to the ML plugin readme file (elastic#80631)
  [ML] Functional tests - fix and re-enable validation API tests (elastic#80617)
  remove non-existing dependency from uptime plugin (elastic#80623)
  [ML] Fix job selection flyout overflow (elastic#80621)
  Move dashboard code in codeowner files to canvas team (elastic#80345)
  [Security Solution][Detections] Update signals template if outdated and rollover indices (elastic#80019)
  Sort service list by TPM if health is not shown (elastic#80447)
  Add in cluster version for sec telemetry sender. (elastic#80545)
  [Usage Collection] Usage collection add saved objects client to collector fetch context (elastic#80554)
  Change tag from experimental to beta (elastic#80443)
  [Metrics UI] Inventory view cleanup (elastic#79881)
  [Security Solutions][Detection Engine] Critical bug where value lists were not operational (elastic#80368)
  [Security Solution] Fix networkTopNFlow search strategy response (elastic#80362)
  [build] Retry docker pull (elastic#80432)
  add template for Security Solution bugs (elastic#80574)
  ...
@lukeelmers lukeelmers added the Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc label Oct 1, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Telemetry release_note:enhancement Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.11.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Telemetry] Migrate to the new Elasticsearch client
7 participants