Skip to content
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

Prepares usage-collection plugin for versioned HTTP APIs #152770

Conversation

TinaHeiligers
Copy link
Contributor

@TinaHeiligers TinaHeiligers commented Mar 7, 2023

WIP: for discussion only.

stats

The stats route reports metrics from core's Metrics service. However, as-is, these metrics are assumed as unknowns, meaning any subsequent change to what is reported is passed through.
One of the requirements for versioned APIs is to explicitly declare (with appropriate types) the response.

As such, there are a few approaches we could take:

  1. Assume the API response is validated elsewhere (and run the risk of not detecting potential issues for consumers)
  2. Duplicate the types from Core
  3. Move the stats api directly to core's metrics service (or somewhere more appropriate)
  4. something else?

This draft PR creates a copy of the OpsMetrics and explicitly types the response using the copy.

usage_counters

There isn't an explicit HTTP API for these, so I'm not sure if versioning the saved object is needed right now.
However, the usage_counters_service reports these metrics through a browser-side API.

Summary

Summarize your PR. If it involves visual changes include a screenshot or gif.

Checklist

Delete any items that are not applicable to this PR.

Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.

When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:

Risk Probability Severity Mitigation/Notes
Multiple Spaces—unexpected behavior in non-default Kibana Space. Low High Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces.
Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. High Low Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure.
Code should gracefully handle cases when feature X or plugin Y are disabled. Medium High Unit tests will verify that any feature flag or plugin combination still results in our service operational.
See more potential risk examples

For maintainers

@TinaHeiligers TinaHeiligers requested a review from jloleysens March 7, 2023 00:22
@TinaHeiligers TinaHeiligers force-pushed the usage-collection-explicitly-type-all-apis branch from 2b04505 to aae570b Compare March 7, 2023 01:51
@TinaHeiligers
Copy link
Contributor Author

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

kibana-ci commented Mar 7, 2023

💔 Build Failed

Failed CI Steps

Metrics [docs]

‼️ ERROR: metrics for d16c068 were not reported

History

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

Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

Overall this is looking great @TinaHeiligers ! Happy with the direction to provide full typings for the response as that gives the strongest guarantees for adhering to versioning. I'll finish my review on another pass. Let me know what you think!

@@ -0,0 +1,207 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Overall this makes sense, it is giving us the full types of the endpoint and we will be able to detect when our response changes👌🏻

Nit: I would name this file "core_metrics" then add a doc comment explaining this starts as a duplicate of the core ops metrics.

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const response = await fetch.post<any>('/api/ui_counters/_report', {
body: JSON.stringify({ report }),
asSystemRequest: true,
});

if (response.status !== 'ok') {
const okStatus: v1.UiCountersResponseOk = response.status;
Copy link
Contributor

Choose a reason for hiding this comment

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

👌🏻

@@ -43,5 +43,6 @@ export const reportSchema = schema.object({
application_usage: schema.maybe(schema.recordOf(schema.string(), applicationUsageReportSchema)),
});

// should the schema types also be versioned explicitly?
Copy link
Contributor

Choose a reason for hiding this comment

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

Good question, for now I think it is OK not to. But it would be consistent with our types. I could go either way on this one 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or now I think it is OK not to

Cool! I'm going with that :-)

@TinaHeiligers
Copy link
Contributor Author

Closing in favor of #152875

@TinaHeiligers TinaHeiligers deleted the usage-collection-explicitly-type-all-apis branch March 8, 2023 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants