Skip to content

feat(manifest): loader.Load(...) includes unselected environments as skipped with Skip: true #1876

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

arthurpitman
Copy link
Contributor

@arthurpitman arthurpitman commented May 6, 2025

Why this PR?

In order to be able to check environment and group overrides in project.LoadProjects(...), something that will be done in a follow up PR, the loaded manifest needs to contain at least the names of all environment and groups, and not just those selected to be deployed or deleted.

What has changed?

An additional field, Skip is added to manifest.EnvironmentDefinition:

  • With Skip set to false, the environment should be used as previously; it is not skipped and therefore is selected for deployment or deletion.
  • With Skip set to true, the environment is loaded within its group, but is not selected for deployment or deletion. Such an environment won't have its URL or credentials resolved.

How does it do it?

  • loader.Load(...) now loads all environments defined in the manifest, setting the Skip field appropriately.
  • Small changes are made to dynatrace.VerifyEnvironmentGeneration(...), dynatrace.CreateEnvironmentClients(...), project.toEnvironmentSlice(...) to make them skip non-Enabled environments.

How is it tested?

  • Existing tests are updated, predominantly to add the Skip: true for environments that should be skipped.
  • Two new tests are added: TestLoadConfigFile_ConfigsGeneratedForNonSkippedEnvironments and TestLoadConfigFile_NoConfigsGeneratedForSkippedEnvironments

How does it affect users?

It has no effect on users.

@arthurpitman arthurpitman added the run-e2e-test Manually trigger the E2E tests for reviewed PRs label May 6, 2025
Copy link

github-actions bot commented May 6, 2025

E2E Test Results

    3 files  ±0    261 suites  ±0   23m 26s ⏱️ + 1m 32s
2 156 tests ±0  2 154 ✅ +2  2 💤 ±0  0 ❌  - 2 
2 363 runs  ±0  2 361 ✅ +2  2 💤 ±0  0 ❌  - 2 

Results for commit 788ac03. ± Comparison against base commit 8c61c24.

♻️ This comment has been updated with latest results.

@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 7, 2025
@arthurpitman arthurpitman force-pushed the feat/manifest-loads-all-environments branch 2 times, most recently from 3af64be to a7dc9ee Compare May 7, 2025 06:39
@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 7, 2025
@arthurpitman arthurpitman force-pushed the feat/manifest-loads-all-environments branch from 28bf0d7 to a8add41 Compare May 7, 2025 07:10
@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 7, 2025
@arthurpitman arthurpitman force-pushed the feat/manifest-loads-all-environments branch from a8add41 to 788ac03 Compare May 7, 2025 09:48
@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 7, 2025
@arthurpitman arthurpitman changed the title feat: manifest.Load(...) includes unselected environments as not enabled environments with Enabled: false feat(manifest): loader.Load(...) includes unselected environments as not enabled environments with Enabled: false May 8, 2025
@arthurpitman arthurpitman force-pushed the feat/manifest-loads-all-environments branch from 788ac03 to 469fd7b Compare May 8, 2025 07:04
@arthurpitman
Copy link
Contributor Author

arthurpitman commented May 8, 2025

I'm pretty satisfied that E2E tests are working with this change, although I've been unable to get them all green in one run here.

@arthurpitman arthurpitman marked this pull request as ready for review May 8, 2025 07:09
@arthurpitman arthurpitman requested a review from a team as a code owner May 8, 2025 07:09
@arthurpitman arthurpitman force-pushed the feat/manifest-loads-all-environments branch 2 times, most recently from 8018745 to 98d9536 Compare May 8, 2025 14:43
@Kirdock
Copy link
Contributor

Kirdock commented May 9, 2025

At the moment, we have a small behavior change here
https://github.com/Dynatrace/dynatrace-configuration-as-code/pull/1876/files#diff-f0178ccba6ea85e4b333a9ba0913163f69960f5361186b218cab7b25d5936d1cR188
If all definitions are skipped, it resulted in an error before.

Here is also a behavior change, right?

undefinedEnvironments[envName] = struct{}{}

Previously, it was marked as an undefined environment

Not sure about this though

projectNamesToLoad = append(projectNamesToLoad, project.Dependencies[environment.Name]...)

Anyway, it would be nice if @Laubi or @tomazpu could also have a look, as this touches a lot of places :)

if shouldSkipEnv(context, group, env) {
log.WithFields(field.F("manifestPath", context.ManifestPath)).Debug("skipping loading of environment %q", env.Name)
environments[env.Name] = manifest.EnvironmentDefinition{Enabled: false, Name: env.Name, Group: group.Name}
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit]: When looking at this, Skip would fit a bit better. We're using Skip for configs, and the condition and logs for excluding this environment are also "skip".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So Skip: true would mean "don't use this environment"? I like that idea 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

@arthurpitman arthurpitman force-pushed the feat/manifest-loads-all-environments branch from 98d9536 to 26ef6c4 Compare May 9, 2025 10:03
@arthurpitman
Copy link
Contributor Author

@Kirdock, you're correct: we need to clarify what the expected behavior is. The code:

_, found := envs[envName]
if !found {
undefinedEnvironments[envName] = struct{}{}
continue
}

doesn't really work as configs are only created for environments in the loaded manifest, which means no configs will violate this. There is even a test for this:

t.Run("undefined environment in project fails", func(t *testing.T) {
err := validateProjectsWithEnvironments(
t.Context(),
[]project.Project{
{
Id: project1Id,
Configs: project.ConfigsPerTypePerEnvironments{
"unknown_env": project.ConfigsPerType{},
},
},
},
manifest.Environments{
env1Id: env1Definition,
})
assert.ErrorContains(t, err, "undefined environment")
})

@arthurpitman
Copy link
Contributor Author

In response to sonarqubecloud, I'll increase test coverage, particularly around loader.LoadConfigFile(...).

…s not enabled environments with `Enabled: false`

In order to be able to check environment and group overrides in `project.LoadProject(...)` they need not to be removed in `loader.Load(...)`. Instead, this function marks them as not enabled, with `Enabled: false`.
…t no configs are loaded for environments with `Skip: true`
@arthurpitman arthurpitman force-pushed the feat/manifest-loads-all-environments branch from 8505894 to b19958e Compare May 12, 2025 07:11
@d0weinberger d0weinberger requested a review from Laubi May 12, 2025 07:43
@arthurpitman arthurpitman changed the title feat(manifest): loader.Load(...) includes unselected environments as not enabled environments with Enabled: false feat(manifest): loader.Load(...) includes unselected environments as skipped with Skip: true May 14, 2025
@@ -38,6 +38,9 @@ import (
func Delete(ctx context.Context, environments manifest.Environments, entriesToDelete delete.DeleteEntries) error {
var envsWithDeleteErrs []string
for _, env := range environments {
if env.Skip {
Copy link
Contributor

Choose a reason for hiding this comment

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

We now have a lot of these env.Skip checks (7), and I am thinking if it would be possible to not even pass them into the consuming functions, aka filter them beforehand.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering the same. Would it be possible to add to the Manifest struct something like a getter method where only active Environments are returned?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a fair point - let's do this!

I just tried with an iterator, but it doesn't really solve the problem: defining it on the Manifest would require changing many function signatures (including this one), definition it on manifest.Environments doesn't improve the problem, as you could still forget to use it. So I think I'll go for an actual getter on the Manifest that does the filtering when called.

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 didn't like how this looked, so have tried something different: #1897

@arthurpitman
Copy link
Contributor Author

Based on feedback, I've gone ahead and tried this in a different way: #1897

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