Skip to content

[Reporting] Use spaceId from request in export generation#76998

Merged
tsullivan merged 20 commits intoelastic:masterfrom
tsullivan:fix/68076
Sep 18, 2020
Merged

[Reporting] Use spaceId from request in export generation#76998
tsullivan merged 20 commits intoelastic:masterfrom
tsullivan:fix/68076

Conversation

@tsullivan
Copy link
Copy Markdown
Member

@tsullivan tsullivan commented Sep 8, 2020

Summary

Release note: Fixed the reporting exports to use the correct Space for advanced settings.

Explanation:
Reporting builds a fakeRequest object to use as a source that provides UI Settings. If the request does not have the space ID baked in, the settings will always come from the default space.

Right now, none of the fake request objects have a space ID baked in, so the default space settings are always used. This affects:

  • CSV: csv:separator and csv:quoteValues are space-specific settings
  • PDF: xpackReporting:customPdfLogo is space-specific

This PR captures the spaceId from the request at job creation time. It plays into the fakeRequest objects at job execution time using:

core.http.basePath.set(fakeRequest, `/s/${spaceId}`)

It replaces code from a very old PR that incorporated the basePath of the request URL to determine the space ID. It then would incorporate the spaceId into fake requests by adding a getBasePath method, which was expected to return the space ID along with the base path. In the new platform, there is no getBasePath method of KibanaRequest, which makes the basePath handling on the server side useless. This PR removes the basePath field from job params since it isn't useful to receive it.

Fix #68076
Fix #70175
Fix: PDF Logo is always taken from default space

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@tsullivan tsullivan force-pushed the fix/68076 branch 2 times, most recently from dd19128 to 9ef809a Compare September 9, 2020 21:52
Copy link
Copy Markdown
Member Author

@tsullivan tsullivan Sep 9, 2020

Choose a reason for hiding this comment

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

This is the no-longer-working code for supporting spaces in our UI Settings clients.

Comment thread x-pack/plugins/reporting/server/export_types/csv/execute_job.ts Outdated
@tsullivan tsullivan force-pushed the fix/68076 branch 3 times, most recently from a16c44c to baafb3f Compare September 9, 2020 22:34
@tsullivan tsullivan changed the title Fix/68076 [Reporting] Use spaceId from request in export generation Sep 9, 2020
@tsullivan tsullivan force-pushed the fix/68076 branch 12 times, most recently from 1acd05e to 1953026 Compare September 10, 2020 22:33
Comment thread x-pack/plugins/reporting/server/export_types/printable_pdf/execute_job/index.ts Outdated
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I refactored getCustomLogo to receive more specific parameters. The other common helper functions here could probably use the same thing

@elasticmachine
Copy link
Copy Markdown
Contributor

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

if (spacesService) {
if (spaceId && spaceId !== DEFAULT_SPACE_ID) {
this.logger.info(`Generating request for space: ` + spaceId);
this.getPluginSetupDeps().basePath.set(fakeRequest, `/s/${spaceId}`);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

cc @jportner Thanks for your help in figuring this part out! Please take a look at how I am using your advice and let me know if you have any thoughts about it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As discussed offline -- looks great!

@tsullivan
Copy link
Copy Markdown
Member Author

@elasticmachine merge upstream

@tsullivan tsullivan merged commit 6908fe7 into elastic:master Sep 18, 2020
@tsullivan tsullivan deleted the fix/68076 branch September 18, 2020 20:08
tsullivan added a commit to tsullivan/kibana that referenced this pull request Sep 18, 2020
)

* [Reporting] Use spaceId from request in export generation

* remove todo that has been done

* whitespace

* use post params api in test

* add logging to core

* Update x-pack/plugins/reporting/server/export_types/printable_pdf/lib/get_custom_logo.ts

Co-authored-by: Joel Griffith <joel@joelgriffith.net>

* more logging

* fix interdependence and remove Promise.all

* getAbsoluteUrl have only 1 way to provide basePath

* --wip-- [skip ci]

* log apipath

* deleteAllReports at the end

* tests pass locally

* set config in the tests

* re-add skips of flaky tests

* test using csv:quoteValues

Co-authored-by: Joel Griffith <joel@joelgriffith.net>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
@kibanamachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky


Test Failures

X-Pack APM API integration tests (basic).x-pack/test/apm_api_integration/basic/tests/metrics_charts/metrics_charts·ts.APM specs (basic) Metrics when data is loaded for opbeans-node returns metrics data CPU usage has correct series overall values

Link to Jenkins

Standard Out

Failed Tests Reporter:
  - Test has failed 2 times on tracked branches: https://github.com/elastic/kibana/issues/77870

[00:00:00]       │
[00:00:00]         └-: APM specs (basic)
[00:00:00]           └-> "before all" hook
[00:01:42]           └-: Metrics
[00:01:42]             └-> "before all" hook
[00:01:42]             └-: when data is loaded
[00:01:42]               └-> "before all" hook
[00:01:42]               └-> "before all" hook
[00:01:42]                 │ info [metrics_8.0.0] Loading "mappings.json"
[00:01:42]                 │ info [metrics_8.0.0] Loading "data.json.gz"
[00:01:42]                 │ info [o.e.c.m.MetadataCreateIndexService] [kibana-ci-immutable-centos-tests-xxl-1600453518999560881] [apm-8.0.0-metric-000001] creating index, cause [api], templates [], shards [1]/[0]
[00:01:42]                 │ info [o.e.c.r.a.AllocationService] [kibana-ci-immutable-centos-tests-xxl-1600453518999560881] current.health="GREEN" message="Cluster health status changed from [YELLOW] to [GREEN] (reason: [shards started [[apm-8.0.0-metric-000001][0]]])." previous.health="YELLOW" reason="shards started [[apm-8.0.0-metric-000001][0]]"
[00:01:42]                 │ info [metrics_8.0.0] Created index "apm-8.0.0-metric-000001"
[00:01:42]                 │ debg [metrics_8.0.0] "apm-8.0.0-metric-000001" settings {"index":{"codec":"best_compression","lifecycle":{"name":"apm-rollover-30-days","rollover_alias":"apm-8.0.0-metric"},"mapping":{"total_fields":{"limit":"2000"}},"max_docvalue_fields_search":"200","number_of_replicas":"0","number_of_shards":"1","priority":"100","refresh_interval":"1ms"}}
[00:01:42]                 │ info [metrics_8.0.0] Indexed 2323 docs into "apm-8.0.0-metric-000001"
[00:01:42]               └-: for opbeans-node
[00:01:42]                 └-> "before all" hook
[00:01:42]                 └-: returns metrics data
[00:01:42]                   └-> "before all" hook
[00:01:42]                   └-> "before all" hook
[00:01:43]                   └-> contains CPU usage and System memory usage chart data
[00:01:43]                     └-> "before each" hook: global before each
[00:01:43]                     └-> "before each" hook
[00:01:43]                     └- ✓ pass  (1ms) "APM specs (basic) Metrics when data is loaded for opbeans-node returns metrics data contains CPU usage and System memory usage chart data"
[00:01:43]                   └-> "after each" hook
[00:01:43]                   └-: CPU usage
[00:01:43]                     └-> "before all" hook
[00:01:43]                     └-> "before all" hook
[00:01:43]                     └-> has correct series
[00:01:43]                       └-> "before each" hook: global before each
[00:01:43]                       └-> "before each" hook
[00:01:43]                       └- ✓ pass  (0ms) "APM specs (basic) Metrics when data is loaded for opbeans-node returns metrics data CPU usage has correct series"
[00:01:43]                     └-> "after each" hook
[00:01:43]                     └-> has correct series overall values
[00:01:43]                       └-> "before each" hook: global before each
[00:01:43]                       └-> "before each" hook
[00:01:43]                       └- ✖ fail: APM specs (basic) Metrics when data is loaded for opbeans-node returns metrics data CPU usage has correct series overall values
[00:01:43]                       │       Error: expect(received).toMatchInlineSnapshot(snapshot)
[00:01:43]                       │ 
[00:01:43]                       │ Snapshot name: `when data is loaded for opbeans-node returns metrics data CPU usage has correct series overall values 1`
[00:01:43]                       │ 
[00:01:43]                       │ - Snapshot  - 1
[00:01:43]                       │ + Received  + 1
[00:01:43]                       │ 
[00:01:43]                       │   Array [
[00:01:43]                       │     0.714,
[00:01:43]                       │ -   0.38770000000000004,
[00:01:43]                       │ +   0.3877,
[00:01:43]                       │     0.75,
[00:01:43]                       │     0.2543,
[00:01:43]                       │   ]
[00:01:43]                       │       + expected - actual
[00:01:43]                       │ 
[00:01:43]                       │       -false
[00:01:43]                       │       +true
[00:01:43]                       │       
[00:01:43]                       │       at Assertion.assert (/dev/shm/workspace/parallel/15/kibana/packages/kbn-expect/expect.js:100:11)
[00:01:43]                       │       at Assertion.toMatchInline [as eql] (/dev/shm/workspace/parallel/15/kibana/packages/kbn-expect/expect.js:244:8)
[00:01:43]                       │       at Context.apply (test/apm_api_integration/basic/tests/metrics_charts/metrics_charts.ts:69:16)
[00:01:43]                       │       at Object.apply (/dev/shm/workspace/parallel/15/kibana/packages/kbn-test/src/functional_test_runner/lib/mocha/wrap_function.js:84:30)
[00:01:43]                       │ 
[00:01:43]                       │ 

Stack Trace

{ Error: expect(received).toMatchInlineSnapshot(snapshot)

Snapshot name: `when data is loaded for opbeans-node returns metrics data CPU usage has correct series overall values 1`

- Snapshot  - 1
+ Received  + 1

  Array [
    0.714,
-   0.38770000000000004,
+   0.3877,
    0.75,
    0.2543,
  ]
    at Assertion.assert (/dev/shm/workspace/parallel/15/kibana/packages/kbn-expect/expect.js:100:11)
    at Assertion.toMatchInline [as eql] (/dev/shm/workspace/parallel/15/kibana/packages/kbn-expect/expect.js:244:8)
    at Context.apply (test/apm_api_integration/basic/tests/metrics_charts/metrics_charts.ts:69:16)
    at Object.apply (/dev/shm/workspace/parallel/15/kibana/packages/kbn-test/src/functional_test_runner/lib/mocha/wrap_function.js:84:30) actual: 'false', expected: 'true', showDiff: true }

Build metrics

distributable file count

id value diff baseline
default 45938 -1 45939

History

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

tsullivan added a commit that referenced this pull request Sep 19, 2020
…77952)

* [Reporting] Use spaceId from request in export generation

* remove todo that has been done

* whitespace

* use post params api in test

* add logging to core

* Update x-pack/plugins/reporting/server/export_types/printable_pdf/lib/get_custom_logo.ts

Co-authored-by: Joel Griffith <joel@joelgriffith.net>

* more logging

* fix interdependence and remove Promise.all

* getAbsoluteUrl have only 1 way to provide basePath

* --wip-- [skip ci]

* log apipath

* deleteAllReports at the end

* tests pass locally

* set config in the tests

* re-add skips of flaky tests

* test using csv:quoteValues

Co-authored-by: Joel Griffith <joel@joelgriffith.net>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Joel Griffith <joel@joelgriffith.net>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
@sophiec20 sophiec20 added the zDeprecated Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead label Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_note:fix v7.10.0 v8.0.0 zDeprecated Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead

Projects

None yet

6 participants