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

[Reporting] ReportingStore module #69426

Merged
merged 9 commits into from
Jun 25, 2020
Merged

Conversation

tsullivan
Copy link
Member

@tsullivan tsullivan commented Jun 17, 2020

Summary

Part of #69340

ESQueue is currently responsible for creating the time-based Reporting index, which is abstracted in its addJob method. That functionality must be removed to allow ESQueue to be replaced with the Task Manager service.

This PR adds a new class called ReportingStore, which has feature parity with the functionality previously held by Esqueue.addJob.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@tsullivan tsullivan force-pushed the reporting/store branch 5 times, most recently from b552cfc to 72a4540 Compare June 18, 2020 23:59
@tsullivan tsullivan added (Deprecated) Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead Team:Reporting Services v8.0.0 chore release_note:skip Skip the PR/issue when compiling release notes labels Jun 23, 2020
Copy link
Member Author

@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.

comments about the diff

@@ -37,26 +36,25 @@ type GenericWorkerFn<JobParamsType> = (
...workerRestArgs: any[]
) => void | Promise<TaskRunResult>;

export async function createQueueFactory<JobParamsType, JobPayloadType>(
Copy link
Member Author

@tsullivan tsullivan Jun 23, 2020

Choose a reason for hiding this comment

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

These generics were not used, so I removed them

Copy link
Contributor

@joelgriffith joelgriffith Jun 24, 2020

Choose a reason for hiding this comment

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

Pray I don't alter it further

_primary_term: number;
}

export type Job = EventEmitter & {
Copy link
Member Author

@tsullivan tsullivan Jun 23, 2020

Choose a reason for hiding this comment

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

This type is no longer needed: replaced with Report class

};
};

export type EnqueueJobFn = <JobParamsType>(
Copy link
Member Author

Choose a reason for hiding this comment

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

Handling JobParamsType isn't necessary since jobParams is just pass-through

@@ -40,21 +37,6 @@ export class Esqueue extends EventEmitter {
});
}

addJob(jobtype, payload, opts = {}) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Replaced with ReportingStore.addJob


const puid = new Puid();

export class Job extends events.EventEmitter {
Copy link
Member Author

Choose a reason for hiding this comment

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

Replaced with Report class, minus the ES client stuff, which is part of ReportingStore

})
.then(() => true)
.catch((err) => {
/* FIXME creating the index will fail if there were multiple jobs staged in parallel.
Copy link
Member Author

Choose a reason for hiding this comment

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

This comment is carried over as-is from the ESQueue x-pack/plugins/reporting/server/lib/esqueue/helpers/create_index.js

});
}

private async saveReport(report: Report) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This method is moved over from ESQueue's Job class constructor

const isIndexExistsError = err.message.match(/resource_already_exists_exception/);
if (isIndexExistsError) {
// Do not fail a job if the job runner hits the race condition.
this.logger.warn(`Automatic index creation failed: index already exists: ${err}`);
Copy link
Member Author

Choose a reason for hiding this comment

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

This fixes a bug that was a FIXME comment: https://github.com/elastic/kibana/blob/2f67cbf/x-pack/plugins/reporting/server/lib/esqueue/helpers/create_index.js#L93

Continuing from index creation failure, when the index already exists, is now actually logged


import { LevelLogger } from '../lib';

export function createMockLevelLogger() {
Copy link
Member Author

Choose a reason for hiding this comment

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

this would have been useful to have earlier :)

@tsullivan tsullivan marked this pull request as ready for review June 24, 2020 01:58
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-reporting-services (Team:Reporting Services)

const isPollingEnabled = config.get('queue', 'pollEnabled');

const elasticsearch = await reporting.getElasticsearchService();
Copy link
Contributor

Choose a reason for hiding this comment

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

Not seeing if this changed from sync to async here. I'm assuming so...

Copy link
Member Author

Choose a reason for hiding this comment

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

This method was never async, so this is a little cleanup. It's something that doesn't get warned about.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

page load asset size

beta
id value diff baseline
/bundles/app/core/bootstrap.js - -13.8KB 13.8KB
/bundles/core/core.entry.js - -1.1MB 1.1MB
/bundles/kbn-ui-shared-deps/[email protected] - -4.0MB 4.0MB
/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.css - -183.7KB 183.7KB
/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js - -4.6MB 4.6MB
/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.v7.light.css - -511.3KB 511.3KB
/bundles/light_theme.style.css - -95.9KB 95.9KB
/bundles/plugin/advancedSettings/advancedSettings.plugin.js - -941.3KB 941.3KB
/bundles/plugin/alerts/alerts.plugin.js - -89.5KB 89.5KB
/bundles/plugin/apm/apm.plugin.js - -215.2KB 215.2KB
/bundles/plugin/apmOss/apmOss.plugin.js - -4.2KB 4.2KB
/bundles/plugin/beats_management/beats_management.plugin.js - -522.9KB 522.9KB
/bundles/plugin/bfetch/bfetch.plugin.js - -28.7KB 28.7KB
/bundles/plugin/canvas/canvas.plugin.js - -2.0MB 2.0MB
/bundles/plugin/charts/charts.plugin.js - -833.9KB 833.9KB
/bundles/plugin/cloud/cloud.plugin.js - -5.7KB 5.7KB
/bundles/plugin/console/console.plugin.js - -28.0KB 28.0KB
/bundles/plugin/crossClusterReplication/crossClusterReplication.plugin.js - -152.3KB 152.3KB
/bundles/plugin/dashboard/dashboard.plugin.js - -634.0KB 634.0KB
/bundles/plugin/dashboardEnhanced/dashboardEnhanced.plugin.js - -143.5KB 143.5KB
/bundles/plugin/dashboardMode/dashboardMode.plugin.js - -109.3KB 109.3KB
/bundles/plugin/data/data.plugin.js - -1.3MB 1.3MB
/bundles/plugin/dataEnhanced/dataEnhanced.plugin.js - -138.1KB 138.1KB
/bundles/plugin/devTools/devTools.plugin.js - -123.9KB 123.9KB
/bundles/plugin/discover/discover.plugin.js - -221.1KB 221.1KB
/bundles/plugin/discoverEnhanced/discoverEnhanced.plugin.js - -13.8KB 13.8KB
/bundles/plugin/embeddable/embeddable.plugin.js - -387.2KB 387.2KB
/bundles/plugin/embeddableEnhanced/embeddableEnhanced.plugin.js - -26.3KB 26.3KB
/bundles/plugin/esUiShared/esUiShared.plugin.js - -927.8KB 927.8KB
/bundles/plugin/expressions/expressions.plugin.js - -314.9KB 314.9KB
/bundles/plugin/features/features.plugin.js - -13.4KB 13.4KB
/bundles/plugin/fileUpload/fileUpload.plugin.js - -688.0KB 688.0KB
/bundles/plugin/globalSearch/globalSearch.plugin.js - -29.0KB 29.0KB
/bundles/plugin/graph/graph.plugin.js - -15.3KB 15.3KB
/bundles/plugin/grokdebugger/grokdebugger.plugin.js - -11.2KB 11.2KB
/bundles/plugin/home/home.plugin.js - -24.6KB 24.6KB
/bundles/plugin/indexLifecycleManagement/indexLifecycleManagement.plugin.js - -184.2KB 184.2KB
/bundles/plugin/indexManagement/indexManagement.plugin.js - -200.8KB 200.8KB
/bundles/plugin/indexPatternManagement/indexPatternManagement.plugin.js - -137.3KB 137.3KB
/bundles/plugin/infra/infra.plugin.js - -92.6KB 92.6KB
/bundles/plugin/ingestPipelines/ingestPipelines.plugin.js - -30.3KB 30.3KB
/bundles/plugin/inputControlVis/inputControlVis.plugin.js - -258.9KB 258.9KB
/bundles/plugin/inspector/inspector.plugin.js - -238.3KB 238.3KB
/bundles/plugin/kibanaLegacy/kibanaLegacy.plugin.js - -174.7KB 174.7KB
/bundles/plugin/kibanaReact/kibanaReact.plugin.js - -575.3KB 575.3KB
/bundles/plugin/kibanaUtils/kibanaUtils.plugin.js - -432.8KB 432.8KB
/bundles/plugin/lens/lens.plugin.js - -746.9KB 746.9KB
/bundles/plugin/licenseManagement/licenseManagement.plugin.js - -26.2KB 26.2KB
/bundles/plugin/licensing/licensing.plugin.js - -21.6KB 21.6KB
/bundles/plugin/logstash/logstash.plugin.js - -141.8KB 141.8KB
/bundles/plugin/management/management.plugin.js - -25.9KB 25.9KB
/bundles/plugin/maps/maps.plugin.js - -220.0KB 220.0KB
/bundles/plugin/mapsLegacy/mapsLegacy.plugin.js - -1.0MB 1.0MB
/bundles/plugin/mapsLegacyLicensing/mapsLegacyLicensing.plugin.js - -3.9KB 3.9KB
/bundles/plugin/ml/ml.plugin.js - -1.3MB 1.3MB
/bundles/plugin/monitoring/monitoring.plugin.js - -22.8KB 22.8KB
/bundles/plugin/navigation/navigation.plugin.js - -122.2KB 122.2KB
/bundles/plugin/newsfeed/newsfeed.plugin.js - -22.7KB 22.7KB
/bundles/plugin/observability/observability.plugin.js - -103.3KB 103.3KB
/bundles/plugin/painlessLab/painlessLab.plugin.js - -158.8KB 158.8KB
/bundles/plugin/regionMap/regionMap.plugin.js - -791.7KB 791.7KB
/bundles/plugin/remoteClusters/remoteClusters.plugin.js - -35.2KB 35.2KB
/bundles/plugin/reporting/reporting.plugin.js - -257.7KB 257.7KB
/bundles/plugin/rollup/rollup.plugin.js - -186.0KB 186.0KB
/bundles/plugin/savedObjects/savedObjects.plugin.js - -196.2KB 196.2KB
/bundles/plugin/savedObjectsManagement/savedObjectsManagement.plugin.js - -176.6KB 176.6KB
/bundles/plugin/searchprofiler/searchprofiler.plugin.js - -42.8KB 42.8KB
/bundles/plugin/security/security.plugin.js - -248.0KB 248.0KB
/bundles/plugin/share/share.plugin.js - -80.5KB 80.5KB
/bundles/plugin/snapshotRestore/snapshotRestore.plugin.js - -57.5KB 57.5KB
/bundles/plugin/spaces/spaces.plugin.js - -367.3KB 367.3KB
/bundles/plugin/statusPage/statusPage.plugin.js - -3.6KB 3.6KB
/bundles/plugin/telemetry/telemetry.plugin.js - -77.2KB 77.2KB
/bundles/plugin/telemetryManagementSection/telemetryManagementSection.plugin.js - -27.5KB 27.5KB
/bundles/plugin/tileMap/tileMap.plugin.js - -807.1KB 807.1KB
/bundles/plugin/transform/transform.plugin.js - -21.6KB 21.6KB
/bundles/plugin/triggers_actions_ui/triggers_actions_ui.plugin.js - -102.9KB 102.9KB
/bundles/plugin/uiActions/uiActions.plugin.js - -162.5KB 162.5KB
/bundles/plugin/uiActionsEnhanced/uiActionsEnhanced.plugin.js - -124.1KB 124.1KB
/bundles/plugin/upgradeAssistant/upgradeAssistant.plugin.js - -46.6KB 46.6KB
/bundles/plugin/uptime/uptime.plugin.js - -327.3KB 327.3KB
/bundles/plugin/usageCollection/usageCollection.plugin.js - -24.3KB 24.3KB
/bundles/plugin/visTypeMarkdown/visTypeMarkdown.plugin.js - -512.5KB 512.5KB
/bundles/plugin/visTypeMetric/visTypeMetric.plugin.js - -536.7KB 536.7KB
/bundles/plugin/visTypeTable/visTypeTable.plugin.js - -563.0KB 563.0KB
/bundles/plugin/visTypeTagcloud/visTypeTagcloud.plugin.js - -797.1KB 797.1KB
/bundles/plugin/visTypeTimelion/visTypeTimelion.plugin.js - -670.7KB 670.7KB
/bundles/plugin/visTypeTimeseries/visTypeTimeseries.plugin.js - -212.2KB 212.2KB
/bundles/plugin/visTypeVega/visTypeVega.plugin.js - -580.3KB 580.3KB
/bundles/plugin/visTypeVislib/visTypeVislib.plugin.js - -1.2MB 1.2MB
/bundles/plugin/visualizations/visualizations.plugin.js - -343.4KB 343.4KB
/bundles/plugin/visualize/visualize.plugin.js - -18.2KB 18.2KB
/bundles/plugin/watcher/watcher.plugin.js - -35.2KB 35.2KB
/node_modules/@kbn/ui-framework/dist/kui_light.css - -62.1KB 62.1KB
/translations/en.json - -29.0B 29.0B
/ui/fonts/inter_ui/Inter-UI-Medium.woff2 - -92.2KB 92.2KB
/ui/fonts/inter_ui/Inter-UI-Regular.woff2 - -86.4KB 86.4KB
total - -36.1MB -

History

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

* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

Copy link
Contributor

Choose a reason for hiding this comment

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

This is starting to feel more like a "constant" to me since it's mostly static. Not sure on your thoughts there

Copy link
Member Author

Choose a reason for hiding this comment

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

We may need to visit this more often than other constants. I think it's best to keep this easy to find.


const esqueue = await createQueueFactory(reportingCore, logger); // starts polling for pending jobs
const enqueueJob = enqueueJobFactory(reportingCore, logger); // called from generation routes
const store = new ReportingStore(reportingCore, logger);
Copy link
Contributor

Choose a reason for hiding this comment

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

How do you feel about adding an instance of the store to the reporting-core object, and having it be access via a getter like we do with the other utilities?

Copy link
Member Author

Choose a reason for hiding this comment

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

++.

We can shrink the options that get passed to pluginStart and have the core instance provide those things for itself, and provide getters.

Copy link
Member Author

@tsullivan tsullivan Jun 25, 2020

Choose a reason for hiding this comment

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

For now, my take on this ended up with more refactoring than I intended. Right now, the reporting store is to be set up in a synchronization with:

  • having the config available, to pass the constructor
  • being made available from ReportingCore before create_queue gets called. It got harder to sync that when ESQueue gets the store from ReportingCore instead of receiving it as a parameter

A few PRs from now when ESQueue is gone, we can revisit this.

Copy link
Contributor

@joelgriffith joelgriffith left a comment

Choose a reason for hiding this comment

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

Had a few thoughts on how we pass around the store object, otherwise looks good.

Copy link
Contributor

@joelgriffith joelgriffith left a comment

Choose a reason for hiding this comment

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

Will follow up with interface changes + exposing store via a core getter later. LETS GET THIS STARTED

@tsullivan tsullivan merged commit e143905 into elastic:master Jun 25, 2020
@tsullivan tsullivan deleted the reporting/store branch June 25, 2020 21:52
tsullivan added a commit to tsullivan/kibana that referenced this pull request Jun 25, 2020
* Add store class

* fix tests

* fix the createIndex bug

* add reportingstore test

* change function args

* nits

* add test for automatic index creation failure recovery
# Conflicts:
#	x-pack/plugins/reporting/server/lib/esqueue/job.js
jloleysens added a commit to jloleysens/kibana that referenced this pull request Jun 26, 2020
…t-pipelines/editor-error-messages

* ingest-pipelines/editor-dropzone-refinement: (122 commits)
  Fixes for monaco XJSON grammar parser and update form copy
  Added cancel move button
  Refactor SCSS values to variables
  use classNames as it is intended to be used
  Remove box shadow on all nested tree items
  Rename variables and prefix booleans with "is"
  Fixes bug on color picker defaults on TSVB (elastic#69889)
  [DOCS] Fixes wording in Upload a CSV section (elastic#69969)
  [Discover] Validate timerange before submitting query to ES (elastic#69363)
  [Maps] avoid using MAP_SAVED_OBJECT_TYPE constant when defining URL paths (elastic#69723)
  [Maps] Fix icon palettes are not working (elastic#69937)
  [Ingest Manager] Fix typo in constant name (elastic#69919)
  [test] skip status.allowAnonymous tests on cloud (elastic#69017)
  Fix backport (elastic#70003)
  [Reporting] ReportingStore module (elastic#69426)
  Add reporting assets to the eslint ignore file (elastic#69968)
  [Discover] set minBarHeight for high cardinality data (elastic#69875)
  Add featureUsage API to licensing context provider (elastic#69838)
  Fix uncaught typecheck merge conflict (elastic#70001)
  Use TS to discourage SO mappings with dynamic: false / dynamic: true (elastic#69927)
  ...
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jun 29, 2020
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

1 similar comment
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jul 1, 2020
tsullivan added a commit that referenced this pull request Jul 1, 2020
* [Reporting] ReportingStore module (#69426)

* Add store class

* fix tests

* fix the createIndex bug

* add reportingstore test

* change function args

* nits

* add test for automatic index creation failure recovery
# Conflicts:
#	x-pack/plugins/reporting/server/lib/esqueue/job.js

* fix ts

* fix bugs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore (Deprecated) Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead release_note:skip Skip the PR/issue when compiling release notes v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants