Skip to content

Init config refactor #2035

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 10 commits into
base: main
Choose a base branch
from

Conversation

turetske
Copy link
Collaborator

@turetske turetske commented Feb 21, 2025

Moved InitConfig into InitServer and InitClient and adjusts the tests as needed.

Also made InitConfigDir platform agnostic.

Ideally, I would like to be able to make InitConfig private, but its use in the cmd/config_printer test makes that impossible.

I'm worried InitConfig will keep being used in tests until we figure out a solution for that if the author/reviewer don't catch it organically.

@turetske turetske requested a review from Saartank February 21, 2025 20:18
@turetske turetske added the internal Internal code improvements, not user-facing label Feb 21, 2025
@turetske turetske added this to the v7.14 milestone Feb 21, 2025
@turetske turetske marked this pull request as draft February 21, 2025 20:41
@turetske turetske modified the milestones: v7.14, v7.15 Feb 24, 2025
@turetske turetske force-pushed the init-config-refactor branch 2 times, most recently from 42bf05f to f55f544 Compare February 27, 2025 21:12
@turetske turetske marked this pull request as ready for review February 27, 2025 21:38
Copy link
Contributor

@Saartank Saartank left a comment

Choose a reason for hiding this comment

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

With this change, the log file initialization code runs when InitServer is executed. However, some code is executed before InitServer is reached. Because of this, all logs generated before InitServer runs will be output to the console even if the log file is configured. This could be problematic if something goes wrong before InitServer is reached, as the log file would not contain the relevant information.

@turetske turetske modified the milestones: v7.15, v7.16 Mar 21, 2025
@turetske turetske force-pushed the init-config-refactor branch from f55f544 to 40118c7 Compare March 24, 2025 22:24
Emma Turetsky added 8 commits April 11, 2025 00:58
   -- Moved InitConfig into InitServer and InitClient
   -- Replaced calls of InitConfig with InitServer and InitClient where
possible
   -- Removed calls to InitConfigDir where possible
   -- Adjusted the tests where needed due to the changes made
	-- Mostly due to unset ConfigDir that should be a tempDir
	-- Adjusted some params and a few other tests as well
@turetske turetske force-pushed the init-config-refactor branch from 40118c7 to 9e7b6d0 Compare April 11, 2025 02:46
@turetske turetske requested review from Saartank and jhiemstrawisc and removed request for Saartank April 11, 2025 03:23
@turetske turetske requested a review from jhiemstrawisc April 16, 2025 16:27

err := config.InitClient()
require.NoError(t, err)
test_utils.InitClient(t, make(map[string]any))
Copy link
Member

Choose a reason for hiding this comment

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

This might be a bit easier to read if you nil to the client initializer instead of make(map[string]any).

Comment on lines 564 to 565
// We are purposely creating a test with a config of a single-space.
// The empty string indicates using the default config, which we don't want.
Copy link
Member

Choose a reason for hiding this comment

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

This comment is no longer relevant.

Comment on lines 848 to 849
// We are purposely creating a test with a config of a single-space.
// The empty string indicates using the default config, which we don't want.
Copy link
Member

Choose a reason for hiding this comment

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

Same with this comment.

// This will be revisited in the future
os := runtime.GOOS
if os == "windows" {
log.Warningln("No home directory found for user -- will check for configuration yaml in C:/ProgramData/pelican")
Copy link
Member

Choose a reason for hiding this comment

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

I think Windows uses back slashes as filepath separators, so the path in this comment should probably be C:\ProgramData\pelican -- safer yet, use whatever gets spit out by the filepath.Join() you call in the next line.

require.NoError(t, err)
})

exportMap := item.(map[string]interface{})
Copy link
Member

Choose a reason for hiding this comment

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

Another any

Comment on lines +172 to +174
originRaw, exists := confMap["Origin"]

if exists {
Copy link
Member

Choose a reason for hiding this comment

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

This might be a bit cleaner as:

if originRaw, exists := confMap["Origin"]; exists {
    // blah
}

since originRaw is not used outside the scope of this condition.

I think it might also be a fatal error if we don't pass this existence check -- that would indicate the test thinks it was provided origin configuration, but that configuration doesn't contain Origin:.

originMap := originRaw.(map[string]interface{})

// Override the test directory from the config file with our temp directory
if exportsRaw, ok := originMap["Exports"]; ok {
Copy link
Member

Choose a reason for hiding this comment

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

In the top-level if, you use exists instead of ok to determine whether the entry is in the map -- I think ok is more canonically "go", but I honestly think "exists" is easier to read. Can you pick one or the other and use in both cases?

err = os.WriteFile(filepath.Join(originDir, "hello_world.txt"), []byte("Hello, World!"), os.FileMode(0644))
require.NoError(t, err)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

The majority of the code in the if exportsRaw, ok := originMap["Exports"]; ok { is duplicated in the subsequent else -- can you turn some of it into an inline helper function somewhere?

err = config.InitServer(ctx, modules)
require.NoError(t, err)

// Read in any config we may have set
var originConf interface{}
if originConfig != "" {
Copy link
Member

Choose a reason for hiding this comment

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

This check shouldn't be needed anymore because a recent change added:

if originConfig == "" {
		originConfig = fedTestDefaultConfig
	}

to the start of the test

@jhiemstrawisc jhiemstrawisc modified the milestones: v7.16, v7.17 Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal Internal code improvements, not user-facing
Projects
None yet
3 participants