Skip to content

feat(config): Warn when undefined environments or groups are used in overrides #1880

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

Merged
merged 1 commit into from
May 28, 2025

Conversation

arthurpitman
Copy link
Contributor

@arthurpitman arthurpitman commented May 8, 2025

Why this PR?

When copying and pasting configs between projects, it is easy to forget to update any overrides. Currently, this is silent: the overrides simply have no effect, which can have undesirable consequences.

What has changed?

With this PR, a warning is emitted when an override references an environment or environment group that is not defined in the manifest.

A decision was made not to emit an error, at least for now, as this would be a breaking change.

How does it do it?

This PR builds on #1897, which adds the names of all environments and groups to the loaded manifest, regardless of whether they're selected to be deployed or not.

In this PR, when a config entry is loaded, the environment or group name of each override is checked against those in the manifest.

How is it tested?

  • Existing tests are updated
  • Two extra tests are added to that explicitly check that warnings are logged:
    • TestLoadProjects_GroupOverrideWithUndefinedGroupProducesWarning
    • TestLoadProjects_EnvironmentOverrideWithUndefinedEnvironmentProducesWarning

How does it affect users?

Users will now receive a warning when an override references an environment or environment group that is not defined in the manifest.

@arthurpitman arthurpitman force-pushed the feat/warn-for-undefined-environments branch from e234621 to 8e0024b Compare May 8, 2025 15:45
@arthurpitman arthurpitman added the run-e2e-test Manually trigger the E2E tests for reviewed PRs label May 8, 2025
Copy link

github-actions bot commented May 8, 2025

E2E Test Results

    3 files  ± 0    263 suites  ±0   25m 30s ⏱️ + 2m 57s
2 151 tests  - 23  2 134 ✅  - 34  2 💤 ±0  15 ❌ +11 
2 381 runs   - 24  2 364 ✅  - 35  2 💤 ±0  15 ❌ +11 

For more details on these failures, see this check.

Results for commit 92c2c3b. ± Comparison against base commit 784755a.

This pull request removes 26 and adds 3 tests. Note that renamed tests count towards both.
github.com/dynatrace/dynatrace-configuration-as-code/v2/cmd/monaco/integrationtest/v2 ‑ TestDeployReport
github.com/dynatrace/dynatrace-configuration-as-code/v2/cmd/monaco/integrationtest/v2 ‑ TestDeployReport/ensure_that_monaco_runs_without_generating_report
github.com/dynatrace/dynatrace-configuration-as-code/v2/cmd/monaco/integrationtest/v2 ‑ TestDeployReport/report_is_generated
github.com/dynatrace/dynatrace-configuration-as-code/v2/cmd/monaco/integrationtest/v2 ‑ TestMonacoVersionLogging
github.com/dynatrace/dynatrace-configuration-as-code/v2/cmd/monaco/integrationtest/v2 ‑ TestMonacoVersionLogging/Account_deploy_should_log_version
github.com/dynatrace/dynatrace-configuration-as-code/v2/cmd/monaco/integrationtest/v2 ‑ TestMonacoVersionLogging/Account_download_should_log_version
github.com/dynatrace/dynatrace-configuration-as-code/v2/cmd/monaco/integrationtest/v2 ‑ TestMonacoVersionLogging/Deploy_should_log_version
github.com/dynatrace/dynatrace-configuration-as-code/v2/cmd/monaco/integrationtest/v2 ‑ TestMonacoVersionLogging/Download_should_log_version
github.com/dynatrace/dynatrace-configuration-as-code/v2/cmd/monaco/integrationtest/v2 ‑ TestMonacoVersionLogging/Help_should_not_log_version
github.com/dynatrace/dynatrace-configuration-as-code/v2/cmd/monaco/integrationtest/v2 ‑ TestMonacoVersionLogging/Incomplete_account_should_not_log_version
…
TestMain
github.com/dynatrace/dynatrace-configuration-as-code/v2/pkg/project ‑ TestLoadProjects_EnvironmentOverrideWithUndefinedEnvironmentProducesWarning
github.com/dynatrace/dynatrace-configuration-as-code/v2/pkg/project ‑ TestLoadProjects_GroupOverrideWithUndefinedGroupProducesWarning

♻️ This comment has been updated with latest results.

@arthurpitman arthurpitman changed the title Feat/warn for undefined environments feat(config): Warn when undefined environments or groups are used in overrides May 9, 2025
@arthurpitman arthurpitman marked this pull request as ready for review May 9, 2025 07:29
@arthurpitman arthurpitman requested a review from a team as a code owner May 9, 2025 07:29
@arthurpitman arthurpitman force-pushed the feat/manifest-loads-all-environments branch 2 times, most recently from 8505894 to b19958e Compare May 12, 2025 07:11
@arthurpitman arthurpitman force-pushed the feat/warn-for-undefined-environments branch from 8e0024b to 11c3d15 Compare May 12, 2025 07:18
@@ -55,7 +56,19 @@ func parseConfigEntry(
return nil, []error{newDefinitionParserError(configId, singleConfigContext, err.Error())}
}

for _, group := range definition.GroupOverrides {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move each check into a separate function to decrease the complexity and have an opportunity to comment on what is checked under which assumption.

My opinion you decide if it makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have also improved the actual log message.

@arthurpitman arthurpitman force-pushed the feat/warn-for-undefined-environments branch from 11c3d15 to c66b269 Compare May 21, 2025 12:49
@arthurpitman arthurpitman changed the base branch from feat/manifest-loads-all-environments to main May 21, 2025 12:49
@arthurpitman arthurpitman force-pushed the feat/warn-for-undefined-environments branch from c66b269 to 70134f1 Compare May 21, 2025 12:50
@arthurpitman arthurpitman added run-e2e-test Manually trigger the E2E tests for reviewed PRs and removed run-e2e-test Manually trigger the E2E tests for reviewed PRs labels May 21, 2025
@arthurpitman arthurpitman force-pushed the feat/warn-for-undefined-environments branch from 70134f1 to 92c2c3b Compare May 21, 2025 13:13
@arthurpitman arthurpitman added run-e2e-test Manually trigger the E2E tests for reviewed PRs and removed run-e2e-test Manually trigger the E2E tests for reviewed PRs labels May 21, 2025
@arthurpitman arthurpitman force-pushed the feat/warn-for-undefined-environments branch from 92c2c3b to 8317a0b Compare May 22, 2025 16:03
@arthurpitman arthurpitman force-pushed the feat/warn-for-undefined-environments branch from 8317a0b to 0b08984 Compare May 26, 2025 07:50
Copy link

@arthurpitman arthurpitman merged commit 54bf33c into main May 28, 2025
10 checks passed
@arthurpitman arthurpitman deleted the feat/warn-for-undefined-environments branch May 28, 2025 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-e2e-test Manually trigger the E2E tests for reviewed PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants