Skip to content

[Reporting] Separate internal and public API endpoints in Reporting#162288

Merged
tsullivan merged 58 commits intoelastic:mainfrom
tsullivan:reporting/use-internal-endpoints
Aug 1, 2023
Merged

[Reporting] Separate internal and public API endpoints in Reporting#162288
tsullivan merged 58 commits intoelastic:mainfrom
tsullivan:reporting/use-internal-endpoints

Conversation

@tsullivan
Copy link
Copy Markdown
Member

@tsullivan tsullivan commented Jul 19, 2023

Summary

Closes #160827
Closes #134517
Closes #149942

In this PR, the following API endpoints are moved into an internal namespace:

New endpoint path Previous
/internal/reporting/diagnose/browser /api/reporting/diagnose/browser
/internal/reporting/diagnose/screenshot /api/reporting/diagnose/screenshot
/internal/reporting/generate/immediate/csv_searchsource /api/reporting/v1/generate/immediate/csv_searchsource
/internal/reporting/generate/{exportTypeId} /api/reporting/generate/{exportTypeId}
/internal/reporting/jobs/count /api/reporting/jobs/count
/internal/reporting/jobs/delete/{jobId} /api/reporting/jobs/delete/{jobId}
/internal/reporting/jobs/info/{jobId} /api/reporting/jobs/info/{jobId}
/internal/reporting/jobs/list /api/reporting/jobs/list

Support for the public APIs continues:

Public endpoint path
/api/reporting/generate/{exportTypeId}
/api/reporting/jobs/delete/{jobId}
/api/reporting/jobs/download/{jobId}

Other changes

  1. Set access options on the routes
  2. Removed API Counter functional tests, which were skipped to begin with.
  3. Replaced functional tests with Jest integration tests.
  4. Consolidated code in the generation routes by creating the getJobParams method of the RequestHandler class.
  5. Added a new test for getJobParams
  6. Consolidated code in the job management routes
  7. Added new code for shared helpers in job management routes
  8. Reorganized libs used for route handlers:
    routes/lib/request_handler.ts             =>  routes/common/generate/request_handler.ts                              
    routes/lib/job_management_pre_routing.ts  =>  routes/common/jobs/job_management_pre_routing.ts
    routes/lib/jobs_query.ts                  =>  routes/common/jobs/jobs_query.ts
    routes/lib/get_document_payload.ts        =>  routes/common/jobs/get_document_payload.ts
    routes/lib/get_counter.ts                 =>  routes/common/get_counter.ts
    routes/lib/authorized_user_pre_routing.ts =>  routes/common/authorized_user_pre_routing.ts
    routes/lib/get_user.ts                    =>  routes/common/get_user.ts
    

Release Note

Updated API endpoint paths for Reporting to clarify which routes are public and which are not. Make sure that any custom script or application that uses Reporting endpoints only uses the public endpoints.

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.

deleting a report is manually done by the user: not a system request

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.

getting report info is manually done by the user: not a system request

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.

using the diagnostic tool is manually done by the user: not a system request

Copy link
Copy Markdown
Member Author

@tsullivan tsullivan Jul 19, 2023

Choose a reason for hiding this comment

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

I can't figure out why my editor says this line uses a deprecated signature, so the comment isn't valid

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.

Nice I'm also not seeing any issues in my editor 👍🏻

@tsullivan tsullivan force-pushed the reporting/use-internal-endpoints branch 2 times, most recently from 4e7152f to c9941b7 Compare July 20, 2023 02:11
@tsullivan tsullivan self-assigned this Jul 20, 2023
@tsullivan tsullivan added zDeprecated Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead Team:SharedUX Platform AppEx-SharedUX (formerly Global Experience) t// labels Jul 20, 2023
@tsullivan tsullivan force-pushed the reporting/use-internal-endpoints branch from fffb568 to 61c611e Compare July 20, 2023 22:55

expect(httpClient.post).toHaveBeenCalledWith(
expect.stringContaining('/diagnose/screenshot'),
expect.any(Object)
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.

the options object was removed from the API calls for many of these, since they mistakenly were used to send the asSystemRequest field

@tsullivan tsullivan force-pushed the reporting/use-internal-endpoints branch from 4305bc8 to 5122ed6 Compare July 27, 2023 23:43
counters: Counters
) {
public getJobParams(): BaseParams {
let jobParamsRison: null | string = null;
Copy link
Copy Markdown
Member Author

@tsullivan tsullivan Jul 27, 2023

Choose a reason for hiding this comment

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

I've added this helper because without it, this section of code would have had to be duplicated in x-pack/plugins/reporting/server/routes/internal/generate/generate_from_jobparams.ts and x-pack/plugins/reporting/server/routes/public/generate_from_jobparams.ts

res: KibanaResponseFactory;
}

export const commonJobsRouteHandlerFactory = (reporting: ReportingCore) => {
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.

Added these helpers to avoid duplicated code in x-pack/plugins/reporting/server/routes/internal/management/jobs.ts and x-pack/plugins/reporting/server/routes/public/jobs.ts

Comment on lines +19 to +22
// TODO: find a way to abstract this using ExportTypeRegistry: it needs a new
// public method to return this array
// const registry = reporting.getExportTypesRegistry();
// const kibanaAccessControlTags = registry.getAllAccessControlTags();
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'm not sure if we still care about this, I just copied this comment from x-pack/plugins/reporting/server/routes/generate/generate_from_jobparams.ts

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.

I am also tempted to remove this comment - I don't think it's really relevant anymore

@@ -7,29 +7,26 @@

import { schema } from '@kbn/config-schema';
import { ROUTE_TAG_CAN_REDIRECT } from '@kbn/security-plugin/server';
import { promisify } from 'util';
Copy link
Copy Markdown
Member Author

@tsullivan tsullivan Jul 28, 2023

Choose a reason for hiding this comment

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

A file was deleted and made into 2 versions, but Github shows this as a rename, so this diff makes a good outline of the goals of this PR:

  1. Use constants for the route path strings
  2. Use helpers within route handler functions to avoid duplicated code

Copy link
Copy Markdown
Contributor

@rshen91 rshen91 left a comment

Choose a reason for hiding this comment

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

I love the constants/routes file making everything so much clearer

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.

Nice I'm also not seeing any issues in my editor 👍🏻


const API_BASE_URL_V1 = '/api/reporting/v1';
const API_BASE_GENERATE_V1 = `${API_BASE_URL_V1}/generate`;
const path = INTERNAL_ROUTES.DOWNLOAD_CSV;
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.

I love that there's the constants/routes file in this PR to reference these vs it being spread across the plugin

Comment on lines +19 to +22
// TODO: find a way to abstract this using ExportTypeRegistry: it needs a new
// public method to return this array
// const registry = reporting.getExportTypesRegistry();
// const kibanaAccessControlTags = registry.getAllAccessControlTags();
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.

I am also tempted to remove this comment - I don't think it's really relevant anymore

@tsullivan tsullivan marked this pull request as ready for review July 28, 2023 16:31
@tsullivan tsullivan requested a review from a team as a code owner July 28, 2023 16:31
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/appex-sharedux (Team:SharedUX)

@tsullivan tsullivan added the release_note:skip Skip the PR/issue when compiling release notes label Jul 28, 2023
@tsullivan tsullivan requested a review from a team July 28, 2023 17:35
@tsullivan tsullivan added release_note:enhancement and removed release_note:skip Skip the PR/issue when compiling release notes labels Jul 28, 2023
@kibana-ci
Copy link
Copy Markdown

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
reporting 90 91 +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
reporting 59.1KB 59.1KB +6.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
reporting 42.8KB 43.1KB +308.0B

History

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

cc @tsullivan

@tsullivan tsullivan merged commit a2e4279 into elastic:main Aug 1, 2023
@kibanamachine kibanamachine added v8.10.0 backport:skip This PR does not require backporting labels Aug 1, 2023
@tsullivan tsullivan deleted the reporting/use-internal-endpoints branch August 1, 2023 15:24
ThomThomson pushed a commit to ThomThomson/kibana that referenced this pull request Aug 1, 2023
…lastic#162288)

## Summary

Closes elastic#160827
Closes elastic#134517
Closes elastic#149942

In this PR, the following API endpoints are moved into an internal
namespace:

| New endpoint path | Previous |
|---|---|
| `/internal/reporting/diagnose/browser` |
`/api/reporting/diagnose/browser` |
| `/internal/reporting/diagnose/screenshot` |
`/api/reporting/diagnose/screenshot` |
| `/internal/reporting/generate/immediate/csv_searchsource` |
`/api/reporting/v1/generate/immediate/csv_searchsource` |
| `/internal/reporting/generate/{exportTypeId}` |
`/api/reporting/generate/{exportTypeId}` |
| `/internal/reporting/jobs/count` | `/api/reporting/jobs/count` |
| `/internal/reporting/jobs/delete/{jobId}` |
`/api/reporting/jobs/delete/{jobId}` |
| `/internal/reporting/jobs/info/{jobId}` |
`/api/reporting/jobs/info/{jobId}` |
| `/internal/reporting/jobs/list` | `/api/reporting/jobs/list` |

Support for the public APIs continues:

| Public endpoint path |
|---|
| `/api/reporting/generate/{exportTypeId}` |
| `/api/reporting/jobs/delete/{jobId}` |
| `/api/reporting/jobs/download/{jobId}` |

## Other changes
1. Set access options on the routes
2. Removed API Counter functional tests, which were skipped to begin
with.
3. Replaced functional tests with Jest integration tests.
4. Consolidated code in the generation routes by creating the
`getJobParams` method of the `RequestHandler` class.
5. Added a new test for `getJobParams` 
6. Consolidated code in the job management routes 
7. Added new code for shared helpers in job management routes 
8. Reorganized libs used for route handlers:
    ```
routes/lib/request_handler.ts =>
routes/common/generate/request_handler.ts
routes/lib/job_management_pre_routing.ts =>
routes/common/jobs/job_management_pre_routing.ts
routes/lib/jobs_query.ts => routes/common/jobs/jobs_query.ts
routes/lib/get_document_payload.ts =>
routes/common/jobs/get_document_payload.ts
routes/lib/get_counter.ts => routes/common/get_counter.ts
routes/lib/authorized_user_pre_routing.ts =>
routes/common/authorized_user_pre_routing.ts
routes/lib/get_user.ts => routes/common/get_user.ts
   ```

## Release Note
Updated API endpoint paths for Reporting to clarify which routes are
public and which are not. Make sure that any custom script or
application that uses Reporting endpoints only uses the public
endpoints.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:enhancement Team:SharedUX Platform AppEx-SharedUX (formerly Global Experience) t// v8.10.0 zDeprecated Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead

Projects

None yet

6 participants