Skip to content

fix: Ignore env variables in comments#625

Merged
kodiakhq[bot] merged 2 commits intomainfrom
fix-variable-expansion
Jan 26, 2023
Merged

fix: Ignore env variables in comments#625
kodiakhq[bot] merged 2 commits intomainfrom
fix-variable-expansion

Conversation

@hermanschaaf
Copy link
Copy Markdown
Contributor

@hermanschaaf hermanschaaf commented Jan 25, 2023

This changes the yaml config parsing code to ignore comments entirely. The solution used here is relatively short and clean, but it required some unfortunate hacking because the curly brackets we use for env variable placeholders are not valid yaml, and so any attempt to parse the yaml with them still in place fails (unless we were to write our own parser).

Simple regex replacement of comments would also be prone to issues, because it wouldn't be aware of the context (maybe the # is inside a string, for example). This solution replaces the variables with temporary placeholders, converts each yaml section to json and back to yaml to strip comments, and then replaces the temporary placeholders again before continuing as before.

@github-actions
Copy link
Copy Markdown

⏱️ Benchmark results

Comparing with 281e706

  • DefaultConcurrencyDFS-2 resources/s: 9,993 ⬇️ 9.17% decrease vs. 281e706
  • DefaultConcurrencyRoundRobin-2 resources/s: 12,166 ⬇️ 1.15% decrease vs. 281e706
  • Glob-2 ns/op: 172 ⬇️ 40.52% decrease vs. 281e706
  • TablesWithChildrenDFS-2 resources/s: 29,888 ⬆️ 16.25% increase vs. 281e706
  • TablesWithChildrenRoundRobin-2 resources/s: 30,111 ⬆️ 11.55% increase vs. 281e706
  • TablesWithRateLimitingDFS-2 resources/s: 28.23 ⬇️ 0.14% decrease vs. 281e706
  • TablesWithRateLimitingRoundRobin-2 resources/s: 823.8 ⬆️ 0.21% increase vs. 281e706
  • BufferedScanner-2 ns/op: 9.299 ⬇️ 25.60% decrease vs. 281e706
  • LogReader-2 ns/op: 31.16 ⬇️ 20.80% decrease vs. 281e706

Copy link
Copy Markdown
Member

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

Approving and
giphy (1)

return nil, fmt.Errorf("%s and %s are reserved words in CloudQuery config", openPlaceholder, closePlaceholder)
}

// replace placeholder variables with valid yaml, otherwise it cannot be parsed
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

GitHub wrote their own YAML parser. We should not do it https://github.com/cloudquery/plugin-sdk/issues/480#issuecomment-1404694684

@github-actions github-actions bot added fix and removed fix labels Jan 26, 2023
@kodiakhq kodiakhq bot merged commit 08bace8 into main Jan 26, 2023
@kodiakhq kodiakhq bot deleted the fix-variable-expansion branch January 26, 2023 12:50
kodiakhq bot pushed a commit that referenced this pull request Jan 26, 2023
🤖 I have created a release *beep* *boop*
---


## [1.30.0](v1.29.0...v1.30.0) (2023-01-26)


### Features

* **destination:** Filter the duplicate primary keys prior to writing batch ([#629](#629)) ([505709e](505709e)), closes [#627](#627)


### Bug Fixes

* Ignore env variables in comments ([#625](#625)) ([08bace8](08bace8))
* Only call `newExecutionClient` if needed ([#630](#630)) ([ece947f](ece947f))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug(env-expanding): Commented env variables should not be expanded

4 participants