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

Next download feature 2.0 #421

Closed
wants to merge 11 commits into from
Closed

Next download feature 2.0 #421

wants to merge 11 commits into from

Conversation

drqc
Copy link
Contributor

@drqc drqc commented Sep 20, 2021

Created the PR for Monaco download 2.0. Still implementing the unit and integration test but everyone can grab the code and start testing/ reviewing it. I have reuse most of the entities from the convert command.

Pending tasks:

  • Performance improvements in the dependency resolution feature
  • Testing for special config cleanup. I have tested it with management zone and alerting profiles and works fine, will need to test it with more configurations.
  • Documentation
  • Integration test
  • Unit test

dependenciesPerEnvironment := make(map[string][]string)
return dependenciesPerEnvironment
}
func solveDependencies(projectId string, configs map[string][]configv2.Config) map[string][]configv2.Config {
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 might be a good case for a parallel foreach implementation https://stackoverflow.com/questions/24238820/parallel-for-loop

cmd/monaco/v2/download/cmd.go Outdated Show resolved Hide resolved
pkg/downloader/downloader.go Outdated Show resolved Hide resolved
pkg/downloader/downloader.go Outdated Show resolved Hide resolved
for _, api := range listApis {
creator := dynatraceparser.NewDynatraceParser()
configs, errs := createConfigforTargetApi(env, creator, client, api, projectId)
//apiconfig, err := createConfigFromApiV2(env, api, projectId, token, client)
Copy link
Contributor

Choose a reason for hiding this comment

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

We still need this?

pkg/downloader/downloader.go Outdated Show resolved Hide resolved
pkg/downloader/downloader.go Outdated Show resolved Hide resolved

package dynatraceparser

//filterConfiguration evaluates multiple filters to check if downloaded configuration is valid
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment should have the following format 'NotSupportedConfiguration ...' (with an optional leading article)

Makefile Outdated Show resolved Hide resolved
if len(errors) > 0 {
return nil, nil, errors
}
projectDefinitions[projectDefinition.Name] = projectDefinition
Copy link
Contributor

Choose a reason for hiding this comment

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

I may be missing something, but don't you build a map (and list) here that always just contains one element?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I'm reusing the entities and methods from convert command. That one takes multiple projects and multiple arrays in general. I could create single implementations of the configs but I would be duplicating code and I didn't want to modify much of the convert command code including methods and entities.

}

//generateManifest builds a manifest with a single environment and project
func generateManifest(fs afero.Fs, workdir string,
Copy link
Contributor

Choose a reason for hiding this comment

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

seems odd to me that you directly write to disk and return a manifest that you never actually use (as far as I can see)

might be worth considering to actually split "generate" and "write" manifest - which would also allow you to test the generation on its own

//returns the list of API filter if the download specific flag is used, otherwise returns all the API's
func getAPIList(downloadSpecificAPI string) (filterAPIList map[string]api.Api, err error) {
availableApis := api.NewApis()
noFilterAPIListProvided := strings.TrimSpace(downloadSpecificAPI) == ""
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: you trimSpace of the input here, then if there's content trim each of the split APIs again.
You could trim the complete string once, then re-use that for splitting.

}
}
if isErr {
return nil, fmt.Errorf("There were some errors in the API list provided")
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure if we want to fail on this - with the general concept of "fail only if you can't proceed at all" (as we e.g. follow on upload) we could maybe just download the APIs we know and at the end tell the user "hey, downloaded A,B,C but D is not an API we know"

@didiladi , @tatomir146 what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

For the upload functionality we default to fail but can overrule this with -c parameter. The option would be to use this flag also for download functionality, or as I would prefer, to do it as @UnseenWizzard described.

for _, configType := range configs {
for _, config := range configType {
content := config.Template.Content()
for key, val := range tempConfig {
Copy link
Contributor

Choose a reason for hiding this comment

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

please use something more explicit like id, coordinate

Choose a reason for hiding this comment

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

TempConfig does not check for empty ID's, which causes major issues when replacing further on. Example from a real customer environment:

image
That turns your app detection rule into this:
image
And the memory consumption into this:
image


package downloader

// func TestCreateConfigsFromAPI(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

please comment in, or delete

Value: name,
}

// if len(errors) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

please delete commented out code

func getTemplate(client rest.DynatraceClient, creator dynatraceparser.DynatraceParser, api api.Api,
val api.Value, path string) (template.Template, map[string]parameter.Parameter, string, bool, error) {

file, dynatraceId, fullpath, name, filter, err := creator.GetConfig(client, api, val, path)
Copy link
Contributor

Choose a reason for hiding this comment

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

I find the way the 'filter' boolean to filter things out is passed through methods pretty hard to grasp/follow

Haven't grasped the handling fully, so no clue if that could actually be improved, but for readability it would be preferably to filter on the outside, before calling things, rather than returning "filter" from the end of the callchain

newContent := strings.ReplaceAll(config.Template.Content(), dependencyCoor.DynatraceId, dependencyCoor.Config)
idProperty := "id" //since all depends on id to relative configs
ref := refParam.New(dependencyCoor.Project, dependencyCoor.Api, dependencyCoor.Config, idProperty)
config.Template.UpdateContent(newContent)
Copy link
Contributor

Choose a reason for hiding this comment

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

would personally rather create a new Template with the newContent here, than extending it with an UpdateContent
generally it's not something that will be modified, so I don't think we should make it possible just for this use

@dynatrace-cla-bot
Copy link

dynatrace-cla-bot commented Sep 21, 2021

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ diegorqc
❌ drqc
You have signed the CLA already but the status is still pending? Let us recheck it.

@CruzanCaramele
Copy link
Contributor

this is good and very important work in this pull request

the download feature and command options should maintain consistency with the deploy command options

The download feature should use the same manifest file as the deployment file to reference environments to download configurations from and get rid of the --environment flag

@tatomir146 tatomir146 linked an issue Sep 28, 2021 that may be closed by this pull request
@UnseenWizzard UnseenWizzard added this to the v2.0 milestone Dec 10, 2021
@UnseenWizzard UnseenWizzard added the v2 Anything related to monaco 2.x label Jul 14, 2022
@UnseenWizzard
Copy link
Contributor

feature was integrated into v2 dev branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v2 Anything related to monaco 2.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Download current environment configuration
6 participants