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

Feature: add cache checking middleware and APISchema #151 #159

Closed

Conversation

onlyjackfrost
Copy link
Contributor

@onlyjackfrost onlyjackfrost commented Apr 11, 2023

Description

This pull request adds a new middleware to validate cache configurations defined in the .yaml file.

Validation logic:

  • if cache is used in .SQL file, but no cache configuration found in .yaml file, throw error.
  • if cache configuration is set, the refreshTime and refreshExpression can not exist at the same time.
  • the time interval(variable "every") in refreshTime and refreshExpression should be a valid string that can be parse by library "ms", throw Error if not valid.

Issue ticket number

issue #151

Additional Context

  • This PR does not include the validation of the variable "express" in refreshExpress and the indexes configuration.
  • the SQL defined in the .yaml file will be validated in another place(like SQL engine).

@vercel
Copy link

vercel bot commented Apr 11, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vulcan-sql-document ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 17, 2023 2:26am

@codecov-commenter
Copy link

codecov-commenter commented Apr 12, 2023

Codecov Report

Patch coverage: 97.91% and project coverage change: +0.05 🎉

Comparison is base (d80a255) 92.97% compared to head (3fd20a3) 93.02%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #159      +/-   ##
===========================================
+ Coverage    92.97%   93.02%   +0.05%     
===========================================
  Files          289      291       +2     
  Lines         4398     4444      +46     
  Branches       582      597      +15     
===========================================
+ Hits          4089     4134      +45     
  Misses         200      200              
- Partials       109      110       +1     
Flag Coverage Δ
build 95.20% <97.77%> (+0.18%) ⬆️
cli 89.38% <ø> (ø)
core 94.00% <100.00%> (+<0.01%) ⬆️
extension-dbt 97.43% <ø> (ø)
extension-debug-tools 98.11% <ø> (ø)
extension-driver-bq 85.21% <ø> (ø)
extension-driver-duckdb 100.00% <ø> (ø)
extension-driver-pg 96.11% <ø> (ø)
extension-driver-snowflake 94.59% <ø> (ø)
integration-testing 96.15% <ø> (ø)
serve 90.04% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ild/src/lib/schema-parser/middleware/checkCache.ts 97.43% <97.43%> (ø)
...d/src/lib/schema-parser/middleware/addParameter.ts 100.00% <100.00%> (ø)
...uild/src/lib/schema-parser/middleware/constants.ts 100.00% <100.00%> (ø)
...es/build/src/lib/schema-parser/middleware/index.ts 100.00% <100.00%> (ø)
packages/core/src/models/artifact.ts 91.66% <100.00%> (+0.75%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@onlyjackfrost onlyjackfrost changed the title [Draft] Feature: add cache checking middleware and APISchema #151 Feature: add cache checking middleware and APISchema #151 Apr 12, 2023
@onlyjackfrost onlyjackfrost requested a review from kokokuo April 12, 2023 03:12
Copy link
Contributor

@kokokuo kokokuo left a comment

Choose a reason for hiding this comment

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

Beside all comment suggestions, other is LGTM.

cacheTableName: 'test_cache',
sql: 'SELECT * FROM test_table',
refreshTime: { every: '5m' },
refreshExpression: { expression: '*/5,*,*,*,*', every: '5m' },
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest changing the value */5,*,*,*,* of "expression", because other members or new members often trace the test cases to understand the user case, when using non-relative values, it will make them confused, for example, the "expression" often use be a column value or the result from call SQL function.

Like the #151, description, the MAX(created_at) is used to get the created_at max value from the query result to check refreshes or not.

If not sure how to give the value in the test case, suggest figuring out the user scenario of #150 by discussion.

Otherwise, when writing test cases, we often use sinon to stub the value for the unnecessary part to make other members know what part is that we would like to focus on the test or use fake.js to fake the value.

Copy link
Contributor

@kokokuo kokokuo left a comment

Choose a reason for hiding this comment

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

There is a suggestion that seems you miss to fix, otherwise other fixed parts still have some minor suggestions, please check it :D

}
if (!isUsedCache && caches) {
throw new ConfigurationError(
`Can not configurate the cache setting in Schema ${schemas.urlPath}, {% cache %} tag not been used in SQL file.`
Copy link
Contributor

@kokokuo kokokuo Apr 17, 2023

Choose a reason for hiding this comment

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

  1. Misspelling for configurate, please update the word.

  2. After discussion although the ${schemas.urlPath} may be long and make the message not easy to read, we still keep it until the cases happened ( If happened, change to sourceName ).

  3. Otherwise, suggest adding the "..." in the ${schemas.sourceName} to highlight it, btw let us make the Schema to lowercase for consistency

// throw if cache not used in .sql file
if (isUsedCache && !caches) {
throw new ConfigurationError(
`{% cache %} tag was used in SQL file, but the cache configurations was not found in Schema ${schemas.urlPath}.`
Copy link
Contributor

@kokokuo kokokuo Apr 17, 2023

Choose a reason for hiding this comment

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

For the ${schemas.urlPath}, it's the same suggestion to add a double quote on it, btw let us make the Schema to lowercase for consistency

const { refreshTime, refreshExpression } = cache;
if (refreshTime && refreshExpression) {
throw new ConfigurationError(
`The cache ${cache.cacheTableName} of Schema ${schemas.urlPath} is invalid: Can not configure refreshTime and refreshExpression at the same time, please pick one`
Copy link
Contributor

@kokokuo kokokuo Apr 17, 2023

Choose a reason for hiding this comment

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

The error message is so long, suggest making it lighter,
e.g: Can not set "refreshTime" and "refreshExpression" at the same time in cache ${cache.cacheTableName} of schema ${schemas.urlPath}.

Comment on lines +36 to +55
// check "every" of "refreshTime" is valid
let every = refreshTime?.['every'];
if (every) {
const { isValid, error } = this.checkRefreshInterval(every);
if (!isValid) {
throw new ConfigurationError(
`The "every" of "refreshTime" in cache ${cache.cacheTableName} of schema ${schemas.urlPath} is invalid: ${error}`
);
}
}
// check "every" of "refreshExpression" is valid
every = refreshExpression?.['every'];
if (every) {
const { isValid, error } = this.checkRefreshInterval(every);
if (!isValid) {
throw new ConfigurationError(
`The "every" of "refreshExpression" in cache ${cache.cacheTableName} of schema ${schemas.urlPath} is invalid: ${error}`
);
}
}
Copy link
Contributor

@kokokuo kokokuo Apr 17, 2023

Choose a reason for hiding this comment

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

  1. This code is similar, could we refactor it by extracting it to a private method?

  2. The error message is better now ~ minor suggestion like above, add a double quote on ${schemas.urlPath},

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @onlyjackfrost have you missed the suggestion ?

@onlyjackfrost
Copy link
Contributor Author

Close this PR due to Github does not detect the latest commit.

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