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

14110: add validation service #14388

Merged
merged 7 commits into from
May 16, 2024
Merged

Conversation

jalbinson
Copy link
Collaborator

@jalbinson jalbinson commented May 13, 2024

This PR adds a validation service that handles both json schema structure validation as well as value validation for filter definitions.

Test Steps:

  1. ./gradlew test

Changes

  • Added type for validation success/failure
  • Updated json schema validation service to use these new types
  • Added service for value validation
  • Added service to bring together json schema and value validation
  • unit tests for all of the above

Checklist

Testing

  • Tested locally?
  • Ran ./prime test or ./gradlew testSmoke against local Docker ReportStream container?
  • Added tests?

Linked Issues

@jalbinson jalbinson requested a review from a team as a code owner May 13, 2024 19:10
@jalbinson jalbinson added the platform Platform Team label May 13, 2024
Copy link

github-actions bot commented May 13, 2024

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Manifest Files

@jalbinson jalbinson requested a deployment to staging May 13, 2024 19:10 — with GitHub Actions Abandoned
Copy link

github-actions bot commented May 13, 2024

Test Results

1 180 tests  +8   1 176 ✅ +8   7m 9s ⏱️ +13s
  149 suites +2       4 💤 ±0 
  149 files   +2       0 ❌ ±0 

Results for commit 70d7c6b. ± Comparison against base commit cb615dc.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented May 13, 2024

Integration Test Results

 62 files   62 suites   33m 35s ⏱️
394 tests 384 ✅ 10 💤 0 ❌
397 runs  387 ✅ 10 💤 0 ❌

Results for commit 70d7c6b.

♻️ This comment has been updated with latest results.

ConfigurationValueValidationServiceImpl(),
) : ConfigurationValidationService {

override fun <T> validateYAML(configType: ConfigurationType<T>, file: File): ConfigurationValidationResult<T> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might answer this question myself by the time I'm done looking at the code: Why do we need to overload the validateYAML to take in different input types (same goes for the other files with similar method overloading)? If we're controlling the validation point shouldn't we just need one?

If we do need them, it would be good to have some unit tests for them too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I overloaded it because I wanted to use some simple strings in the tests.

I also wanted to use some shared logic between both files and strings and found that input streams would let me handle both the same way.

/**
* A configration type containing all necessary data to parse and validate a YAML file
*/
sealed class ConfigurationType<T> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

First time I've come across a "sealed" class. I read this but if you have a second to huddle I'd be interested in hearing more about it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sealed classes and interfaces are great when you want to know all your implementing/subclasses at runtime. Its useful in this case because I want to define the possible configuration types and include a generic type, vals, and functions along with each configuration type. I'm using it in a very "enum" way.

ConfigurationValidationFailure(schemaErrors)
}
} catch (ex: Exception) {
ConfigurationValidationFailure(schemaErrors, ex)
Copy link
Collaborator

Choose a reason for hiding this comment

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

When these ConfigurationValidationFailure data classes are being created, is anything happening to them? Or is all the logging/output going to happen in a later PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right now this isn't hooked up to anything (besides unit tests). I'll be using it as a part of 14158 (CLI task).

val jsonSchemaValidation = jsonSchemaValidationService.validateYAMLStructure(configType, inputStream)
) {
is ConfigurationValidationSuccess -> {
configurationValueValidationService.validate(configType, jsonSchemaValidation.parsed)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just want to make sure I understand the workflow happening here.

First the ConfigurationValidationService is called.
This calls the JsonSchemaValidationService, which validates the structure of the YAML file?
And if that passes it then calls the ConfigurationValueValidationService, which validates that the filters are valid?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup thats correct

  1. validate against json schema
  2. parse with jackson into class
  3. validate with konform
  4. return success/failure

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

side note: if step 1 fails it will short circuit to a failure (since we can't validate values if we cant even parse something into a type)

}

@Test
fun organizations() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Love the idea of testing this in the unit tests

@JFisk42
Copy link
Collaborator

JFisk42 commented May 14, 2024

Forgot to add that I did pull the branch down and tests passed locally for me 👍

Copy link
Collaborator

@arnejduranovic arnejduranovic left a comment

Choose a reason for hiding this comment

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

Great use of interfaces!

Copy link

sonarcloud bot commented May 16, 2024

@jalbinson jalbinson merged commit eab7c83 into master May 16, 2024
16 checks passed
@jalbinson jalbinson deleted the platform/jamie/14110-validation-service branch May 16, 2024 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform Platform Team
Projects
Development

Successfully merging this pull request may close these issues.

Create Validation Service to validate organizations
3 participants