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

[EBT] Schema-based event&context validation (only in dev mode) #132250

Closed
Tracked by #121992
afharo opened this issue May 16, 2022 · 2 comments · Fixed by #135061
Closed
Tracked by #121992

[EBT] Schema-based event&context validation (only in dev mode) #132250

afharo opened this issue May 16, 2022 · 2 comments · Fixed by #135061
Assignees
Labels
Feature:Telemetry Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc

Comments

@afharo
Copy link
Member

afharo commented May 16, 2022

When using the EBT APIs, developers need to call analytics.registerEventType({ eventType, schema }) and analytics.reportEvent(eventType, { ...eventProperties }).

This can cause a disconnection between the schema and the eventProperties that can lead to reporting unexpected data.

Let's add a schema-based validation step to throw when reporting an event that doesn't adhere to the schema specification (only when running in dev mode):

if (this.initContext.isDev) {
// TODO: In the future we may need to validate the eventData based on the eventType's registered schema (only if isDev)
}

We may use the schema_to_io-ts implementation from the POC: https://github.com/elastic/kibana/pull/95960/files#diff-5eda84ca820acad68804d4415017a209cc784672b6512871063b1f9134abc7e4

NOTE: While the analytics.registerContextProvider API is less prone to this error, we may want to add the same validation there:

if (this.isDevMode) {
// TODO: In the future we may need to validate the input of the context based on the schema (only if isDev)
}

@botelastic botelastic bot added the needs-team Issues missing a team label label May 16, 2022
@afharo afharo changed the title Schema-based event&context validation (only in dev mode) [EBT] Schema-based event&context validation (only in dev mode) May 16, 2022
@afharo afharo added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Feature:Telemetry labels May 16, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

@botelastic botelastic bot removed the needs-team Issues missing a team label label May 16, 2022
@afharo
Copy link
Member Author

afharo commented May 17, 2022

Dynamically import io-ts validation library so it's not actually loaded in production!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Telemetry Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants