-
Notifications
You must be signed in to change notification settings - Fork 94
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
Rework internal config structure #261
Conversation
7fe58d3
to
a4cf2cf
Compare
This PR is getting more and more in a state where we could merge it. There is also now the possibility to test the new config syntax, by setting the What is still missing for now are tests. I'm now focusing on those. @dynatrace-oss/mac-maintainers would be nice if somebody could read through the PR |
3bb1c97
to
a20e811
Compare
f1af432
to
8d9f817
Compare
❌ Integration tests failed on ubuntu-latest |
❌ Integration tests failed on ubuntu-latest |
698d162
to
1b9d73c
Compare
🎉 Integration tests ran successfully on ubuntu-latest 🥳 |
49e73b3
to
02b591d
Compare
🎉 Integration tests ran successfully on ubuntu-latest 🥳 |
68a7196
to
7bafac0
Compare
pkg/version/version.go
Outdated
@@ -16,4 +16,4 @@ | |||
|
|||
package version | |||
|
|||
const MonitoringAsCode = "1.5.0" | |||
const MonitoringAsCode = "config-poc" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
random note cause I started by scrolling to the bottom: this should change before merging this ;)
7bafac0
to
1c28d82
Compare
54c5194
to
1572399
Compare
pkg/config/v2/config.go
Outdated
const ( | ||
// id is a special parameter. it is not allowed to be set via the config, | ||
// but needs to work as normal parameter otherwise (e.g. it can be referenced). | ||
ID_PARAMETER = "id" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Goland complains we shoud use camel and not snake case for these constants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL that golang uses camel case as naming convention for constants.
THX! I will fix it!
pkg/config/v2/config.go
Outdated
) | ||
|
||
const ( | ||
// id is a special parameter. it is not allowed to be set via the config, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These comments should start with
// ID_PARAMETER is a special...
pkg/config/v2/config.go
Outdated
return c.Coordinate.Match(ref) | ||
} | ||
|
||
// test if this config has a dependency on the given config. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for method comments, they should start with method name
// HasDependencyOn
pkg/config/v2/config.go
Outdated
// map of all parameters which will be resolved and are then available | ||
// in the template | ||
Parameters Parameters | ||
// slice of references as specified by the paramters. needed so that the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// slice of references as specified by the paramters. needed so that the | |
// slice of references as specified by the parameters. needed so that the |
pkg/config/v2/config_loader.go
Outdated
} | ||
|
||
func parseSkip(context *ConfigLoaderContext, environment manifest.EnvironmentDefinition, | ||
configId string, definition configDefinition, param interface{}) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused param
configId string, definition configDefinition, param interface{}) (bool, error) { | |
configId string, param interface{}) (bool, error) { |
pkg/config/v2/config_loader.go
Outdated
} | ||
|
||
func parseParameter(context *ConfigLoaderContext, environment manifest.EnvironmentDefinition, | ||
configId string, definition configDefinition, name string, param interface{}) (parameter.Parameter, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused param
configId string, definition configDefinition, name string, param interface{}) (parameter.Parameter, error) { | |
configId string, name string, param interface{}) (parameter.Parameter, error) { |
pkg/config/v2/config_writer.go
Outdated
} | ||
|
||
switch valueParam.Value.(type) { | ||
// map/array values need special handling to not collide with oter paramters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
other parameters
} | ||
|
||
// tests if this coordinate is the same as the given one | ||
func (c *Coordinate) Match(coordinate Coordinate) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using different receiver names
pkg/deploy/v2/deploy.go
Outdated
|
||
type knownEntityMap map[string]map[string]struct{} | ||
|
||
// deployes the given configs with the given apis via the given client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// deployes the given configs with the given apis via the given client | |
// DeployConfigs deploys the given configs with the given apis via the given client |
pkg/deploy/v2/deploy.go
Outdated
// as they will never be resolved before we validate | ||
// the parameters | ||
if ref.Config == configCoordinates { | ||
// parameters referencing themselfs makes no sense |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// parameters referencing themselfs makes no sense | |
// parameters referencing themselves makes no sense |
@@ -33,7 +33,7 @@ func LoadEnvironmentList(specificEnvironment string, environmentsFile string, fs | |||
|
|||
environmentsFromFile, errorList := readEnvironments(environmentsFile, fs) | |||
|
|||
if environmentsFromFile == nil || len(environmentsFromFile) == 0 { | |||
if len(environmentsFromFile) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we fix the typo on line 30:
"no environment file provided"
pkg/manifest/manifest.go
Outdated
} | ||
|
||
func (m *Manifest) GetEnvironmentsAsSlice() []EnvironmentDefinition { | ||
var result []EnvironmentDefinition = make([]EnvironmentDefinition, 0, len(m.Environments)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var result []EnvironmentDefinition = make([]EnvironmentDefinition, 0, len(m.Environments)) | |
var result = make([]EnvironmentDefinition, 0, len(m.Environments)) |
pkg/util/client/dummy_client.go
Outdated
"path/filepath" | ||
"time" | ||
|
||
api "github.com/dynatrace-oss/dynatrace-monitoring-as-code/pkg/api" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
api "github.com/dynatrace-oss/dynatrace-monitoring-as-code/pkg/api" | |
"github.com/dynatrace-oss/dynatrace-monitoring-as-code/pkg/api" |
1572399
to
e064d77
Compare
@@ -88,6 +87,11 @@ func NewConfigForDelete(id string, fileName string, properties map[string]map[st | |||
return newConfig(id, "", nil, filterProperties(id, properties), api, fileName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NewConfigForDelete
seems to not be used anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is legacy config file. I would rather not touch it any more than necessary 😆
I guess the plan would be, to get rid of all legacy files within the next few versions.
pkg/version/version.go
Outdated
@@ -16,4 +16,4 @@ | |||
|
|||
package version | |||
|
|||
const MonitoringAsCode = "1.6.0" | |||
const MonitoringAsCode = "2.0.0-new-config" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not simply
const MonitoringAsCode = "2.0.0-new-config" | |
const MonitoringAsCode = "2.0.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was just for local debug builds. I would not go with 2.0.0
yet.
Maybe 2.0.0-next
, since we are going to build next binaries. That
way people don't mistake it for a full release.
cmd/monaco/main.go
Outdated
Aliases: []string{"v"}, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "specific-environment", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a good opportunity to modify this: how about using -e
or -environment
. Not sure we need specific
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you ask me, we should delete this file anyway. The new main is located
in cmd/monaco/v2/main.go
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just kept this file as I wasn't sure how we want to go on with it.
cmd/monaco/main.go
Outdated
deployCommand := getDeployCommand(fs) | ||
var deployCommand cli.Command | ||
|
||
if isEnvFlagEnabled("NEW_CONFIG") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we make NEW_CONFIG
a default? We should rather allow compatibility mode with CONFIG_V1
flag, but use new config as default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As pointed out above, I would ignore this file and delete it.
1b119ef
to
fc0a49c
Compare
}) | ||
|
||
if errs != nil { | ||
return errors.New("error while loading projects") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return errors.New("error while loading projects") | |
util.PrintErrors(errs) | |
return errors.New("error while loading projects") |
Is there any reason not to print the errors? Just dropping them and returning a new error doesn't seem very favorable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch 😆
sortedConfigs, errs := sort.GetSortedConfigsForEnvironments(projects, environmentNames) | ||
|
||
if errs != nil { | ||
return errors.New("error during sort") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return errors.New("error during sort") | |
util.PrintErrors(errs) | |
return errors.New("error during sort") |
cmd/monaco/v2/deploy/cmd.go
Outdated
for _, err := range errs { | ||
util.Log.Error(err.Error()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for _, err := range errs { | |
util.Log.Error(err.Error()) | |
} | |
util.PrintErrors(errs) |
cmd/monaco/v2/deploy/cmd.go
Outdated
if errors != nil { | ||
deploymentErrors = append(deploymentErrors, errors...) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if errors != nil { | |
deploymentErrors = append(deploymentErrors, errors...) | |
} | |
deploymentErrors = append(deploymentErrors, errors...) |
No need to check for nil, appending a nil slice is perfectly fine
for _, err := range generalErrors { | ||
util.Log.Error(util.ErrorString(err)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for _, err := range generalErrors { | |
util.Log.Error(util.ErrorString(err)) | |
} | |
util.PrintErrors(generalErrors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to change anyway. We should create a proper error report here.
I'll add an TODO.
return result, nil | ||
} | ||
|
||
func parseProjectDefinition(context *projectLoaderContext, project project) ([]ProjectDefinition, []error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I see it only one error is ever returned, is a slice really needed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this method is designed with adding new project types in mind,
I would personally keep it.
pkg/project/v2/sort/sort.go
Outdated
if errs != nil { | ||
errors = append(errors, errs...) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if errs != nil { | |
errors = append(errors, errs...) | |
} | |
errors = append(errors, errs...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should short-circuit anyway here, as the sortedProjectsPerEnvironment
will anyway be nil
.
pkg/writer/writer.go
Outdated
if len(errs) > 0 { | ||
errors = append(errors, errs...) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if len(errs) > 0 { | |
errors = append(errors, errs...) | |
} | |
errors = append(errors, errs...) |
pkg/writer/writer.go
Outdated
func collectAllConfigs(p project.Project) []config.Config { | ||
var result []config.Config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func collectAllConfigs(p project.Project) []config.Config { | |
var result []config.Config | |
func collectAllConfigs(p project.Project) (result []config.Config) { |
|
||
func (c *DummyClient) BulkDeleteByName(a api.Api, names []string) error { | ||
for _, name := range names { | ||
err := c.DeleteByName(a, name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dummy client's DeleteByName
only returns nil
error, so no need to check for that tbh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, for now. The interface specifies that it could return an error,
so imho we should handle it (even though it is pretty much useless
now ^^)
e941c0a
to
ad0117a
Compare
ad0117a
to
bae85be
Compare
bae85be
to
f772b33
Compare
As the current config structure was a bit complicated to use, it has been completely reworked. First of all, there is now a central manifest file, which specifies all the details needed for deployment. This includes a list of all available projects (including paths to them, so goodbye recursive project discovery) and a grouping of available environment (including the name of the env variable holding the token). The structure within a project now has to follow a strict scheme, naminly `[api]/[config]`. Auto-discovery of sub-Projects are no longer supported. This was done to make things more explicit. The configuration yaml also looks now different. Instead of splitting configuration definitions in two parts (template location, rest of the config), everything is now in one structure. The top level structure of each yaml file is now called `configs`. For examples please see the documentation. Config paramters also have been reworked. They now support more values besides strings. There are some special parameter though. One of this special parameter is the reference parameter. References no longer depend on a special formatted string, instead you have to explicitly define the location of the config you want to reference. It is now also possible to depend on **any** reference of a config, not just id and name. Another special parameter is the environment parameter. It is **no longer** possible to reference env variables via the `{ .env.XYZ }` syntax in the config yaml or the template. This decision was made, to make configs more explicit. For more details on how the new parameter syntax works, please see the documentation. The delete.yaml now also supports deleting configs with multiple `/` in its name. Fixes Dynatrace#351 Fixes Dynatrace#255
Since we reworked the configuration syntax, the current configuration file syntax won't work. In order to support different types of integration tests, they have been moved into their own package. Also all the command parsing logic of the main file was factored out into a runner package. This way we can easily use it from the integration test packages.
f772b33
to
f4ceb79
Compare
This PR contains a proof of concept of a new configuration scheme.
It basically breaks with the current one completely. For further information have a look at
discussion #165
I opened this PR just to make my code changes more visible.