refactor: use gritql for cdk and terraform metrics transforms#447
refactor: use gritql for cdk and terraform metrics transforms#447
Conversation
ef02aa6 to
57d8c26
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #447 +/- ##
==========================================
- Coverage 91.51% 91.47% -0.04%
==========================================
Files 86 86
Lines 2957 3016 +59
Branches 646 664 +18
==========================================
+ Hits 2706 2759 +53
- Misses 98 106 +8
+ Partials 153 151 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
044ec30 to
820c289
Compare
820c289 to
e0d7dc7
Compare
packages/nx-plugin/src/utils/ast.ts
Outdated
| // Exponential back-off: ~50ms, ~150ms, ~350ms | ||
| const delay = 50 * Math.pow(2, attempt) + Math.random() * 50; | ||
| const until = Date.now() + delay; | ||
| while (Date.now() < until) { |
There was a problem hiding this comment.
can we just do this with timeouts/sleep instead of busy wait?
await (new Promise(resolve => setTimeout(resolve, delay)))
There was a problem hiding this comment.
Yeah good shout! :)
| await applyGritQLTransform( | ||
| tree, | ||
| METRICS_ASPECT_FILE_PATH, | ||
| `\`const tags: string[] = $old\`` + |
There was a problem hiding this comment.
Just want to confirm this does the following:
- Will only work if within a metric aspect body (
where { ${WITHIN_METRICS_ASPECT},) - Will do nothing if it already contains the metric (
$old <: not contains \'${info.metric}'\) - Will set
$oldto[$info.metric]if$oldis[] - Will set
$oldto[$items, $info.metric]if$oldhas$items
There was a problem hiding this comment.
Yep that's right! :) <: reads as "matches". This is a bit harder to read than most gritql queries as the += is mutative. Unfortunately multi-line arrays with trailing commas break what I'd intuitively do:
const tags: string[] = [$items] => const tags: string[] = [$items, info.metric]
6c755b2 to
51c1dba
Compare
Use GritQL to transform the metrics aspect for cdk and metrics cloudformation stack for Terraform. GritQL is a query language for modifying source code and supports typescript, terraform and python, and so the intention is to gradually migrate our ast manipulation to use this instead so that we can perform python ast updates, and have a consistent way to do this regardless of language.
51c1dba to
f390b40
Compare
Reason for this change
GritQL is a query language for modifying source code and supports typescript, terraform and python, and so the intention is to gradually migrate our ast manipulation to use this instead so that we can perform python ast updates, and have a consistent way to do this regardless of language.
Description of changes
Use GritQL to transform the metrics aspect for cdk and metrics cloudformation stack for Terraform.
Also replace illegible ast construction code for cognito auth with readable gritql! :)
Currently, the only way we can invoke gritql is to wrap the cli, published to npm as
@getgrit/cli, but if biomejs/gritql#617 is merged we can switch to use napi bindings which is faster and more reliable - only napi bindings for mac are published right now so we can't use it yet unfortunately.Description of how you validated changes
Unit tests, integration tests
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license