-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Implement HTTP API versioned types in usage collection plugin #152875
Implement HTTP API versioned types in usage collection plugin #152875
Conversation
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.
Did a quick review, let me know if that helps with the failed test!
const body: Stats.v1.StatsHTTPBodyTyped = { | ||
...kibanaStats, | ||
...extended, | ||
}; |
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.
🥳
const extendedClusterUuid = isLegacy ? { clusterUuid } : { cluster_uuid: clusterUuid }; | ||
extended = { | ||
usage: {}, | ||
extendedClusterUuid, |
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.
Do we need to spread this?
extendedClusterUuid, | |
...extendedClusterUuid, |
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.
ah, that makes sense! I'll give it a go.
|
||
let extended; | ||
if (isExtended) { | ||
const core = await context.core; | ||
const { asCurrentUser } = core.elasticsearch.client; | ||
// as of https://github.com/elastic/kibana/pull/151082, usage will always be an empty object. |
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.
Thanks for adding this comment!
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
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.
Exporting the types as aliased to the unversioned type definitions allows us to use:
Stats.v1.StatsHTTPBodyTyped
for example
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.
Self review with comments to reviewers
*/ | ||
|
||
/** | ||
* The types are exact duplicates of the ops metrics types declared in core needed for reporting in the stats api. |
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.
We're duplicating the types from core
so that we'll detect any changes to the original metrics.
}; | ||
} | ||
/** Stats response body */ | ||
export type StatsHTTPBodyTyped = LastOpsMetrics | KibanaStats | ExtendedStats; |
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.
explicitly declare (with appropriate types) the full response body from the stats
api
|
||
if (response.status !== 'ok') { | ||
const okStatus: UiCounters.v1.UiCountersResponseOk = response.status; | ||
if (response.status !== okStatus) { |
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.
The responses are hard-coded, depending on whether fetch
throws or not, so we declare separate types for each outcome.
const SNAPSHOT_REGEX = /-snapshot/i; | ||
|
||
interface UsageObject { |
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.
moved to v1
@@ -26,16 +27,22 @@ export function registerUiCountersRoute( | |||
}, | |||
}, | |||
async (context, req, res) => { | |||
const { report } = req.body; | |||
const requestBody: UiCounters.v1.UiCountersRequestBody = req.body; |
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.
The request needs to be fully versioned to accommodate future changes.
const bodyOk: UiCounters.v1.UiCountersResponseOk = { | ||
status: 'ok', | ||
}; | ||
return res.ok({ body: bodyOk }); |
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.
Explicitly type the hard-coded response.
@@ -5,13 +5,14 @@ | |||
* in compliance with, at your election, the Elastic License 2.0 or the Server | |||
* Side Public License, v 1. | |||
*/ | |||
import { UsageCounter, CounterMetric } from './usage_counter'; | |||
import { UsageCounter } from './usage_counter'; | |||
import type { UsageCounters } from '../../common/types'; |
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.
The type and implementation having the same name might not be appropriate. I'm open to renaming the type, if needed.
@elasticmachine merge upstream |
1 similar comment
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Public APIs missing exports
Page load bundle
Unknown metric groupsAPI count
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
Pinging @elastic/kibana-core (Team:Core) |
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.
Great work @TinaHeiligers !
…c#152875) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Similar to 152111 prepares usage collection plugin types for versioning
In this PR we ensure that we are adhering to the goals of versioned HTTP APIs to:
The types for the following HTTP API routes have been versioned:
Stats API
The stats route reports (along with other metrics), a subset of
cores'
OpsMetrics
. Since usage isn't included in the response anymore (ref #151082), we have a few options to allow us to detect changes to these metrics:stats
route to corepackages/core/metrics/core-metrics-server/index.ts
and rely on validation elsewhereThis PR takes the 4th approach: Use duplicates with explicitly declaring the full response body.
How to test this:
extended
andlegacy
queries:{basepath}/api/stats?extended&legacy
{basepath}/api/stats?extended
{basepath}/api/stats