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

Reduce diff spam and unset defaults #65

Merged
merged 8 commits into from
Jun 16, 2020

Conversation

dekimsey
Copy link
Contributor

Currently when the terraform plan is generated, there is a great deal of spurious noise from default values being re-set to null. This change alters how the JSON is being generated such that null entries are dropped entirely from the resultant task specification. It's not perfect, as there are some complex entries that have keys set as a result of the type system (logConfiguration for instance). But it does significantly reduce the noise in the delta.

Additionally, this drops all default values that don't correspond.

Before a plan might look like:

                { 
                  ....
                    portMappings           = []
                  + privileged             = null
                    readonlyRootFilesystem = false
                  + repositoryCredentials  = null
                  + secrets                = null
                    startTimeout           = 120
                    stopTimeout            = 30
                  + systemControls         = null
                  + ulimits                = null
                  + user                   = null
                  ~ volumesFrom            = [] -> null
                  + workingDirectory       = null
                } # forces replacement,

After:

              ~ {
                  - cpu                    = 0 -> null
                  ~ environment            = [
                      ~ {
                            name  = "CT_LOCAL_CONFIG"
                          ~ value = <<~EOT
                                log_level = "debug"

                              - telemetry {
                              -   prometheus {
                              -     reporting_interval = "60s"
                              -     port = 8888
                              -   }
                              - }
                              -
                            EOT
                        },
                    ]
                  ~ logConfiguration       = {
                        logDriver     = "awslogs"
                        options       = {
                            awslogs-group         = "stg"
                            awslogs-region        = "us-east-2"
                            awslogs-stream-prefix = "app"
                        }
                      + secretOptions = null
                    }
                    name                   = "config"
                    portMappings           = []
                    readonlyRootFilesystem = false
                    startTimeout           = 30
                    stopTimeout            = 30
                    user                   = "root"
                    volumesFrom            = []
                } # forces replacement,

Which is significantly reduced change noise. There are a few places it's still happening due to the sub-dictionary keys. I'm not sure if I want to go bother trying to address those.

@jtdoepke
Copy link
Contributor

Couldn't this be done with a for-loop?

container_definition_without_null = {
  for k, v in container_definition :
  k => v
  if v != null
}

@dekimsey
Copy link
Contributor Author

Maybe, I hadn't considered it. I'll give it a try though. I like the idea.

The sub-maps are still somewhat problematic, but I didn't have any good ideas on how to address those.

@aknysh
Copy link
Member

aknysh commented May 30, 2020

@dekimsey please rebase

@dekimsey
Copy link
Contributor Author

dekimsey commented Jun 4, 2020

@jtdoepke Your recommendation is on point, much saner change.

And at least for Fargate tasks, due the key validation we are doing in the module, there's still some diff noise (see below) It's possible when the new validation rules become mainstream, this could be tweaked again to improve output.

I wanted to play with it some more, but I feared it might behave differently on Fargate vs ECS task deltas and I don't have any good tests for that.

So right now, we still see some delta spam:

# Only hostPort is not valid to be set, but validation requires we set one (setting to explict null results in this diff)
                  ~ portMappings           = [
                      ~ {
                            containerPort = 8301
                          ~ hostPort      = 8301 -> null
                            protocol      = "tcp"
                        },
                    ]
# Only initProcessEnabled is valid, but the validation requires all keys.
                  ~ linuxParameters        = {
                      + capabilities       = null
                      + devices            = null
                        initProcessEnabled = true
                      + maxSwap            = null
                      + sharedMemorySize   = null
                      + swappiness         = null
                      + tmpfs              = null
                    }
# defaults when unset appears to be empty lists instead
                  - mountPoints            = [] -> null
                  - environment            = [] -> null

@Gowiem
Copy link
Member

Gowiem commented Jun 14, 2020

/test all

@Gowiem Gowiem requested review from aknysh and Gowiem June 14, 2020 17:02
@Gowiem
Copy link
Member

Gowiem commented Jun 14, 2020

/rebuild-readme

@Gowiem
Copy link
Member

Gowiem commented Jun 14, 2020

/test all

@nitrocode nitrocode self-requested a review June 15, 2020 22:03
nitrocode
nitrocode previously approved these changes Jun 15, 2020
@nitrocode
Copy link
Member

/test all

@nitrocode
Copy link
Member

/rebuild-readme

@nitrocode
Copy link
Member

/test all

@nitrocode
Copy link
Member

/rebuild-readme

@nitrocode
Copy link
Member

/test all

Copy link
Member

@nitrocode nitrocode left a comment

Choose a reason for hiding this comment

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

lgtm

@nitrocode nitrocode merged commit 4f5e998 into cloudposse:master Jun 16, 2020
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.

6 participants