-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Http] Added version header to unversioned, public routes #195464
[Http] Added version header to unversioned, public routes #195464
Conversation
Pinging @elastic/kibana-core (Team:Core) |
code: jest.fn().mockImplementation(() => mockResponse), | ||
header: jest.fn().mockImplementation(() => mockResponse), | ||
}; | ||
const mockResponseToolkit: any = { | ||
} as unknown as jest.Mocked<ResponseObject>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly better than any
, at least we can use a typed object in these tests
packages/core/http/core-http-router-server-internal/src/router.ts
Outdated
Show resolved
Hide resolved
).resolves.toMatchObject({ | ||
message: expect.stringMatching(/Invalid version/), | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced use of toEqual(expect.objectContaining({...
for more terse toMatchObject({...
API
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]
cc @jloleysens |
const [first, second] = mockResponse.header.mock.calls | ||
.concat() | ||
.sort(([k1], [k2]) => k1.localeCompare(k2)); | ||
expect(first).toEqual(['AAAA', 'test']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AAAAAAAA
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Starting backport for target branches: 8.x https://github.com/elastic/kibana/actions/runs/11259229795 |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
) (#195646) # Backport This will backport the following commits from `main` to `8.x`: - [[Http] Added version header to unversioned, public routes (#195464)](#195464) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Jean-Louis Leysens","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-09T16:33:54Z","message":"[Http] Added version header to unversioned, public routes (#195464)","sha":"61251bfdaffdb621558fff96d78cc8b2260c0abe","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:http","Team:Core","release_note:skip","v9.0.0","v8.16.0","backport:version"],"title":"[Http] Added version header to unversioned, public routes","number":195464,"url":"https://github.com/elastic/kibana/pull/195464","mergeCommit":{"message":"[Http] Added version header to unversioned, public routes (#195464)","sha":"61251bfdaffdb621558fff96d78cc8b2260c0abe"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195464","number":195464,"mergeCommit":{"message":"[Http] Added version header to unversioned, public routes (#195464)","sha":"61251bfdaffdb621558fff96d78cc8b2260c0abe"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Jean-Louis Leysens <[email protected]>
…#195940) ## Summary Follow up on #195464 Adds public route registrar option `httpResource` to distinguish API routes from routes intended to be used for loading resources, [for ex](https://github.com/elastic/kibana/blob/bd22f1370fc55179ea6f2737176570176f700b6e/x-pack/plugins/security/server/routes/authentication/oidc.ts#L36). This enables us to avoid returning the version header `elastic-api-version` for HTTP resource routes. It's still possible for API authors to use the versioned router for things that should be HTTP resources, but it's assumed that all routes registered through HTTP resources services are: 1. Public 2. Not versioned (focus of this PR) 3. Not documented (done in #192675) ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <[email protected]>
…elastic#195940) ## Summary Follow up on elastic#195464 Adds public route registrar option `httpResource` to distinguish API routes from routes intended to be used for loading resources, [for ex](https://github.com/elastic/kibana/blob/bd22f1370fc55179ea6f2737176570176f700b6e/x-pack/plugins/security/server/routes/authentication/oidc.ts#L36). This enables us to avoid returning the version header `elastic-api-version` for HTTP resource routes. It's still possible for API authors to use the versioned router for things that should be HTTP resources, but it's assumed that all routes registered through HTTP resources services are: 1. Public 2. Not versioned (focus of this PR) 3. Not documented (done in elastic#192675) ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <[email protected]> (cherry picked from commit 72f3d2d)
Summary
Close #190735
All unversioned, public routes, like versioned routes, will now include the following header in responses:
...when:
(1) The route produces a response from the handler (any status code)
(2) The route validation failed (400 bad request)
The header will not be included if we encounter a 500 or encounter some issue before reaching the router.
How to test
At time of PR
/api/stats
is not versioned, but public so useful to test with:Checklist