Implement HTTP API versioned types in usage collection plugin#152875
Implement HTTP API versioned types in usage collection plugin#152875TinaHeiligers merged 6 commits intoelastic:mainfrom
Conversation
jloleysens
left a comment
There was a problem hiding this comment.
Did a quick review, let me know if that helps with the failed test!
| const body: Stats.v1.StatsHTTPBodyTyped = { | ||
| ...kibanaStats, | ||
| ...extended, | ||
| }; |
| const extendedClusterUuid = isLegacy ? { clusterUuid } : { cluster_uuid: clusterUuid }; | ||
| extended = { | ||
| usage: {}, | ||
| extendedClusterUuid, |
There was a problem hiding this comment.
Do we need to spread this?
| extendedClusterUuid, | |
| ...extendedClusterUuid, |
There was a problem hiding this comment.
ah, that makes sense! I'll give it a go.
| 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.
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.
Exporting the types as aliased to the unversioned type definitions allows us to use:
Stats.v1.StatsHTTPBodyTyped for example
TinaHeiligers
left a comment
There was a problem hiding this comment.
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.
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.
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.
The responses are hard-coded, depending on whether fetch throws or not, so we declare separate types for each outcome.
| import { Stats } from '../../../common/types'; | ||
| const SNAPSHOT_REGEX = /-snapshot/i; | ||
|
|
||
| interface UsageObject { |
| }, | ||
| async (context, req, res) => { | ||
| const { report } = req.body; | ||
| const requestBody: UiCounters.v1.UiCountersRequestBody = req.body; |
There was a problem hiding this comment.
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.
Explicitly type the hard-coded response.
| */ | ||
| import { UsageCounter, CounterMetric } from './usage_counter'; | ||
| import { UsageCounter } from './usage_counter'; | ||
| import type { UsageCounters } from '../../common/types'; |
There was a problem hiding this comment.
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) |
jloleysens
left a comment
There was a problem hiding this comment.
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:statsroute to corepackages/core/metrics/core-metrics-server/index.tsand rely on validation elsewhereThis PR takes the 4th approach: Use duplicates with explicitly declaring the full response body.
How to test this:
extendedandlegacyqueries:{basepath}/api/stats?extended&legacy{basepath}/api/stats?extended{basepath}/api/stats