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

Clean up TSVB turn Joi schema into kbn schema #65482

Merged
merged 5 commits into from
May 8, 2020

Conversation

DianaDerevyankina
Copy link
Contributor

Part of #57342

Summary

Changed Joi schema to @kbn/config-schema

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@DianaDerevyankina DianaDerevyankina added Feature:TSVB TSVB (Time Series Visual Builder) v8.0.0 labels May 6, 2020
@DianaDerevyankina DianaDerevyankina self-assigned this May 6, 2020
},
},
async (requestContext, request, response) => {
const { error: validationError } = visPayloadSchema.validate(request.body);
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for removing it. I like your idea of using official way for validating! 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

@dziyanadzeraviankina Unfortunately we can't remove this part just yet. The telemetry is reporting that there are still some problems left in the validation which means working tsvb visualizations would start to fail when we are rolling this out now. The plan is to let the "soft validation" currently in place running for at least another minor.

The new kbn/schema should be used in the same way the joi schema is used right now.

},
},
async (requestContext, request, response) => {
const { error: validationError } = visPayloadSchema.validate(request.body);
Copy link
Contributor

Choose a reason for hiding this comment

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

@dziyanadzeraviankina Unfortunately we can't remove this part just yet. The telemetry is reporting that there are still some problems left in the validation which means working tsvb visualizations would start to fail when we are rolling this out now. The plan is to let the "soft validation" currently in place running for at least another minor.

The new kbn/schema should be used in the same way the joi schema is used right now.

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

Tested and still works fine for both error case and regular case. However I noticed a few differences between the Joi schema and the kbn/schema definition (see comments in the code)

import { schema } from '@kbn/config-schema';
import { TypeOptions } from '@kbn/config-schema/target/types/types';

const stringOptionalNullable = schema.nullable(schema.string());
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this should be schema.maybe(schema.nullable(schema.string()));

The current schema just gives string | null.

.allow(null)
.optional(),
const backgroundColorRulesItems = schema.object({
value: schema.nullable(schema.number()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this needs a schema.maybe wrapper as well - in the Joi schema this was optional.

.items(Joi.string().allow('', null))
.allow(null)
.optional(),
values: schema.nullable(schema.arrayOf(schema.nullable(schema.string()))),
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

}).required(),
savedObjectId: Joi.string().optional(),
timerange: Joi.object({
query: schema.maybe(schema.arrayOf(schema.nullable(queryObject))),
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the query is required, so the maybe should be removed here. Also when I'm reading the Joi schema correctly, query is allowed to be null, not the items within the array. That's not the same thing, Joi would allow query: null but fail on query: [null] while the new version would do the exact opposite.

So it should be schema.nullable(schema.arrayOf(queryObject))

@kibanamachine
Copy link
Contributor

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

LGTM once green, didn't run the code again.

Copy link
Contributor

@alexwizp alexwizp left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you

@DianaDerevyankina DianaDerevyankina marked this pull request as ready for review May 8, 2020 09:29
@DianaDerevyankina DianaDerevyankina requested a review from a team May 8, 2020 09:29
@DianaDerevyankina DianaDerevyankina added v7.9.0 release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure labels May 8, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@DianaDerevyankina DianaDerevyankina merged commit ef58a90 into elastic:master May 8, 2020
DianaDerevyankina added a commit to DianaDerevyankina/kibana that referenced this pull request May 8, 2020
* Clean up TSVB turn Joi schema into kbn schema

Part of elastic#57342

* Return validationTelemerty and logging part back

* Add schema.maybe() where it was missed
DianaDerevyankina added a commit that referenced this pull request May 8, 2020
* Clean up TSVB turn Joi schema into kbn schema

Part of #57342

* Return validationTelemerty and logging part back

* Add schema.maybe() where it was missed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:TSVB TSVB (Time Series Visual Builder) release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.9.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants